internal static void CalculatePointVisibilityGraph(IEnumerable<Polyline> listOfHoles,
                                                    VisibilityGraph visibilityGraph, Point point,
                                        VisibilityKind visibilityKind, out VisibilityVertex qVertex) {
     //maybe there is nothing to do
     var qv = visibilityGraph.FindVertex(point);
     if (qv != null){
         qVertex = qv;
         return;
     }
         
     var calculator = new PointVisibilityCalculator(listOfHoles, visibilityGraph, point, visibilityKind);
     calculator.FillGraph();
     qVertex = calculator.QVertex;
     Debug.Assert(qVertex != null);
 }
Esempio n. 2
0
        /// <summary>
        /// We suppose that the holes are convex and oriented clockwis and are mutually disjoint
        /// </summary>
        /// <param name="listOfHoles"></param>
        /// <param name="visibilityGraph"></param>
        /// <param name="point">The point can belong to the boundary of one of the holes</param>
        /// <param name="visibilityKind">tangent or regural visibility</param>
        /// <param name="qVertex">the graph vertex corresponding to the pivot</param>
        /// <returns></returns>
        internal static VisibilityVertex CalculatePointVisibilityGraph(
            IEnumerable <Polyline> listOfHoles,
            VisibilityGraph visibilityGraph,
            Point point,
            VisibilityKind visibilityKind)
        {
            //maybe there is nothing to do
            var qv = visibilityGraph.FindVertex(point);

            if (qv != null)
            {
                return(qv);
            }

            var calculator = new PointVisibilityCalculator(listOfHoles, visibilityGraph, point, visibilityKind);

            calculator.FillGraph();
            return(calculator.QVertex);
        }
        internal static void CalculatePointVisibilityGraph(IEnumerable <Polyline> listOfHoles,
                                                           VisibilityGraph visibilityGraph, Point point,
                                                           VisibilityKind visibilityKind, out VisibilityVertex qVertex)
        {
            //maybe there is nothing to do
            var qv = visibilityGraph.FindVertex(point);

            if (qv != null)
            {
                qVertex = qv;
                return;
            }

            var calculator = new PointVisibilityCalculator(listOfHoles, visibilityGraph, point, visibilityKind);

            calculator.FillGraph();
            qVertex = calculator.QVertex;
            Debug.Assert(qVertex != null);
        }
 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;
        }
        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 LoadEndOverlapVertexIfNeeded(VisibilityGraph vg) {
     // See comments in LoadStartOverlapVertexIfNeeded.
     if (NeedEndOverlapVertex) {
         VisibilityVertex vertex = vg.FindVertex(End);
         AppendVisibilityVertex(vg, vertex ?? vg.AddVertex(End));
     }
 }
 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));
     }
 }