public void computeMinimumDistancePoints(ConvexPolygon2DReadOnly polygon1, ConvexPolygon2DReadOnly polygon2, Point2DBasics point1ToPack, Point2DBasics point2ToPack) { computeMinimumDistancePoints(polygon1, polygon2, .01, point1ToPack, point2ToPack); }
public static Point2d[] computeMinimumDistancePoints(ConvexPolygon2d polygon1, ConvexPolygon2d polygon2) { return computeMinimumDistancePoints(polygon1, polygon2, .01); }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testDistanceBetweenPolygonsIntersectingPolygons() { ConvexPolygon2D polygon1 = getPolygon(new double[] {0, 0, 0, 1, 1, 0, 2, 1, 1, 2}); ConvexPolygon2D polygon2 = getPolygon(new double[] {1, 1, 0, 3, 2, 2, 3, 0}); try { new ConvexPolygonTools().computeMinimumDistancePoints(polygon1, polygon2, new Point2D(), new Point2D()); fail(); } catch (RuntimeException re) { assertEquals(re.getMessage(), "Cannot compute minimum distance between intersecting polygons."); } try { new ConvexPolygonTools().computeMinimumDistancePoints(polygon2, polygon1, new Point2D(), new Point2D()); fail(); } catch (RuntimeException re) { assertEquals(re.getMessage(), "Cannot compute minimum distance between intersecting polygons."); } }
private void assertPolygons(double[] p1, double[] p2, double[] expectedSolution, double epsilon) { if (expectedSolution.length != 4) { throw new RuntimeException("Invalid input."); } ConvexPolygon2D polygon1 = getPolygon(p1); ConvexPolygon2D polygon2 = getPolygon(p2); Point2D[] closestPoints = new Point2D[] {new Point2D(), new Point2D()}; Point2D[] closestPointsReversed = new Point2D[] {new Point2D(), new Point2D()}; ConvexPolygonTools convexPolygonTools = new ConvexPolygonTools(); convexPolygonTools.computeMinimumDistancePoints(polygon1, polygon2, closestPoints[0], closestPoints[1]); convexPolygonTools.computeMinimumDistancePoints(polygon2, polygon1, closestPointsReversed[0], closestPointsReversed[1]); assertEquals(closestPoints[0].distance(closestPoints[1]), closestPointsReversed[0].distance(closestPointsReversed[1]), epsilon); assertEquals(expectedSolution[0], closestPoints[0].getX(), epsilon); assertEquals(expectedSolution[1], closestPoints[0].getY(), epsilon); assertEquals(expectedSolution[2], closestPoints[1].getX(), epsilon); assertEquals(expectedSolution[3], closestPoints[1].getY(), epsilon); }