@Test @Category(UnitTest.class) public void testInsideWithRightHorizontal() { Point v0 = GeometryFactory.createPoint(10.0, 10.0); Point v1 = GeometryFactory.createPoint(20.0, 10.0); Point p = GeometryFactory.createPoint(15.0, 5.0); Assert.assertFalse(GeometryUtils.inside(v0, v1, p)); p = GeometryFactory.createPoint(15.0, 15.0); Assert.assertTrue(GeometryUtils.inside(v0, v1, p)); p = GeometryFactory.createPoint(15.0, 10.0); Assert.assertFalse(GeometryUtils.inside(v0, v1, p)); }
public static boolean inside(Polygon poly, Point p) { LinearRing ring = poly.getExteriorRing(); Bounds b = ring.getBounds(); if (b.contains(p.getX(), p.getY())) { boolean odd = false; double x = p.getX(); double y = p.getY(); Point r1 = ring.getPoint(0); for (int i = 1; i < ring.getNumPoints(); i++) { Point r2 = ring.getPoint(i); double r1x = r1.getX(); double r1y = r1.getY(); double r2x = r2.getX(); double r2y = r2.getY(); if ((r1y < y && r2y >= y || r2y < y && r1y >= y) && (r1x <= x || r2x <= x)) { odd ^= (r1x + (y - r1y) / (r2y - r1y) * (r2x - r1x) < x); } r1 = r2; } return odd; } return false; }
GeometryUtils { public static boolean inside(Polygon poly, Point p) { LinearRing ring = poly.getExteriorRing(); Bounds b = ring.getBounds(); if (b.contains(p.getX(), p.getY())) { boolean odd = false; double x = p.getX(); double y = p.getY(); Point r1 = ring.getPoint(0); for (int i = 1; i < ring.getNumPoints(); i++) { Point r2 = ring.getPoint(i); double r1x = r1.getX(); double r1y = r1.getY(); double r2x = r2.getX(); double r2y = r2.getY(); if ((r1y < y && r2y >= y || r2y < y && r1y >= y) && (r1x <= x || r2x <= x)) { odd ^= (r1x + (y - r1y) / (r2y - r1y) * (r2x - r1x) < x); } r1 = r2; } return odd; } return false; } }
GeometryUtils { public static boolean inside(Polygon poly, Point p) { LinearRing ring = poly.getExteriorRing(); Bounds b = ring.getBounds(); if (b.contains(p.getX(), p.getY())) { boolean odd = false; double x = p.getX(); double y = p.getY(); Point r1 = ring.getPoint(0); for (int i = 1; i < ring.getNumPoints(); i++) { Point r2 = ring.getPoint(i); double r1x = r1.getX(); double r1y = r1.getY(); double r2x = r2.getX(); double r2y = r2.getY(); if ((r1y < y && r2y >= y || r2y < y && r1y >= y) && (r1x <= x || r2x <= x)) { odd ^= (r1x + (y - r1y) / (r2y - r1y) * (r2x - r1x) < x); } r1 = r2; } return odd; } return false; }  }
GeometryUtils { public static boolean inside(Polygon poly, Point p) { LinearRing ring = poly.getExteriorRing(); Bounds b = ring.getBounds(); if (b.contains(p.getX(), p.getY())) { boolean odd = false; double x = p.getX(); double y = p.getY(); Point r1 = ring.getPoint(0); for (int i = 1; i < ring.getNumPoints(); i++) { Point r2 = ring.getPoint(i); double r1x = r1.getX(); double r1y = r1.getY(); double r2x = r2.getX(); double r2y = r2.getY(); if ((r1y < y && r2y >= y || r2y < y && r1y >= y) && (r1x <= x || r2x <= x)) { odd ^= (r1x + (y - r1y) / (r2y - r1y) * (r2x - r1x) < x); } r1 = r2; } return odd; } return false; }  @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "Checking stored type 1st") static Geometry clip(Geometry geometry, Polygon clip); static Geometry clip(GeometryCollection collection, Polygon clip); static Geometry clip(LinearRing ring, Polygon clip); static Geometry clip(LineString line, Polygon clip); static Geometry clip(Point point, Polygon clip); static Geometry clip(Polygon poly, Polygon clip); static boolean colinear(Point p0, Point p1, Point p2); static Point computeIntersection(Point v0s, Point v0e, Point v1s,
    Point v1e); static boolean contains(Point v0, Point v1, Point p); static double dist(Point p0, Point p1); static double dist2(Point p0, Point p1); static boolean inside(Polygon poly, Point p); static boolean intersects(Polygon polygon, Geometry geometry); static boolean intersects(Point A, Point B, Point C, Point D); static boolean intersects(Point A, Point B, Point C, Point D,
    WritablePoint intersection); static boolean isOn(LinearRing clip, Point p); static Polygon toPoly(Bounds bounds); static LinearRing toRing(Bounds bounds); }
GeometryUtils { public static boolean inside(Polygon poly, Point p) { LinearRing ring = poly.getExteriorRing(); Bounds b = ring.getBounds(); if (b.contains(p.getX(), p.getY())) { boolean odd = false; double x = p.getX(); double y = p.getY(); Point r1 = ring.getPoint(0); for (int i = 1; i < ring.getNumPoints(); i++) { Point r2 = ring.getPoint(i); double r1x = r1.getX(); double r1y = r1.getY(); double r2x = r2.getX(); double r2y = r2.getY(); if ((r1y < y && r2y >= y || r2y < y && r1y >= y) && (r1x <= x || r2x <= x)) { odd ^= (r1x + (y - r1y) / (r2y - r1y) * (r2x - r1x) < x); } r1 = r2; } return odd; } return false; }  @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "Checking stored type 1st") static Geometry clip(Geometry geometry, Polygon clip); static Geometry clip(GeometryCollection collection, Polygon clip); static Geometry clip(LinearRing ring, Polygon clip); static Geometry clip(LineString line, Polygon clip); static Geometry clip(Point point, Polygon clip); static Geometry clip(Polygon poly, Polygon clip); static boolean colinear(Point p0, Point p1, Point p2); static Point computeIntersection(Point v0s, Point v0e, Point v1s,
    Point v1e); static boolean contains(Point v0, Point v1, Point p); static double dist(Point p0, Point p1); static double dist2(Point p0, Point p1); static boolean inside(Polygon poly, Point p); static boolean intersects(Polygon polygon, Geometry geometry); static boolean intersects(Point A, Point B, Point C, Point D); static boolean intersects(Point A, Point B, Point C, Point D,
    WritablePoint intersection); static boolean isOn(LinearRing clip, Point p); static Polygon toPoly(Bounds bounds); static LinearRing toRing(Bounds bounds);  }