Exemple #1
0
        public void DeleteEdge(Edge edge)
        {
            if (!edges.Contains(edge))
            {
                return;
            }

            RemoveRelation(edge);

            var splitVertex = edge.GetSplitVertex();

            foreach (var e in edges)
            {
                if (e.End == edge.Begin)
                {
                    e.End = splitVertex;
                }
                else if (e.Begin == edge.End)
                {
                    e.Begin = splitVertex;
                }
            }

            vertices.Remove(edge.Begin);
            vertices.Remove(edge.End);
            vertices.Add(splitVertex);
            edges.Remove(edge);
        }
Exemple #2
0
        public bool SplitEdge(Edge edge)
        {
            if (edge.Length < DrawingConstants.MinimumSplitLength)
            {
                return(false);
            }

            if (!edges.Contains(edge))
            {
                return(false);
            }

            RemoveRelation(edge);

            var splitVertex = edge.GetSplitVertex();

            lastProcessedVertex = edge.End;
            var secondEdge = new Edge(splitVertex, edge.End, this);

            edge.End = splitVertex;

            edges.Insert(edges.IndexOf(edge) + 1, secondEdge);
            vertices.Insert(vertices.IndexOf(edge.Begin) + 1, splitVertex);

            return(true);
        }
Exemple #3
0
        private static void RotateNeighboursToPerpendicular(Edge first, Edge second)
        {
            var temp   = new Edge(first.Begin, second.End);
            var middle = temp.GetSplitVertex();
            var oldPos = first.End.Position;

            first.End.Position = middle.Position;
            var direction      = first.GetDirection();
            var positionFirst  = first.End.Position.Add(new Point(-(int)Math.Round(direction.Y), (int)Math.Round(direction.X)));
            var positionSecond = first.End.Position.Add(new Point((int)Math.Round(direction.Y), -(int)Math.Round(direction.X)));

            first.End.Position = positionFirst.DistanceSquaredTo(oldPos) > positionSecond.DistanceSquaredTo(oldPos) ? positionSecond : positionFirst;
        }