/// <summary> /// Constructor. /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="pen"></param> /// <param name="parent"></param> /// <remarks>Updates informationa about incident edges for <paramref name="start"/> nad <paramref name="end"./></remarks> public Line(VerticePoint start, VerticePoint end, Polygon parent = null, Color?color = null, int?thickness = null) { Id = AppUtils.GenerateEdgeId(); this.start = start; this.end = end; SetSelfAsIncidentEdgeforVetrices(); Pen = new Pen(color == null ? DefaultLineColor : (Color)color, thickness == null? DefaultLineThickness : (int)thickness); UpdateLinePosition(); Parent = parent; }
public (Line deletedEdge, Line firstAddedEdge, Line secondAddedEdge, VerticePoint addedVertice) AddVerticeOnEdge(Line e) { #region CheckArgs if (e == null) { return(null, null, null, null); } if (vertices.Count == 0) { return(null, null, null, null); } if (edges.Count == 0) { return(null, null, null, null); } #endregion int edgeIndex = edges.IndexOf(e); if (edgeIndex == -1) { return(null, null, null, null); } // point for new vertice var point = e.LinePoints[e.LinePoints.Count / 2]; // ddelete old edge edges.RemoveAt(edgeIndex); // new vertce var newVertice = new VerticePoint(point.X, point.Y, this); vertices.Insert(edgeIndex + 1, newVertice); // new Edges var firsNewEgde = new Line(e.start, newVertice, this); var secondNewEdge = new Line(newVertice, e.end, this); edges.Insert(edgeIndex, firsNewEgde); edges.Insert(edgeIndex + 1, secondNewEdge); return(e, firsNewEgde, secondNewEdge, newVertice); }
public void Clear() { selectedVertice = null; }
public MovingVerticeState(VerticePoint currentlyMovingVertice, PointF hitPoint) { this.selectedVertice = currentlyMovingVertice; this.hitPoint = hitPoint; }
public DeletingVerticeState(VerticePoint currentlyDeletingVertice) { this.selectedVertice = currentlyDeletingVertice; }
public (Line firstDeletedEdge, Line secondDeletedEdge, Line addedEdge) DeleteVertice(VerticePoint v) { #region CheckArgs if (v == null) { return(null, null, null); } if (vertices.Count == 0) { return(null, null, null); } if (edges.Count == 0) { return(null, null, null); } #endregion int verticeIndex = vertices.IndexOf(v); if (verticeIndex == -1) { return(null, null, null); } // polygon must have at least 3 vertices and edges int newEdgeIndex = verticeIndex - 1 >= 0 ? verticeIndex - 1 : edges.Count - 2; // insert new edge at the end if deleting first vertice // delete vertice vertices.Remove(v); // delete incident edges edges.Remove(v.FirstIncidentEdge); edges.Remove(v.SecondIncidentEdge); // crete and add new Edge // TODO default color var newEdge = new Line(v.FirstIncidentEdge.start, v.SecondIncidentEdge.end, this, v.FirstIncidentEdge.Pen.Color, (int)v.FirstIncidentEdge.Pen.Width); edges.Insert(newEdgeIndex, newEdge); return(v.FirstIncidentEdge, v.SecondIncidentEdge, newEdge); }