();
// Search the according node pairs in the other ring
for (int i : thisSwitchPoints) {
LatLon a = thisBorder.get(i - 1).getLatLon();
LatLon b = thisBorder.get(i).getLatLon();
otherSwitchPoints.add(getTheSegmentRingIntersectsSegment(a, b));
}
/*
* TODO:
*
* * Split the other Ring into ways from splitPoint to splitPoint
*
* * Split this ring into ways from splitPoint to splitPoint
*
* * Filter out the parts of way from this that are inside the other Ring
* Use the insideOther var and the switchPoints list for this.
*
* * For each two parts of way from this, search a part of way connecting the two.
* If there are two, take the shortest.
*/
}
/**
* Get the segment of the Ring that intersects a segment
* going from point a to point b
*
* @param a the begin point of the segment
* @param b the end point of the segment
* @return an integer i which is the index so that the segment
* from getBorder().get(i-1) to getBorder().get(i) intersects with
* the segment from parameters a to b.
*
* 0 if the segment from a to b doesn't intersect with the Ring.
*/
private int getTheSegmentRingIntersectsSegment(LatLon a, LatLon b) {
List border = getBorder();
for (int i = 1; i < border.size(); i++) {
LatLon c = border.get(i - 1).getLatLon();
LatLon d = border.get(i).getLatLon();
if (MapAlgorithms.linesIntersect(
a.getLatitude(), a.getLongitude(),
b.getLatitude(), b.getLongitude(),
c.getLatitude(), c.getLongitude(),
d.getLatitude(), d.getLongitude())) {
return i;
}
}
return 0;
}
public double getArea() {
if (area == -1) {
//cache the area
area = OsmMapUtils.getArea(getBorder());
}
return area;
}
public LinearRing toLinearRing() {
GeometryFactory geometryFactory = new GeometryFactory();
CoordinateList coordinates = new CoordinateList();
for (Node node : border.getNodes()) {
coordinates.add(new Coordinate(node.getLatitude(), node.getLongitude()), true);
}
coordinates.closeRing();
return geometryFactory.createLinearRing(coordinates.toCoordinateArray());
}
/**
* Use area size as comparable metric
*/
@Override
public int compareTo(Ring r) {
return Double.compare(getArea(), r.getArea());
}
}