private static int quickTest2DMultiPointPoint(MultiPoint geomA, Point2D ptB, double tolerance) { // TODO: Add Geometry accelerator. (RasterizedGeometry + kd-tree or // alike) for (int i = 0, n = geomA.getPointCount(); i < n; i++) { Point2D ptA; ptA = geomA.getXY(i); int res = quickTest2DPointPoint(ptA, ptB, tolerance); if (res != (int) Relation.Disjoint) { if ((res & (int) Relation.Within) != 0 && n != 1) { // _ASSERT(res & (int)Relation.Contains); return (int) Relation.Contains; } return res; } } return (int) Relation.Disjoint; }
private static int quickTest2DMultiPointPoint(MultiPoint geomA, Point2D ptB, double tolerance) { // TODO: Add Geometry accelerator. (RasterizedGeometry + kd-tree or // alike) for (int i = 0, n = geomA.getPointCount(); i < n; i++) { Point2D ptA; ptA = geomA.getXY(i); int res = quickTest2DPointPoint(ptA, ptB, tolerance); if (res != (int) Relation.Disjoint) { if ((res & (int) Relation.Within) != 0 && n != 1) { // _ASSERT(res & (int)Relation.Contains); return (int) Relation.Contains; } return res; } } return (int) Relation.Disjoint; }
static boolean multiPointDisjointPointImpl_(MultiPoint multipoint_a, Point2D pt_b, double tolerance, ProgressTracker progressTracker) { Point2D pt_a = new Point2D(); double tolerance_sq = tolerance * tolerance; for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (Point2D.sqrDistance(pt_a, pt_b) <= tolerance_sq) return false; } return true; }
static boolean multiPointDisjointPointImpl_(MultiPoint multipoint_a, Point2D pt_b, double tolerance, ProgressTracker progressTracker) { Point2D pt_a = new Point2D(); double tolerance_sq = tolerance * tolerance; for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (Point2D.sqrDistance(pt_a, pt_b) <= tolerance_sq) return false; } return true; }
private static Point2D computePointsCentroid(MultiPoint multiPoint) { double xSum = 0; double ySum = 0; int pointCount = multiPoint.getPointCount(); Point2D point2D = new Point2D(); for (int i = 0; i < pointCount; i++) { multiPoint.getXY(i, point2D); xSum += point2D.x; ySum += point2D.y; } return new Point2D(xSum / pointCount, ySum / pointCount); }
private static Point2D computePointsCentroid(MultiPoint multiPoint) { double xSum = 0; double ySum = 0; int pointCount = multiPoint.getPointCount(); Point2D point2D = new Point2D(); for (int i = 0; i < pointCount; i++) { multiPoint.getXY(i, point2D); xSum += point2D.x; ySum += point2D.y; } return new Point2D(xSum / pointCount, ySum / pointCount); }
private static boolean multiPointContainsMultiPointBrute_( MultiPoint multipoint_a, MultiPoint multipoint_b, double tolerance) { double tolerance_sq = tolerance * tolerance; Point2D pt_a = new Point2D(); Point2D pt_b = new Point2D(); for (int i = 0; i < multipoint_b.getPointCount(); i++) { multipoint_b.getXY(i, pt_b); boolean b_contained = false; for (int j = 0; j < multipoint_a.getPointCount(); j++) { multipoint_a.getXY(j, pt_a); if (Point2D.sqrDistance(pt_a, pt_b) <= tolerance_sq) { b_contained = true; break; } } if (!b_contained) return false; } return true; }
private static boolean multiPointContainsMultiPointBrute_( MultiPoint multipoint_a, MultiPoint multipoint_b, double tolerance) { double tolerance_sq = tolerance * tolerance; Point2D pt_a = new Point2D(); Point2D pt_b = new Point2D(); for (int i = 0; i < multipoint_b.getPointCount(); i++) { multipoint_b.getXY(i, pt_b); boolean b_contained = false; for (int j = 0; j < multipoint_a.getPointCount(); j++) { multipoint_a.getXY(j, pt_a); if (Point2D.sqrDistance(pt_a, pt_b) <= tolerance_sq) { b_contained = true; break; } } if (!b_contained) return false; } return true; }
private static boolean multiPointExactlyEqualsMultiPoint_( MultiPoint multipoint_a, MultiPoint multipoint_b, double tolerance, ProgressTracker progress_tracker) { if (multipoint_a.getPointCount() != multipoint_b.getPointCount()) return false; Point2D ptA = new Point2D(), ptB = new Point2D(); boolean bAllPointsEqual = true; double tolerance_sq = tolerance * tolerance; for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, ptA); multipoint_b.getXY(i, ptB); if (Point2D.sqrDistance(ptA, ptB) > tolerance_sq) { bAllPointsEqual = false; break; } } if (!bAllPointsEqual) return false; return true; }
private static boolean multiPointExactlyEqualsMultiPoint_( MultiPoint multipoint_a, MultiPoint multipoint_b, double tolerance, ProgressTracker progress_tracker) { if (multipoint_a.getPointCount() != multipoint_b.getPointCount()) return false; Point2D ptA = new Point2D(), ptB = new Point2D(); boolean bAllPointsEqual = true; double tolerance_sq = tolerance * tolerance; for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, ptA); multipoint_b.getXY(i, ptB); if (Point2D.sqrDistance(ptA, ptB) > tolerance_sq) { bAllPointsEqual = false; break; } } if (!bAllPointsEqual) return false; return true; }
for (int ib = 0, nb = geomB.getPointCount(); ib < nb; ib++) { Point2D ptB; ptB = geomB.getXY(ib); int res = quickTest2DMultiPointPoint(geomA, ptB, tolerance); if (res != (int) Relation.Disjoint) {
for (int ib = 0, nb = geomB.getPointCount(); ib < nb; ib++) { Point2D ptB; ptB = geomB.getXY(ib); int res = quickTest2DMultiPointPoint(geomA, ptB, tolerance); if (res != (int) Relation.Disjoint) {
private static int quickTest2DMultiPointEnvelope(MultiPoint geomA, Envelope2D geomBEnv, double tolerance, int testType) { // Add early bailout for disjoint test. Envelope2D envBMinus = geomBEnv; envBMinus.inflate(-tolerance, -tolerance); Envelope2D envBPlus = geomBEnv; envBPlus.inflate(tolerance, tolerance); int dres = 0; for (int i = 0, n = geomA.getPointCount(); i < n; i++) { Point2D ptA; ptA = geomA.getXY(i); int res = reverseResult(quickTest2DEnvelopePoint(envBPlus, envBMinus, ptA, tolerance)); if (res != (int) Relation.Disjoint) { dres |= res; if (testType == (int) Relation.Disjoint) return (int) Relation.Intersects; } } if (dres == 0) return (int) Relation.Disjoint; if (dres == (int) Relation.Within) return dres; return (int) Relation.Overlaps; }
private static int quickTest2DMultiPointEnvelope(MultiPoint geomA, Envelope2D geomBEnv, double tolerance, int testType) { // Add early bailout for disjoint test. Envelope2D envBMinus = geomBEnv; envBMinus.inflate(-tolerance, -tolerance); Envelope2D envBPlus = geomBEnv; envBPlus.inflate(tolerance, tolerance); int dres = 0; for (int i = 0, n = geomA.getPointCount(); i < n; i++) { Point2D ptA; ptA = geomA.getXY(i); int res = reverseResult(quickTest2DEnvelopePoint(envBPlus, envBMinus, ptA, tolerance)); if (res != (int) Relation.Disjoint) { dres |= res; if (testType == (int) Relation.Disjoint) return (int) Relation.Intersects; } } if (dres == 0) return (int) Relation.Disjoint; if (dres == (int) Relation.Within) return dres; return (int) Relation.Overlaps; }
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 multiPointMinusEnvelope_(MultiPoint multi_point, Envelope envelope, double tolerance, ProgressTracker progress_tracker) { Envelope2D env = new Envelope2D(); envelope.queryEnvelope2D(env); env.inflate(tolerance, tolerance); int point_count = multi_point.getPointCount(); boolean b_found_covered = false; boolean[] covered = new boolean[point_count]; for (int i = 0; i < point_count; i++) covered[i] = false; Point2D pt = new Point2D(); for (int i = 0; i < point_count; i++) { multi_point.getXY(i, pt); if (!env.contains(pt)) continue; b_found_covered = true; covered[i] = true; } if (!b_found_covered) return multi_point; MultiPoint new_multipoint = (MultiPoint) multi_point.createInstance(); for (int i = 0; i < point_count; i++) { if (!covered[i]) new_multipoint.add(multi_point, i, i + 1); } return new_multipoint; }
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; }
multi_point.getXY(i, pt);
private static boolean multiPointDisjointEnvelope_(MultiPoint multipoint_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); multipoint_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; Envelope2D env_b_inflated = new Envelope2D(); env_b_inflated.setCoords(env_b); env_b_inflated.inflate(tolerance, tolerance); Point2D pt_a = new Point2D(); for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (!env_b_inflated.contains(pt_a)) continue; return false; } return true; }
private static boolean multiPointDisjointEnvelope_(MultiPoint multipoint_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); multipoint_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; Envelope2D env_b_inflated = new Envelope2D(); env_b_inflated.setCoords(env_b); env_b_inflated.inflate(tolerance, tolerance); Point2D pt_a = new Point2D(); for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (!env_b_inflated.contains(pt_a)) continue; return false; } return true; }