Пример #1
0
        public void DeleteVertex(Vertex vertex)
        {
            if (Vertices.Count <= 3)
            {
                return;
            }

            var prevVertex = vertex.Edges[0].Vertices[0];
            var nextVertex = vertex.Edges[1].Vertices[1];
            var prevEdge   = vertex.Edges[0];
            var nextEdge   = vertex.Edges[1];

            _window.DrawPoints(vertex.Edges[0].Points, DefaultColor);
            _window.DrawPoints(vertex.Edges[1].Points, DefaultColor);
            _window.DrawDot(vertex.Point, DefaultColor);

            var newEdgePoints = GetLine(nextVertex.Point.X, nextVertex.Point.Y, prevVertex.Point.X, prevVertex.Point.Y);
            var maxEdgeId     = Edges.Select(e => e.Id).Max();
            var newEdge       = new Edge(maxEdgeId + 1, newEdgePoints);

            prevVertex.Edges[1] = nextVertex.Edges[0] = newEdge;
            newEdge.Vertices[0] = prevVertex;
            newEdge.Vertices[1] = nextVertex;

            Edges.Add(newEdge);
            Vertices.Remove(vertex);
            Edges.Remove(prevEdge);
            Edges.Remove(nextEdge);

            ParallelPairs.RemoveAll(pair => pair.Vertices.Contains(vertex.Id));

            _window.RedrawAll();
        }
Пример #2
0
        public void AddVertexOnEdge(Point edgePoint, Edge edge)
        {
            _window.DrawPoints(edge.Points, DefaultColor);

            ParallelPairs.RemoveAll(pair => pair.Edges.Contains(edge.Id));

            var prevVertex = edge.Vertices[0];
            var nextVertex = edge.Vertices[1];

            var maxVertexId    = Vertices.Select(v => v.Id).Max();
            var maxEdgeId      = Edges.Select(e => e.Id).Max();
            var prevEdgePoints = GetLine(edgePoint.X, edgePoint.Y, prevVertex.Point.X, prevVertex.Point.Y);
            var nextEdgePoints = GetLine(edgePoint.X, edgePoint.Y, nextVertex.Point.X, nextVertex.Point.Y);

            var newVertex   = new Vertex(maxVertexId + 1, edgePoint);
            var newPrevEdge = new Edge(maxEdgeId + 1, prevEdgePoints);
            var newNextEdge = new Edge(maxEdgeId + 2, nextEdgePoints);

            newVertex.Edges[0] = newPrevEdge;
            newVertex.Edges[1] = newNextEdge;

            newPrevEdge.Vertices[0] = prevVertex;
            newPrevEdge.Vertices[1] = newVertex;
            newNextEdge.Vertices[0] = newVertex;
            newNextEdge.Vertices[1] = nextVertex;

            prevVertex.Edges[1] = newPrevEdge;
            nextVertex.Edges[0] = newNextEdge;

            Edges.Remove(edge);
            Edges.Add(newPrevEdge);
            Edges.Add(newNextEdge);
            Vertices.Add(newVertex);

            _window.RedrawAll();
        }
Пример #3
0
 public void DeleteEdgeRelation(Edge edge)
 {
     ParallelPairs.RemoveAll(pair => pair.Edges.Contains(edge.Id));
     _window.RedrawAll();
 }