protected void AddDiamondGridCell(PointF offset, float size, ref List <Node> cellNodeList) { int oldNodeListCount = nodeDict.Count; SizeF cellSize = new SizeF(size, size); PointF point = new PointF(); //Point i = new Point(0,0); point.X = offset.X * 1; point.Y = offset.Y * 3; for (int id = 0; id < 6; id++) { ShapeNode node = new ShapeNode(); for (int ip = 0; ip < 4; ip++) { point.X = (offset.X * 2) + (d[id, ip].X * 2); point.Y = (offset.Y * 3) + d[id, ip].Y; node.AddPoint(ip, point); } nodeDict.Add(node, node.LinkList); } for (int index = oldNodeListCount; index < nodeDict.Count; index++) { cellNodeList.Add(nodeDict.ElementAt(index).Key); } }
protected void ConnectEdge(ShapeNode n, ref int index, List <Node> nl) { // Attempts to connect an edge(index) on a ShapeNode(n) against all edges in a list of Nodes(nl) // Subdivides matching edges accordingly if the intersection is less than the entire length of one of the edges. // Note: Subdivision code is fairly basic at the moment. Some edge cases are not covered. if (n.LinkList[index] != null) { return; } Vector2D edge = n.GetEdge(index); Vector2D norm1 = edge.Normalized(); foreach (ShapeNode n2 in nl) { if (n2 != n) { for (int index2 = 0; index2 < n2.points.Count; index2++) { Vector2D edge2 = n2.GetAntiClockwiseEdge(index2); Vector2D norm2 = edge2.Normalized(); if (edge.a == edge2.a && norm1 == norm2) { NodeLink nodeLink = ShapeNode.ConnectEdges(n, index, n2, index2); if (edge.Length() > edge2.Length()) { n.AddPoint(index + 1, edge2.b); index--; } if (edge2.Length() > edge.Length()) { n2.AddPoint(index2 + 1, edge.b); n2.LinkList[index2 + 1] = n2.LinkList[index2]; n2.LinkList[index2] = null; ConnectEdge(n2, ref index2, nl); } return; } } } } }
protected void AddTriangleGridCell(PointF offset, float size, ref List <Node> cellNodeList) { int oldNodeListCount = nodeDict.Count; SizeF cellSize = new SizeF(size, size); PointF point = new PointF(); Point i = new Point(0, 0); point.X = offset.X + (i.X * size); point.Y = offset.Y + (i.Y * size); // Randomly flip orientation of triangles in a cell if (_random.Next(0, 2) == 0) { ShapeNode node = new ShapeNode(); node.AddPoint(0, point); point.X += size; point.Y += size; node.AddPoint(1, point); point.X -= size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); node = new ShapeNode(); point.X += size; node.AddPoint(0, point); point.X -= size; point.Y -= size; node.AddPoint(1, point); point.X += size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); } else { ShapeNode node = new ShapeNode(); point.X += size; node.AddPoint(0, point); point.X -= size; point.Y += size; node.AddPoint(1, point); point.Y -= size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); node = new ShapeNode(); point.Y += size; node.AddPoint(0, point); point.X += size; point.Y -= size; node.AddPoint(1, point); point.Y += size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); } for (int index = oldNodeListCount; index < nodeDict.Count; index++) { cellNodeList.Add(nodeDict.ElementAt(index).Key); } }
protected void AddDiamondGridCell(PointF offset, float size, ref List<Node> cellNodeList) { int oldNodeListCount = nodeDict.Count; SizeF cellSize = new SizeF(size, size); PointF point = new PointF(); //Point i = new Point(0,0); point.X = offset.X * 1; point.Y = offset.Y * 3; for(int id = 0; id < 6; id++) { ShapeNode node = new ShapeNode(); for(int ip = 0; ip < 4; ip++) { point.X = (offset.X * 2) + (d[id,ip].X * 2); point.Y = (offset.Y * 3) + d[id,ip].Y; node.AddPoint(ip, point); } nodeDict.Add(node, node.LinkList); } for (int index = oldNodeListCount; index < nodeDict.Count; index++) { cellNodeList.Add(nodeDict.ElementAt(index).Key); } }
protected void AddTriangleGridCell(PointF offset, float size, ref List<Node> cellNodeList) { int oldNodeListCount = nodeDict.Count; SizeF cellSize = new SizeF(size, size); PointF point = new PointF(); Point i = new Point(0,0); point.X = offset.X + (i.X * size); point.Y = offset.Y + (i.Y * size); // Randomly flip orientation of triangles in a cell if(_random.Next(0,2) == 0) { ShapeNode node = new ShapeNode(); node.AddPoint(0, point); point.X += size; point.Y += size; node.AddPoint(1, point); point.X -= size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); node = new ShapeNode(); point.X += size; node.AddPoint(0, point); point.X -= size; point.Y -= size; node.AddPoint(1, point); point.X += size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); } else { ShapeNode node = new ShapeNode(); point.X += size; node.AddPoint(0, point); point.X -= size; point.Y += size; node.AddPoint(1, point); point.Y -= size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); node = new ShapeNode(); point.Y += size; node.AddPoint(0, point); point.X += size; point.Y -= size; node.AddPoint(1, point); point.Y += size; node.AddPoint(2, point); nodeDict.Add(node, node.LinkList); } for (int index = oldNodeListCount; index < nodeDict.Count; index++) { cellNodeList.Add(nodeDict.ElementAt(index).Key); } }
protected void ConnectEdge(ShapeNode n, ref int index, List<Node> nl) { // Attempts to connect an edge(index) on a ShapeNode(n) against all edges in a list of Nodes(nl) // Subdivides matching edges accordingly if the intersection is less than the entire length of one of the edges. // Note: Subdivision code is fairly basic at the moment. Some edge cases are not covered. if (n.LinkList[index] != null) { return; } Vector2D edge = n.GetEdge(index); Vector2D norm1 = edge.Normalized(); foreach (ShapeNode n2 in nl) { if (n2 != n) { for (int index2 = 0; index2 < n2.points.Count; index2++) { Vector2D edge2 = n2.GetAntiClockwiseEdge(index2); Vector2D norm2 = edge2.Normalized(); if (edge.a == edge2.a && norm1 == norm2) { NodeLink nodeLink = ShapeNode.ConnectEdges(n, index, n2, index2); if (edge.Length() > edge2.Length()) { n.AddPoint(index + 1, edge2.b); index--; } if (edge2.Length() > edge.Length()) { n2.AddPoint(index2 + 1, edge.b); n2.LinkList[index2 + 1] = n2.LinkList[index2]; n2.LinkList[index2] = null; ConnectEdge(n2, ref index2, nl); } return; } } } } }