findEdgeRingContaining static method
Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
The innermost enclosing ring is the smallest 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)
@return containing EdgeRing, if there is one or null if no containing EdgeRing is found
Implementation
static EdgeRing findEdgeRingContaining(EdgeRing testEr, List shellList) {
LinearRing testRing = testEr.getLinearRing()!;
Envelope testEnv = testRing.getEnvelopeInternal();
Coordinate? testPt = testRing.getCoordinateN(0);
EdgeRing? minShell = null;
Envelope? minShellEnv = null;
for (EdgeRing tryShell in shellList) {
LinearRing tryShellRing = tryShell.getLinearRing()!;
Envelope tryShellEnv = tryShellRing.getEnvelopeInternal();
// the hole envelope cannot equal the shell envelope
// (also guards against testing rings against themselves)
if (tryShellEnv == testEnv) continue;
// hole must be contained in shell
if (!tryShellEnv.containsEnvelope(testEnv)) continue;
testPt = CoordinateArrays.ptNotInList(
testRing.getCoordinates(), tryShellRing.getCoordinates());
bool isContained = false;
if (PointLocation.isInRing(testPt!, tryShellRing.getCoordinates()))
isContained = true;
// check if this new containing ring is smaller than the current minimum ring
if (isContained) {
if (minShell == null || minShellEnv!.containsEnvelope(tryShellEnv)) {
minShell = tryShell;
minShellEnv = minShell.getLinearRing()!.getEnvelopeInternal();
}
}
}
return minShell!;
}