private static VisibilityVertex GetCrossingInteriorVertex(VisibilityGraph vg, VisibilityVertex crossingVertex,
         GroupBoundaryCrossing crossing) {
     Point interiorPoint = crossing.GetInteriorVertexPoint(crossingVertex.Point);
     return vg.FindVertex(interiorPoint) ?? vg.AddVertex(interiorPoint);
 }
        private bool AppendGroupCrossingsThroughPoint(VisibilityGraph vg, Point lastPoint) {
            if (null == GroupBoundaryPointAndCrossingsList) {
                return false;
            }

            bool found = false;
            while (GroupBoundaryPointAndCrossingsList.CurrentIsBeforeOrAt(lastPoint)) {
                // We will only create crossing Edges that the segment actually crosses, not those it ends before crossing.
                // For those terminal crossings, the adjacent segment creates the interior vertex and crossing edge.
                PointAndCrossings pac = GroupBoundaryPointAndCrossingsList.Pop();
                GroupBoundaryCrossing[] lowDirCrossings = null;
                GroupBoundaryCrossing[] highDirCrossings = null;
                if (PointComparer.Compare(pac.Location, Start) > 0) {
                    lowDirCrossings = PointAndCrossingsList.ToCrossingArray(pac.Crossings,
                            ScanDirection.OppositeDirection);
                }
                if (PointComparer.Compare(pac.Location, End) < 0) {
                    highDirCrossings = PointAndCrossingsList.ToCrossingArray(pac.Crossings, ScanDirection.Direction);
                }

                found = true;
                VisibilityVertex crossingVertex = vg.FindVertex(pac.Location) ?? vg.AddVertex(pac.Location);

                if ((null != lowDirCrossings) || (null != highDirCrossings)) {
                    AddLowCrossings(vg, crossingVertex, lowDirCrossings);
                    AddHighCrossings(vg, crossingVertex, highDirCrossings);
                } else {
                    // This is at this.Start with only lower-direction toward group interior(s), or at this.End with only 
                    // higher-direction toward group interior(s).  Therefore an adjacent ScanSegment will create the crossing
                    // edge, so create the crossing vertex here and we'll link to it.
                    if (null == LowestVisibilityVertex) {
                        SetInitialVisibilityVertex(crossingVertex);
                    } else {
                        Debug.Assert(PointComparer.Equal(End, crossingVertex.Point), "Expected this.End crossingVertex");
                        AppendHighestVisibilityVertex(crossingVertex);
                    }
                }
            }
            return found;
        }
 private void LoadEndOverlapVertexIfNeeded(VisibilityGraph vg) {
     // See comments in LoadStartOverlapVertexIfNeeded.
     if (NeedEndOverlapVertex) {
         VisibilityVertex vertex = vg.FindVertex(End);
         AppendVisibilityVertex(vg, vertex ?? vg.AddVertex(End));
     }
 }
        internal void CreateSparseVerticesAndEdges(VisibilityGraph vg) {
            if (this.sparsePerpendicularCoords == null) {
                return;
            }

            AppendGroupCrossingsThroughPoint(vg, Start);
            foreach (var perpCoord in this.sparsePerpendicularCoords.OrderBy(d => d)) {
                var vertexLocation = this.CreatePointFromPerpCoord(perpCoord);
                Debug.Assert(this.ContainsPoint(vertexLocation), "vertexLocation is not on Segment");
                this.AppendVisibilityVertex(vg, vg.FindVertex(vertexLocation) ?? vg.AddVertex(vertexLocation));
            }
            AppendGroupCrossingsThroughPoint(vg, End);
            GroupBoundaryPointAndCrossingsList = null;

            this.sparsePerpendicularCoords.Clear();
            this.sparsePerpendicularCoords = null;
        }
 private void LoadStartOverlapVertexIfNeeded(VisibilityGraph vg) {
     // For adjacent segments with different IsOverlapped, we need a vertex that
     // joins the two so a path may be run.  This is paired with the other segment's
     // LoadEndOverlapVertexIfNeeded.
     if (NeedStartOverlapVertex) {
         VisibilityVertex vertex = vg.FindVertex(Start);
         AppendVisibilityVertex(vg, vertex ?? vg.AddVertex(Start));
     }
 }