use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareCrossClustersIntoGrids method lowerEdgeIndex.
@Test
public void lowerEdgeIndex() {
for (int numCorners = 3; numCorners <= 5; numCorners++) {
for (int first = 0; first < numCorners; first++) {
int second = (first + 1) % numCorners;
SquareNode node = new SquareNode();
node.square = new Polygon2D_F64(numCorners);
node.updateArrayLength();
connect(node, first, new SquareNode(), 0);
node.edges[first].b.graph = SquareNode.RESET_GRAPH;
connect(node, second, new SquareNode(), 0);
node.edges[second].b.graph = SquareNode.RESET_GRAPH;
assertEquals(first, SquareCrossClustersIntoGrids.lowerEdgeIndex(node));
}
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareGraph method findSideIntersect.
@Test
public void findSideIntersect() {
LineSegment2D_F64 line = new LineSegment2D_F64();
LineSegment2D_F64 storage = new LineSegment2D_F64();
SquareNode a = new SquareNode();
a.square = new Polygon2D_F64(-1, 1, 1, 1, 1, -1, -1, -1);
SquareGraph alg = new SquareGraph();
Point2D_F64 intersection = new Point2D_F64();
line.b.set(0, 2);
assertEquals(0, alg.findSideIntersect(a, line, intersection, storage));
line.b.set(0, -2);
assertEquals(2, alg.findSideIntersect(a, line, intersection, storage));
line.b.set(2, 0);
assertEquals(1, alg.findSideIntersect(a, line, intersection, storage));
line.b.set(-2, 0);
assertEquals(3, alg.findSideIntersect(a, line, intersection, storage));
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareGraph method acuteAngle.
private void acuteAngle(boolean changeClock) {
SquareNode a = new SquareNode();
a.square = new Polygon2D_F64(-1, 1, 1, 1, 1, -1, -1, -1);
SquareNode b = new SquareNode();
b.square = new Polygon2D_F64(1, 1, 3, 1, 3, -1, 1, -1);
if (changeClock) {
UtilPolygons2D_F64.flip(a.square);
UtilPolygons2D_F64.flip(b.square);
}
SquareGraph alg = new SquareGraph();
assertEquals(0, alg.acuteAngle(a, 0, b, 0), 1e-8);
assertEquals(0, alg.acuteAngle(a, 0, b, 2), 1e-8);
assertEquals(0, alg.acuteAngle(a, 2, b, 0), 1e-8);
assertEquals(0, alg.acuteAngle(a, 2, b, 2), 1e-8);
assertEquals(0, alg.acuteAngle(a, 1, b, 1), 1e-8);
assertEquals(0, alg.acuteAngle(a, 1, b, 3), 1e-8);
assertEquals(0, alg.acuteAngle(a, 3, b, 1), 1e-8);
assertEquals(0, alg.acuteAngle(a, 3, b, 3), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 0, b, 1), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 0, b, 3), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 2, b, 1), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 2, b, 3), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 1, b, 0), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 3, b, 0), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 1, b, 2), 1e-8);
assertEquals(Math.PI / 2, alg.acuteAngle(a, 3, b, 2), 1e-8);
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareGridTools method boundingPolygonCCW_rect.
@Test
public void boundingPolygonCCW_rect() {
SquareGridTools alg = new SquareGridTools();
double w = TestSquareRegularClustersIntoGrids.DEFAULT_WIDTH;
Polygon2D_F64 poly = new Polygon2D_F64(4);
for (int rows = 2; rows <= 4; rows++) {
for (int cols = 2; cols <= 4; cols++) {
SquareGrid grid = createGrid(rows, cols);
for (int i = 0; i < 2; i++) {
if (i == 1)
alg.transpose(grid);
// ensure preconditions are meet
if (alg.checkFlip(grid)) {
alg.flipRows(grid);
}
alg.boundingPolygonCCW(grid, poly);
double x0 = -w / 2;
double y0 = -w / 2;
double x1 = w * 2 * (cols - 1) + w / 2;
double y1 = w * 2 * (rows - 1) + w / 2;
Polygon2D_F64 expected = new Polygon2D_F64(4);
expected.get(0).set(x0, y0);
expected.get(1).set(x1, y0);
expected.get(2).set(x1, y1);
expected.get(3).set(x0, y1);
assertTrue(UtilPolygons2D_F64.isEquivalent(expected, poly, 1e-8));
}
}
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareRegularClustersIntoGrids method createSquare.
public static SquareNode createSquare(double x, double y, double width) {
double r = width / 2;
Polygon2D_F64 poly = new Polygon2D_F64(4);
poly.get(0).set(-r, r);
poly.get(1).set(r, r);
poly.get(2).set(r, -r);
poly.get(3).set(-r, -r);
SquareNode square = new SquareNode();
for (int i = 0; i < 4; i++) {
poly.get(i).x += x;
poly.get(i).y += y;
square.sideLengths[i] = width;
}
square.square = poly;
square.center.set(x, y);
square.largestSide = width;
return square;
}
Aggregations