@Test public void testIsPointInside() { Random random = new Random(4564656L); double[][] verticesArray = {{-10.0, 10.0}, {10.0, 10.0}, {10.0, -10.0}, {-10.0, -10.0}}; T doubles = createConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(verticesArray)); for (int i = 0; i < 10; i++) { int x = random.nextInt(10); int y = random.nextInt(10); assertTrue(doubles.isPointInside(x, y)); } }
@Test public void testIsPointInside1() { // single point polygon T polygon = createEmptyConvexPolygon2D(); polygon.addVertex(new Point2D(1.0, 1.0)); polygon.update(); Point2D point1 = new Point2D(1.0, 1.0); assertTrue(polygon.isPointInside(point1, EPSILON)); Point2D point2 = new Point2D(0.8, 0.9); assertFalse(polygon.isPointInside(point2)); Point2D point3 = new Point2D(0.8, 1.1); assertTrue(polygon.isPointInside(point3, 0.3)); Point2D point4 = new Point2D(1.0, 0.9); assertFalse(polygon.isPointInside(point4)); Point2D point5 = new Point2D(2.0, 1.0); assertFalse(polygon.isPointInside(point5)); assertTrue(polygon.isPointInside(point5, 1.0)); Point2D point6 = new Point2D(1.0, 2.0); assertFalse(polygon.isPointInside(point6)); assertTrue(polygon.isPointInside(point6, 1.0)); }
if (convexPolygon.isPointInside(testPoint)) assertNull(projectedPoint); else assertTrue("Projected point was not inside the polygon for point\n" + projectedPoint + "\nand convex polygon \n" + convexPolygon, convexPolygon.isPointInside(projectedPoint, 1.0E-10));
@Test public void testIsPointInside4() { // empty polygon T polygon = createEmptyConvexPolygon2D(); Point2D point1 = new Point2D(10.0, 0.0); assertFalse(polygon.isPointInside(point1, EPSILON)); }
@Test public void testIsPointInside2() { // line polygon T polygon = createEmptyConvexPolygon2D(); polygon.addVertex(new Point2D(0.0, 0.0)); polygon.addVertex(new Point2D(1.0, 0.0)); polygon.update(); Point2D point1 = new Point2D(0.1, 0.0); assertTrue(polygon.isPointInside(point1, EPSILON)); Point2D point2 = new Point2D(0.1, 0.1); assertFalse(polygon.isPointInside(point2, EPSILON)); Point2D point3 = new Point2D(1.5, 0.0); assertFalse(polygon.isPointInside(point3, EPSILON)); Point2D point4 = new Point2D(1.0, 0.0); assertTrue(polygon.isPointInside(point4.getX(), point4.getY())); Point2D point5 = new Point2D(1.0, EPSILON * 0.1); assertFalse(polygon.isPointInside(point5.getX(), point5.getY())); Point2D point6 = new Point2D(1.0, EPSILON * 0.1); assertTrue(polygon.isPointInside(point6, EPSILON)); Point2D point7 = new Point2D(1.5, 0.0); assertTrue(polygon.isPointInside(point7, 0.5)); }
@Test public void testIsInside() { double[][] polygonPoints = new double[][] {{-0.05107802536335158, 0.04155594197133163}, {-0.05052044462374434, 0.1431544119584275}, {0.12219695435431863, 0.14220652470109518}, {0.12219695435431865, -0.041946248489056696}, {0.12163937361471142, -0.1435447184761526}, {-0.05107802536335154, -0.14259683121882027}}; Point2D testPoint = new Point2D(-0.04907805548171582, 2.6934439541712686E-4); T polygon = createConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(polygonPoints)); boolean isInside = polygon.isPointInside(testPoint); assertTrue(isInside); }
@Test public void testIsPointInside3() { // triangle polygon T polygon = createEmptyConvexPolygon2D(); polygon.addVertex(new Point2D(0.0, 0.0)); polygon.addVertex(new Point2D(5.0, 0.0)); polygon.addVertex(new Point2D(3.0, 5.0)); polygon.update(); Point2D point1 = new Point2D(0.3, 0.0); assertTrue(polygon.isPointInside(point1, EPSILON)); Point2D point2 = new Point2D(0.0, 0.0); assertTrue(polygon.isPointInside(point2, EPSILON)); Point2D point3 = new Point2D(2.0, 2.0); assertTrue(polygon.isPointInside(point3)); Point2D point4 = new Point2D(1.0, 0.3); assertTrue(polygon.isPointInside(point4, EPSILON)); Point2D point5 = new Point2D(-1.0, 4.0); assertFalse(polygon.isPointInside(point5.getX(), point5.getY(), EPSILON)); Point2D point6 = new Point2D(6.0, 7.0); assertFalse(polygon.isPointInside(point6, EPSILON)); Point2D point7 = new Point2D(10.0, 0.0); assertFalse(polygon.isPointInside(point7, EPSILON)); Point2D point8 = new Point2D(0.1, 0.2); assertFalse(polygon.isPointInside(point8)); Point2D point9 = new Point2D(3.5, 4.9); assertFalse(polygon.isPointInside(point9.getX(), point9.getY(), EPSILON)); Point2D point10 = new Point2D(3.5, -1.0); assertFalse(polygon.isPointInside(point10)); }
@Test public void testIsPointInside5() { // foot polygon T polygon = createEmptyConvexPolygon2D(); polygon.addVertex(new Point2D(-0.06, -0.08)); polygon.addVertex(new Point2D(0.14, -0.08)); polygon.addVertex(new Point2D(0.14, -0.19)); polygon.addVertex(new Point2D(-0.06, -0.19)); polygon.update(); Point2D point1 = new Point2D(0.03, 0.0); assertFalse(polygon.isPointInside(point1, 0.02)); Point2D point2 = new Point2D(0.03, -0.09); assertTrue(polygon.isPointInside(point2)); }
Point2D point = new Point2D(1.314592, 6.0221415); // Useless Riddle: first number is easy, second one multiplied by 1e23 is called? assertFalse(polygon.isPointInside(point));