hasClosedEndpointIntersection method
Tests that no edge intersection is the endpoint of a closed line. This ensures that closed lines are not touched at their endpoint, which is an interior point according to the Mod-2 rule To check this we compute the degree of each endpoint. The degree of endpoints of closed lines must be exactly 2.
Implementation
bool hasClosedEndpointIntersection(GeometryGraph graph) {
Map endPoints = new SplayTreeMap();
for (Iterator i = graph.getEdgeIterator(); i.moveNext();) {
Edge e = i.current as Edge;
bool isClosed = e.isClosed();
Coordinate p0 = e.getCoordinateWithIndex(0);
addEndpoint(endPoints, p0, isClosed);
Coordinate p1 = e.getCoordinateWithIndex(e.getNumPoints() - 1);
addEndpoint(endPoints, p1, isClosed);
}
for (Iterator i = endPoints.values.iterator; i.moveNext();) {
EndpointInfo eiInfo = i.current as EndpointInfo;
if (eiInfo.isClosed && eiInfo.degree != 2) {
nonSimpleLocation = eiInfo.getCoordinate();
return true;
}
}
return false;
}