Skip to content

Commit

Permalink
Feature/convex polygon geometrically equals testing (#63)
Browse files Browse the repository at this point in the history
This PR adds a test to validate that issue #51 has been resolved.

---------

Co-authored-by: vroy <vroy@10.100.3.21>
  • Loading branch information
Richiedu38 and vroy authored Apr 30, 2024
1 parent 81809c0 commit 095823e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/test/java/us/ihmc/euclid/geometry/ConvexPolygon2DTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,49 @@ public void testConstructors()
assertEquals(4.0, polygonPolygon.getNumberOfVertices(), EPSILON, "Number of vertices should be four");
assertTrue(polygonPolygon.isUpToDate());
}

@Test


/* If two polygons built in different ways (vertices in different order), they are still equivalent
*/
public void geometricallyEquals()
{

int numberOfVertices = 4;
ArrayList<Point2D> verticesList = new ArrayList<>();
verticesList.add(new Point2D(0.0, 0.0));
verticesList.add(new Point2D(0.0, 1.0));
verticesList.add(new Point2D(1.0, 0.0));
verticesList.add(new Point2D(1.0, 1.0));

int numberOfVertices2 = 4;
ArrayList<Point2D> verticesList2 = new ArrayList<>();

verticesList2.add(new Point2D(1.0, 0.0));
verticesList2.add(new Point2D(1.0, 1.0));
verticesList2.add(new Point2D(0.0, 1.0));
verticesList2.add(new Point2D(0.0, 0.0));

ConvexPolygon2D polygonA = new ConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(verticesList, numberOfVertices));
ConvexPolygon2D polygonB = new ConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(verticesList2, numberOfVertices2));

assertEquals(polygonA.getNumberOfVertices(), polygonB.getNumberOfVertices());

for (int i = 0; i < numberOfVertices; i++)
{
boolean foundMatchingVertex = false;
for (int j = 0; j < numberOfVertices2; j++)
{
if (polygonA.getVertex(i).equals(polygonB.getVertex(j)))
{
assertEquals(polygonA.getVertex(i), polygonB.getVertex(j));
foundMatchingVertex = true;
break;
} // Once we find the corresponding vertex, we stop
}
assertTrue(foundMatchingVertex, "No matching vertex found in polygonB for vertex" + polygonA.getVertex(i));
}
}
}

0 comments on commit 095823e

Please sign in to comment.