Search in sources :

Example 1 with SidedPlane

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;
}
Also used : GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint) SidedPlane(org.apache.lucene.spatial3d.geom.SidedPlane) SidedPlane(org.apache.lucene.spatial3d.geom.SidedPlane) Plane(org.apache.lucene.spatial3d.geom.Plane) ArrayList(java.util.ArrayList) GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint)

Aggregations

ArrayList (java.util.ArrayList)1 GeoPoint (org.apache.lucene.spatial3d.geom.GeoPoint)1 Plane (org.apache.lucene.spatial3d.geom.Plane)1 SidedPlane (org.apache.lucene.spatial3d.geom.SidedPlane)1