Point2DReadOnly lastVertex = polygon.getVertex(0); for (int i = 1; i < vertices + 1; i++) if (i == vertices) nextVertex = polygon.getVertex(0); nextVertex = polygon.getVertex(i); Point2DReadOnly vertexA = polygon.getVertex(idx1); Point2DReadOnly vertexB = polygon.getVertex(idx2); double xNew = (vertexA.getX() + vertexB.getX()) / 2.0; double yNew = (vertexA.getY() + vertexB.getY()) / 2.0;
@Test public void testTranslate() { T polygon = createEmptyConvexPolygon2D(); polygon.addVertex(new Point2D(0.0, 0.0)); polygon.update(); Vector2D translation1 = new Vector2D(-0.1, 0.0); polygon.translate(translation1); assertTrue(polygon.getVertex(0).epsilonEquals(translation1, EPSILON)); }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testTranslatePolygon1() { ConvexPolygon2D polygon = new ConvexPolygon2D(); polygon.addVertex(new Point2D(0.0, 0.0)); polygon.addVertex(new Point2D(10.0, 0.0)); polygon.addVertex(new Point2D(0.0, 10.0)); polygon.update(); Vector2D translation1 = new Vector2D(0.0, 0.0); ConvexPolygon2DBasics polygon1 = polygon.translateCopy(translation1); assertTrue(polygon1.epsilonEquals(polygon, epsilon)); Vector2D translation2 = new Vector2D(1.0, 0.5); ConvexPolygon2DBasics polygon2 = polygon.translateCopy(translation2); assertTrue(polygon2.getVertex(2).epsilonEquals(new Point2D(1.0, 0.5), epsilon)); assertTrue(polygon2.getVertex(1).epsilonEquals(new Point2D(11.0, 0.5), epsilon)); assertTrue(polygon2.getVertex(0).epsilonEquals(new Point2D(1.0, 10.5), epsilon)); }
while (index < polygonToCut.getNumberOfVertices()) Point2DReadOnly vertex = polygonToCut.getVertex(index); if (cuttingLine.isPointOnSideOfLine(vertex, sideOfLineToCut == RobotSide.LEFT))
for (int i = 0; i < numberOfVertices; i++) Point2DReadOnly currentPoint = polygon.getVertex(i); if (arePointsAtExactlyEqualPosition(closestVertex, currentPoint)) neighbourPoints[0] = polygon.getVertex(prevIndex); neighbourPoints[1] = polygon.getVertex(nextIndex); int neighbourIndex = 1; int wrongNeighbourIndex = 0;
for (int i = 0; i < polygon.getNumberOfVertices(); i++) if (polygon.getVertex(i).epsilonEquals(new Point2D(0.0, 0.0), EPSILON)) assertTrue(polygon.canObserverSeeEdge(i, observer2)); else for (int i = 0; i < polygon.getNumberOfVertices(); i++) if (polygon.getVertex(i).epsilonEquals(new Point2D(0.0, 1.0), EPSILON)) assertTrue(polygon.canObserverSeeEdge(i, observer3)); else if (polygon.getVertex(i).epsilonEquals(new Point2D(1.0, 1.0), EPSILON)) assertTrue(polygon.canObserverSeeEdge(i, observer3)); else
Point2D pointTranslation = new Point2D(pointThatDefinesThePolygon); pointTranslation.add(arbitraryPoint0); assertEquals(polygonTranslation.getVertex(0), pointTranslation);