public void SplitEdge(Edge e) { foreach (var vertice in e.Endpoints) { vertice.DisconnectEdge(e); } var middleOfEdge = PointUtilities.GetPointInTheMiddleOfSegment(e.Endpoints[0].Position, e.Endpoints[1].Position); Vertice v = new Vertice { Position = middleOfEdge }; CreateEdgeBetweenVertices(v, e.Endpoints[0]); CreateEdgeBetweenVertices(v, e.Endpoints[1]); List <Vertice> verticesList = Vertices.ToList(); List <Edge> edgesList = Edges.ToList(); verticesList.Add(v); edgesList.Remove(e); Vertices = verticesList; Edges = edgesList; }
private bool RepairEdgeRecursion(Vertice vertice, Edge edge, Vertice start) { var otherVertice = edge.GetSecondEndpoint(vertice); if (otherVertice == start) { return(false); } if (edge.Type == EdgeType.Vertical) { if (Math.Abs(vertice.Position.X - otherVertice.Position.X) != 0) { otherVertice.Position = new Point(vertice.Position.X, otherVertice.Position.Y); return(RepairEdgeRecursion(otherVertice, otherVertice.GetSecondEdge(edge), start)); } } else if (edge.Type == EdgeType.Horizontal) { if (Math.Abs(vertice.Position.Y - otherVertice.Position.Y) != 0) { otherVertice.Position = new Point(otherVertice.Position.X, vertice.Position.Y); return(RepairEdgeRecursion(otherVertice, otherVertice.GetSecondEdge(edge), start)); } } else if (edge.Type == EdgeType.FixedLength) { otherVertice.Position = PointUtilities.GetPointOnLineWithSpecificDistanceFromStart(vertice.Position, otherVertice.Position, edge.Length); return(RepairEdgeRecursion(otherVertice, otherVertice.GetSecondEdge(edge), start)); } return(true); }
public int Compare(Point x, Point y) { int orientation = Orientation(point, x, y); if (orientation == 0) { return((PointUtilities.SquaredDistanceBetweenPoints(point, y) >= PointUtilities.SquaredDistanceBetweenPoints(point, x)) ? -1 : 1); } return((orientation == 2) ? -1 : 1); }
public static Polygon CreatePolygon(List <Point> positionsOfVertices, List <EdgeType> edgeTypes) { List <Vertice> vertices = new List <Vertice>(); List <Edge> edges = new List <Edge>(); if (positionsOfVertices.Count != edgeTypes.Count) { return(new Polygon(vertices, edges)); } foreach (Point position in positionsOfVertices) { vertices.Add(new Vertice { Position = position }); } for (int i = 0; i < edgeTypes.Count; i++) { int leftVerticeIndex = i; int rightVerticeIndex = (i + 1) % edgeTypes.Count; Edge edge = new Edge { Type = edgeTypes[i] }; edge.Endpoints[0] = vertices[leftVerticeIndex]; edge.Endpoints[1] = vertices[rightVerticeIndex]; if (edge.Type == FixedLength) { edge.Length = (int)PointUtilities.GetDistanceBetweenPoints(edge.Endpoints[0].Position, edge.Endpoints[1].Position); } vertices[leftVerticeIndex].Edges[1] = edge; vertices[rightVerticeIndex].Edges[0] = edge; edges.Add(edge); } return(new Polygon(vertices, edges)); }
private void DrawIcon(Graphics graphics, Edge edge) { if (edge.Type == EdgeType.Normal) { return; } Point middle = PointUtilities.GetPointInTheMiddleOfSegment(edge.Endpoints[0].Position, edge.Endpoints[1].Position); Point leftUpperCorner = new Point(middle.X - IconRadius, middle.Y - IconRadius); using (Pen pen = new Pen(IconColor, IconLineThickness)) { Point leftUpper = new Point((int)(middle.X - 0.5 * IconRadius), (int)(middle.Y - 0.5 * IconRadius)); Point leftLower = new Point(leftUpper.X, leftUpper.Y + IconRadius); Point rightUpper = new Point((int)(middle.X + 0.5 * IconRadius), leftUpper.Y); Point rightLower = new Point(rightUpper.X, leftLower.Y); if (edge.Type == EdgeType.Horizontal) { graphics.DrawLine(pen, leftUpper, rightUpper); graphics.DrawLine(pen, leftLower, rightLower); } else if (edge.Type == EdgeType.Vertical) { graphics.DrawLine(pen, leftUpper, leftLower); graphics.DrawLine(pen, rightUpper, rightLower); } else if (edge.Type == EdgeType.FixedLength) { using (Brush b = new SolidBrush(IconColor)) using (Font f = new Font(IconFontName, IconFontSize)) { graphics.DrawString("F", f, b, leftUpper); } } } }