use of org.apache.lucene.spatial3d.geom.SidedPlane in project lucene-solr by apache.
the class TestGeo3DPoint method verifyPolygon.
protected static boolean verifyPolygon(final PlanetModel pm, final Polygon polygon, final GeoPolygon outsidePolygon) {
// Each point in the new poly should be inside the outside poly, and each edge should not intersect the outside poly edge
final double[] lats = polygon.getPolyLats();
final double[] lons = polygon.getPolyLons();
final List<GeoPoint> polyPoints = new ArrayList<>(lats.length - 1);
for (int i = 0; i < lats.length - 1; i++) {
final GeoPoint newPoint = new GeoPoint(pm, toRadians(lats[i]), toRadians(lons[i]));
if (!outsidePolygon.isWithin(newPoint)) {
return false;
}
polyPoints.add(newPoint);
}
// We don't need to construct the world to find intersections -- just the bordering planes.
for (int planeIndex = 0; planeIndex < polyPoints.size(); planeIndex++) {
final GeoPoint startPoint = polyPoints.get(planeIndex);
final GeoPoint endPoint = polyPoints.get(legalIndex(planeIndex + 1, polyPoints.size()));
final GeoPoint beforeStartPoint = polyPoints.get(legalIndex(planeIndex - 1, polyPoints.size()));
final GeoPoint afterEndPoint = polyPoints.get(legalIndex(planeIndex + 2, polyPoints.size()));
final SidedPlane beforePlane = new SidedPlane(endPoint, beforeStartPoint, startPoint);
final SidedPlane afterPlane = new SidedPlane(startPoint, endPoint, afterEndPoint);
final Plane plane = new Plane(startPoint, endPoint);
// Check for intersections!!
if (outsidePolygon.intersects(plane, null, beforePlane, afterPlane)) {
return false;
}
}
return true;
}
Aggregations