private static boolean polygonContainsPolygon_(Polygon polygon_a, Polygon polygon_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); polygon_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. if (!envelopeInfContainsEnvelope_(env_a, env_b, tolerance)) return false; // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, polygon_b, tolerance, false); if (relation == Relation.disjoint || relation == Relation.within) return false; if (relation == Relation.contains) return true; return polygonContainsPolygonImpl_(polygon_a, polygon_b, tolerance, progress_tracker); }
private static boolean polygonContainsPolygon_(Polygon polygon_a, Polygon polygon_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); polygon_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. if (!envelopeInfContainsEnvelope_(env_a, env_b, tolerance)) return false; // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, polygon_b, tolerance, false); if (relation == Relation.disjoint || relation == Relation.within) return false; if (relation == Relation.contains) return true; return polygonContainsPolygonImpl_(polygon_a, polygon_b, tolerance, progress_tracker); }
private static boolean polygonWithinEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); return envelopeInfContainsEnvelope_(env_b, env_a, tolerance); }
private static boolean polygonWithinEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); return envelopeInfContainsEnvelope_(env_b, env_a, tolerance); }
private static boolean polygonEqualsPolygon_(Polygon polygon_a, Polygon polygon_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); polygon_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. if (!envelopeEqualsEnvelope_(env_a, env_b, tolerance, progress_tracker)) return false; // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, polygon_b, tolerance, false); if (relation == Relation.disjoint || relation == Relation.contains || relation == Relation.within) return false; // Quick point equality check for true equality. This just checks if all // the points in each ring are the same (within a tolerance) and in the // same order if (multiPathExactlyEqualsMultiPath_(polygon_a, polygon_b, tolerance, progress_tracker)) return true; double length_a = polygon_a.calculateLength2D(); double length_b = polygon_b.calculateLength2D(); int max_vertices = Math.max(polygon_a.getPointCount(), polygon_b.getPointCount()); if (Math.abs(length_a - length_b) > max_vertices * 4.0 * tolerance) return false; return linearPathEqualsLinearPath_(polygon_a, polygon_b, tolerance, true); }
private void areaGeomContainsOrDisjointPredicates_(Polygon polygon, int matrix_interior, char c1, int matrix_boundary, char c2) { if (matrix_interior != -1 || matrix_boundary != -1) { boolean has_area = ((c1 != 'T' && c1 != 'F' && matrix_interior != -1) || (c2 != 'T' && c2 != 'F' && matrix_boundary != -1) ? polygon.calculateArea2D() != 0 : true); if (has_area) { if (matrix_interior != -1) m_matrix[matrix_interior] = 2; if (matrix_boundary != -1) m_matrix[matrix_boundary] = 1; } else { if (matrix_boundary != -1) m_matrix[matrix_boundary] = -1; if (matrix_interior != -1) { Envelope2D env = new Envelope2D(); polygon.queryEnvelope2D(env); m_matrix[matrix_interior] = (env.getHeight() == 0.0 && env.getWidth() == 0.0 ? 0 : 1); } } } }
private void areaGeomContainsOrDisjointPredicates_(Polygon polygon, int matrix_interior, char c1, int matrix_boundary, char c2) { if (matrix_interior != -1 || matrix_boundary != -1) { boolean has_area = ((c1 != 'T' && c1 != 'F' && matrix_interior != -1) || (c2 != 'T' && c2 != 'F' && matrix_boundary != -1) ? polygon.calculateArea2D() != 0 : true); if (has_area) { if (matrix_interior != -1) m_matrix[matrix_interior] = 2; if (matrix_boundary != -1) m_matrix[matrix_boundary] = 1; } else { if (matrix_boundary != -1) m_matrix[matrix_boundary] = -1; if (matrix_interior != -1) { Envelope2D env = new Envelope2D(); polygon.queryEnvelope2D(env); m_matrix[matrix_interior] = (env.getHeight() == 0.0 && env.getWidth() == 0.0 ? 0 : 1); } } } }
private static boolean polygonContainsPolyline_(Polygon polygon_a, Polyline polyline_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); polyline_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. if (!envelopeInfContainsEnvelope_(env_a, env_b, tolerance)) return false; // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, polyline_b, tolerance, false); if (relation == Relation.disjoint) return false; if (relation == Relation.contains) return true; return polygonContainsPolylineImpl_(polygon_a, polyline_b, tolerance, progress_tracker); }
private static boolean polygonContainsPolyline_(Polygon polygon_a, Polyline polyline_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); polyline_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. if (!envelopeInfContainsEnvelope_(env_a, env_b, tolerance)) return false; // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, polyline_b, tolerance, false); if (relation == Relation.disjoint) return false; if (relation == Relation.contains) return true; return polygonContainsPolylineImpl_(polygon_a, polyline_b, tolerance, progress_tracker); }
private static boolean polygonEqualsEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. // This check will correctly handle degenerate envelope cases (i.e. // degenerate to point or line) if (!envelopeEqualsEnvelope_(env_a, env_b, tolerance, progress_tracker)) return false; Polygon polygon_b = new Polygon(); polygon_b.addEnvelope(envelope_b, false); return linearPathEqualsLinearPath_(polygon_a, polygon_b, tolerance, true); }
private static boolean polygonEqualsEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); // Quick envelope rejection test for false equality. // This check will correctly handle degenerate envelope cases (i.e. // degenerate to point or line) if (!envelopeEqualsEnvelope_(env_a, env_b, tolerance, progress_tracker)) return false; Polygon polygon_b = new Polygon(); polygon_b.addEnvelope(envelope_b, false); return linearPathEqualsLinearPath_(polygon_a, polygon_b, tolerance, true); }
private static boolean polygonContainsPolygonImpl_(Polygon polygon_a, Polygon polygon_b, double tolerance, ProgressTracker progressTracker) { boolean[] b_result_known = new boolean[1]; b_result_known[0] = false; boolean res = polygonContainsMultiPath_(polygon_a, polygon_b, tolerance, b_result_known, progressTracker); if (b_result_known[0]) return res; // We can clip polygon_a to the extent of polyline_b Envelope2D envBInflated = new Envelope2D(); polygon_b.queryEnvelope2D(envBInflated); envBInflated.inflate(1000.0 * tolerance, 1000.0 * tolerance); Polygon _polygonA = null; if (polygon_a.getPointCount() > 10) { _polygonA = (Polygon)Clipper.clip(polygon_a, envBInflated, tolerance, 0.0); if (_polygonA.isEmpty()) return false; } else { _polygonA = polygon_a; } boolean bContains = RelationalOperationsMatrix.polygonContainsPolygon_(_polygonA, polygon_b, tolerance, progressTracker); return bContains; }
private static boolean polygonContainsPolygonImpl_(Polygon polygon_a, Polygon polygon_b, double tolerance, ProgressTracker progressTracker) { boolean[] b_result_known = new boolean[1]; b_result_known[0] = false; boolean res = polygonContainsMultiPath_(polygon_a, polygon_b, tolerance, b_result_known, progressTracker); if (b_result_known[0]) return res; // We can clip polygon_a to the extent of polyline_b Envelope2D envBInflated = new Envelope2D(); polygon_b.queryEnvelope2D(envBInflated); envBInflated.inflate(1000.0 * tolerance, 1000.0 * tolerance); Polygon _polygonA = null; if (polygon_a.getPointCount() > 10) { _polygonA = (Polygon)Clipper.clip(polygon_a, envBInflated, tolerance, 0.0); if (_polygonA.isEmpty()) return false; } else { _polygonA = polygon_a; } boolean bContains = RelationalOperationsMatrix.polygonContainsPolygon_(_polygonA, polygon_b, tolerance, progressTracker); return bContains; }
private static boolean polygonDisjointMultiPoint_(Polygon polygon_a, MultiPoint multipoint_b, double tolerance, boolean bIncludeBoundaryA, ProgressTracker progress_tracker) { // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, multipoint_b, tolerance, false); if (relation == Relation.disjoint) return true; if (relation == Relation.contains) return false; Envelope2D env_a_inflated = new Envelope2D(); polygon_a.queryEnvelope2D(env_a_inflated); env_a_inflated.inflate(tolerance, tolerance); Point2D ptB = new Point2D(); for (int i = 0; i < multipoint_b.getPointCount(); i++) { multipoint_b.getXY(i, ptB); if (!env_a_inflated.contains(ptB)) continue; PolygonUtils.PiPResult result = PolygonUtils.isPointInPolygon2D( polygon_a, ptB, tolerance); if (result == PolygonUtils.PiPResult.PiPInside || (bIncludeBoundaryA && result == PolygonUtils.PiPResult.PiPBoundary)) return false; } return true; }
private static boolean polygonDisjointMultiPoint_(Polygon polygon_a, MultiPoint multipoint_b, double tolerance, boolean bIncludeBoundaryA, ProgressTracker progress_tracker) { // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, multipoint_b, tolerance, false); if (relation == Relation.disjoint) return true; if (relation == Relation.contains) return false; Envelope2D env_a_inflated = new Envelope2D(); polygon_a.queryEnvelope2D(env_a_inflated); env_a_inflated.inflate(tolerance, tolerance); Point2D ptB = new Point2D(); for (int i = 0; i < multipoint_b.getPointCount(); i++) { multipoint_b.getXY(i, ptB); if (!env_a_inflated.contains(ptB)) continue; PolygonUtils.PiPResult result = PolygonUtils.isPointInPolygon2D( polygon_a, ptB, tolerance); if (result == PolygonUtils.PiPResult.PiPInside || (bIncludeBoundaryA && result == PolygonUtils.PiPResult.PiPBoundary)) return false; } return true; }
static Geometry multiPointMinusPolygon_(MultiPoint multi_point, Polygon polygon, double tolerance, ProgressTracker progress_tracker) { Envelope2D env = new Envelope2D(); polygon.queryEnvelope2D(env); env.inflate(tolerance, tolerance);
private static boolean polygonOverlapsEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, envelope_b, tolerance, false); if (relation == Relation.disjoint || relation == Relation.contains || relation == Relation.within) return false; Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; if (env_b.getWidth() <= tolerance || env_b.getHeight() <= tolerance) return false; // has no interior Polygon polygon_b = new Polygon(); polygon_b.addEnvelope(envelope_b, false); return polygonOverlapsPolygonImpl_(polygon_a, polygon_b, tolerance, progress_tracker); }
private static boolean polygonOverlapsEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { // Quick rasterize test to see whether the the geometries are disjoint, // or if one is contained in the other. int relation = tryRasterizedContainsOrDisjoint_(polygon_a, envelope_b, tolerance, false); if (relation == Relation.disjoint || relation == Relation.contains || relation == Relation.within) return false; Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; if (env_b.getWidth() <= tolerance || env_b.getHeight() <= tolerance) return false; // has no interior Polygon polygon_b = new Polygon(); polygon_b.addEnvelope(envelope_b, false); return polygonOverlapsPolygonImpl_(polygon_a, polygon_b, tolerance, progress_tracker); }
private static boolean polygonCrossesEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; if (env_b.getHeight() > tolerance && env_b.getWidth() > tolerance) return false; // when treated as an area, areas cannot cross areas. if (env_b.getHeight() <= tolerance && env_b.getWidth() <= tolerance) return false; // when treated as a point, areas cannot cross points. // Treat as polyline Polyline polyline_b = new Polyline(); Point p = new Point(); envelope_b.queryCornerByVal(0, p); polyline_b.startPath(p); envelope_b.queryCornerByVal(2, p); polyline_b.lineTo(p); return polygonCrossesPolylineImpl_(polygon_a, polyline_b, tolerance, progress_tracker); }
private static boolean polygonCrossesEnvelope_(Polygon polygon_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polygon_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; if (env_b.getHeight() > tolerance && env_b.getWidth() > tolerance) return false; // when treated as an area, areas cannot cross areas. if (env_b.getHeight() <= tolerance && env_b.getWidth() <= tolerance) return false; // when treated as a point, areas cannot cross points. // Treat as polyline Polyline polyline_b = new Polyline(); Point p = new Point(); envelope_b.queryCornerByVal(0, p); polyline_b.startPath(p); envelope_b.queryCornerByVal(2, p); polyline_b.lineTo(p); return polygonCrossesPolylineImpl_(polygon_a, polyline_b, tolerance, progress_tracker); }