/// <summary> /// /// </summary> /// <param name="er"></param> /// <returns></returns> public int GetOutgoingDegree(EdgeRing er) { int degree = 0; for (IEnumerator it = GetEnumerator(); it.MoveNext(); ) { DirectedEdge de = (DirectedEdge)it.Current; if (de.EdgeRing == er) degree++; } return degree; }
/// <summary> /// This method will cause the ring to be computed. /// It will also check any holes, if they have been assigned. /// </summary> /// <param name="p"></param> public bool ContainsPoint(ICoordinate p) { ILinearRing shell = LinearRing; IEnvelope env = shell.EnvelopeInternal; if (!env.Contains(p)) { return(false); } if (!CGAlgorithms.IsPointInRing(p, shell.Coordinates)) { return(false); } for (IEnumerator i = holes.GetEnumerator(); i.MoveNext();) { EdgeRing hole = (EdgeRing)i.Current; if (hole.ContainsPoint(p)) { return(false); } } return(true); }
/// <summary> /// Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any. /// The innermost enclosing ring is the <i>smallest</i> enclosing ring. /// The algorithm used depends on the fact that: /// ring A contains ring B iff envelope(ring A) contains envelope(ring B). /// This routine is only safe to use if the chosen point of the hole /// is known to be properly contained in a shell /// (which is guaranteed to be the case if the hole does not touch its shell). /// </summary> /// <param name="testEr"></param> /// <param name="shellList"></param> /// <returns>Containing EdgeRing, if there is one, OR /// null if no containing EdgeRing is found.</returns> private EdgeRing FindEdgeRingContaining(EdgeRing testEr, IList shellList) { ILinearRing teString = testEr.LinearRing; IEnvelope testEnv = teString.EnvelopeInternal; ICoordinate testPt = teString.GetCoordinateN(0); EdgeRing minShell = null; IEnvelope minEnv = null; for (IEnumerator it = shellList.GetEnumerator(); it.MoveNext(); ) { EdgeRing tryShell = (EdgeRing) it.Current; ILinearRing tryRing = tryShell.LinearRing; IEnvelope tryEnv = tryRing.EnvelopeInternal; if (minShell != null) minEnv = minShell.LinearRing.EnvelopeInternal; bool isContained = false; if (tryEnv.Contains(testEnv) && CGAlgorithms.IsPointInRing(testPt, tryRing.Coordinates)) isContained = true; // check if this new containing ring is smaller than the current minimum ring if (isContained) { if (minShell == null || minEnv.Contains(tryEnv)) minShell = tryShell; } } return minShell; }
/// <summary> /// This method assigns the holes for a Polygon (formed from a list of /// MinimalEdgeRings) to its shell. /// Determining the holes for a MinimalEdgeRing polygon serves two purposes: /// it is faster than using a point-in-polygon check later on. /// it ensures correctness, since if the PIP test was used the point /// chosen might lie on the shell, which might return an incorrect result from the /// PIP test. /// </summary> /// <param name="shell"></param> /// <param name="minEdgeRings"></param> private void PlacePolygonHoles(EdgeRing shell, IList minEdgeRings) { for (IEnumerator it = minEdgeRings.GetEnumerator(); it.MoveNext(); ) { MinimalEdgeRing er = (MinimalEdgeRing) it.Current; if (er.IsHole) er.Shell = shell; } }
/// <summary> /// /// </summary> /// <param name="de"></param> /// <param name="er"></param> public override void SetEdgeRing(DirectedEdge de, EdgeRing er) { de.EdgeRing = er; }
/// <summary> /// /// </summary> /// <param name="de"></param> /// <param name="er"></param> abstract public void SetEdgeRing(DirectedEdge de, EdgeRing er);
/// <summary> /// /// </summary> /// <param name="ring"></param> public void AddHole(EdgeRing ring) { holes.Add(ring); }
/// <summary> /// /// </summary> /// <param name="er"></param> public void LinkMinimalDirectedEdges(EdgeRing er) { // find first area edge (if any) to start linking at DirectedEdge firstOut = null; DirectedEdge incoming = null; int state = ScanningForIncoming; // link edges in CW order for (int i = resultAreaEdgeList.Count - 1; i >= 0; i--) { DirectedEdge nextOut = (DirectedEdge)resultAreaEdgeList[i]; DirectedEdge nextIn = nextOut.Sym; // record first outgoing edge, in order to link the last incoming edge if (firstOut == null && nextOut.EdgeRing == er) firstOut = nextOut; switch (state) { case ScanningForIncoming: if (nextIn.EdgeRing != er) continue; incoming = nextIn; state = LinkingToOutgoing; break; case LinkingToOutgoing: if (nextOut.EdgeRing != er) continue; incoming.NextMin = nextOut; state = ScanningForIncoming; break; default: break; } } if (state == LinkingToOutgoing) { Assert.IsTrue(firstOut != null, "found null for first outgoing dirEdge"); Assert.IsTrue(firstOut.EdgeRing == er, "unable to link last incoming dirEdge"); incoming.NextMin = firstOut; } }