public static LineSegment2D[] getIntersectingEdgesCopy(Line2DReadOnly line, ConvexPolygon2DReadOnly polygon) { LineSegment2D edge1 = new LineSegment2D(); LineSegment2D edge2 = new LineSegment2D(); int edges = getIntersectingEdges(line, edge1, edge2, polygon); if (edges == 2) return new LineSegment2D[] {edge1, edge2}; if (edges == 1) return new LineSegment2D[] {edge1}; return null; } }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testGetIntersectingEdges4() { // empty polygon ConvexPolygon2D polygon = new ConvexPolygon2D(); LineSegment2D result1 = new LineSegment2D(); LineSegment2D result2 = new LineSegment2D(); Line2D line1 = new Line2D(new Point2D(0.5, 1.5), new Vector2D(0.0, 0.1)); assertEquals(ConvexPolygon2dCalculator.getIntersectingEdges(line1, result1, result2, polygon), 0); assertTrue(ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line1, polygon) == null); }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testGetIntersectingEdges3() { // point polygon ConvexPolygon2D polygon = new ConvexPolygon2D(); polygon.addVertex(new Point2D(-1.0, -0.5)); polygon.update(); LineSegment2D result1 = new LineSegment2D(); LineSegment2D result2 = new LineSegment2D(); Line2D line1 = new Line2D(new Point2D(0.0, 0.0), new Vector2D(-0.5, -0.25)); assertEquals(ConvexPolygon2dCalculator.getIntersectingEdges(line1, result1, result2, polygon), 0); assertTrue(ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line1, polygon) == null); Line2D line2 = new Line2D(new Point2D(0.5, 1.5), new Vector2D(0.0, 0.1)); assertEquals(ConvexPolygon2dCalculator.getIntersectingEdges(line2, result1, result2, polygon), 0); assertTrue(ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line2, polygon) == null); Line2D line3 = new Line2D(new Point2D(-1.0, -0.5), new Vector2D(1.0, 0.1)); assertEquals(ConvexPolygon2dCalculator.getIntersectingEdges(line3, result1, result2, polygon), 0); assertTrue(ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line3, polygon) == null); }
public static LineSegment2d[] getIntersectingEdgesCopy(Line2d line, ConvexPolygon2d polygon) { LineSegment2d edge1 = new LineSegment2d(); LineSegment2d edge2 = new LineSegment2d(); int edges = getIntersectingEdges(line, edge1, edge2, polygon); if (edges == 2) return new LineSegment2d[] {edge1, edge2}; if (edges == 1) return new LineSegment2d[] {edge1}; return null; }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testGetIntersectingEdges2() { // line polygon Point2D vertex1 = new Point2D(1.0, 1.0); Point2D vertex2 = new Point2D(1.0, 0.0); LineSegment2D edge1 = new LineSegment2D(vertex1, vertex2); LineSegment2D edge2 = new LineSegment2D(vertex2, vertex1); // add in order so update does not change indices: ConvexPolygon2D polygon = new ConvexPolygon2D(); polygon.addVertex(vertex1); polygon.addVertex(vertex2); polygon.update(); LineSegment2D result1 = new LineSegment2D(); LineSegment2D result2 = new LineSegment2D(); Line2D line1 = new Line2D(new Point2D(0.5, 1.5), new Vector2D(0.0, 0.1)); LineSegment2D[] expected1 = null; assertEdgesEqual(expected1, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line1, polygon), false); assertEquals(0, ConvexPolygon2dCalculator.getIntersectingEdges(line1, result1, result2, polygon)); Line2D line2 = new Line2D(new Point2D(-0.5, 0.0), new Vector2D(0.75, 0.25)); LineSegment2D[] expected2 = new LineSegment2D[] {edge1, edge2}; assertEdgesEqual(expected2, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line2, polygon), false); assertEquals(2, ConvexPolygon2dCalculator.getIntersectingEdges(line2, result1, result2, polygon)); assertEdgesEqual(expected2, new LineSegment2D[] {result1, result2}, false); Line2D line3 = new Line2D(new Point2D(1.0, -0.5), new Vector2D(0.0, 0.1)); LineSegment2D[] expected3 = null; assertEdgesEqual(expected3, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line3, polygon), false); assertEquals(0, ConvexPolygon2dCalculator.getIntersectingEdges(line3, result1, result2, polygon)); }
LineSegment2D[] expected1 = new LineSegment2D[] {edge4, edge2}; assertEdgesEqual(expected1, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line1, polygon), false); assertEquals(2, ConvexPolygon2dCalculator.getIntersectingEdges(line1, result1, result2, polygon)); assertEdgesEqual(expected1, new LineSegment2D[] {result1, result2}, false); LineSegment2D[] expected2 = null; assertEdgesEqual(expected2, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line2, polygon), false); assertEquals(0, ConvexPolygon2dCalculator.getIntersectingEdges(line2, result1, result2, polygon)); assertEquals(1, ConvexPolygon2dCalculator.getIntersectingEdges(line3, result1, result2, polygon)); assertEdgesEqual(expected3, new LineSegment2D[] {result1}, false); LineSegment2D[] expected4 = new LineSegment2D[] {edge1, edge3}; assertEdgesEqual(expected4, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line4, polygon), false); assertEquals(2, ConvexPolygon2dCalculator.getIntersectingEdges(line4, result1, result2, polygon)); assertEdgesEqual(expected4, new LineSegment2D[] {result1, result2}, false); LineSegment2D[] expected5 = new LineSegment2D[] {edge1, edge3}; assertEdgesEqual(expected5, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line5, polygon), false); assertEquals(2, ConvexPolygon2dCalculator.getIntersectingEdges(line5, result1, result2, polygon)); assertEdgesEqual(expected5, new LineSegment2D[] {result1, result2}, false); LineSegment2D[] expected6 = new LineSegment2D[] {edge1, edge3}; assertEdgesEqual(expected6, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line6, polygon), false); assertEquals(2, ConvexPolygon2dCalculator.getIntersectingEdges(line6, result1, result2, polygon)); assertEdgesEqual(expected6, new LineSegment2D[] {result1, result2}, false); LineSegment2D[] expected7 = new LineSegment2D[] {edge2, edge4}; assertEdgesEqual(expected7, ConvexPolygon2dCalculator.getIntersectingEdgesCopy(line7, polygon), false);