use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareCrossClustersIntoGrids method findSeedNode.
@Test
public void findSeedNode() {
List<SquareNode> cluster = new ArrayList<>();
cluster.add(new SquareNode());
cluster.add(new SquareNode());
cluster.add(new SquareNode());
for (SquareNode n : cluster) {
n.square = new Polygon2D_F64(4);
}
cluster.get(1).edges[2] = new SquareEdge();
cluster.get(2).edges[0] = new SquareEdge();
cluster.get(2).edges[1] = new SquareEdge();
assertTrue(cluster.get(1) == SquareCrossClustersIntoGrids.findSeedNode(cluster));
cluster.get(1).edges[3] = new SquareEdge();
assertTrue(cluster.get(1) == SquareCrossClustersIntoGrids.findSeedNode(cluster));
cluster.get(1).edges[0] = new SquareEdge();
assertTrue(cluster.get(2) == SquareCrossClustersIntoGrids.findSeedNode(cluster));
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareGraph method almostParallel.
private void almostParallel(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);
int adj = 1;
if (changeClock) {
UtilPolygons2D_F64.flip(a.square);
UtilPolygons2D_F64.flip(b.square);
adj = 3;
}
SquareGraph alg = new SquareGraph();
for (int i = 0; i < 4; i++) {
assertTrue(alg.almostParallel(a, i, b, i));
assertTrue(alg.almostParallel(a, i, b, (i + 2) % 4));
assertFalse(alg.almostParallel(a, i, b, (i + 1) % 4));
}
// give it some slant
double angle0 = 0.1;
double angle1 = Math.PI / 4;
double cos0 = Math.cos(angle0);
double sin0 = Math.sin(angle0);
double cos1 = Math.cos(angle1);
double sin1 = Math.sin(angle1);
a.square.get(adj).set(-1 + 2 * cos0, 1 + 2 * sin0);
assertTrue(alg.almostParallel(a, 0, b, 0));
assertFalse(alg.almostParallel(a, 1, b, 0));
a.square.get(adj).set(-1 + 2 * cos1, 1 + 2 * sin1);
assertTrue(alg.almostParallel(a, 0, b, 0));
assertFalse(alg.almostParallel(a, 1, b, 0));
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareGraph method computeNodeInfo.
@Test
public void computeNodeInfo() {
SquareNode a = new SquareNode();
a.square = new Polygon2D_F64(-1, 1, 2, 1, 2, -1, -1, -1);
SquareGraph alg = new SquareGraph();
alg.computeNodeInfo(a);
assertEquals(3, a.sideLengths[0], UtilEjml.TEST_F64);
assertEquals(2, a.sideLengths[1], UtilEjml.TEST_F64);
assertEquals(3, a.sideLengths[2], UtilEjml.TEST_F64);
assertEquals(2, a.sideLengths[3], UtilEjml.TEST_F64);
assertEquals(3, a.largestSide, UtilEjml.TEST_F64);
assertEquals(2, a.smallestSide, UtilEjml.TEST_F64);
assertTrue(a.center.distance(0.5, 0) < UtilEjml.TEST_F64);
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareGridTools method orderNode.
@Test
public void orderNode() {
SquareNode target = new SquareNode();
target.square = new Polygon2D_F64(4);
target.square.get(0).set(-1, -1);
target.square.get(1).set(1, -1);
target.square.get(2).set(1, 1);
target.square.get(3).set(-1, 1);
SquareNode up = new SquareNode();
up.center.set(0, 5);
SquareNode down = new SquareNode();
down.center.set(0, -5);
SquareNode left = new SquareNode();
left.center.set(-5, 0);
SquareNode right = new SquareNode();
right.center.set(5, 0);
SquareGridTools alg = new SquareGridTools();
// try different orders and clockwiseness
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
// System.out.println("i = " + i + " j = " + j);
alg.orderNode(target, right, true);
checkOrder(alg.ordered, -1, -1, 1, -1, 1, 1, -1, 1);
alg.orderNode(target, left, true);
checkOrder(alg.ordered, 1, 1, -1, 1, -1, -1, 1, -1);
alg.orderNode(target, up, false);
checkOrder(alg.ordered, -1, -1, 1, -1, 1, 1, -1, 1);
alg.orderNode(target, down, false);
checkOrder(alg.ordered, 1, 1, -1, 1, -1, -1, 1, -1);
UtilPolygons2D_F64.shiftDown(target.square);
}
UtilPolygons2D_F64.flip(target.square);
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSquareGridTools method boundingPolygonCCW_column.
@Test
public void boundingPolygonCCW_column() {
SquareGridTools alg = new SquareGridTools();
SquareGrid grid = createGrid(3, 1);
Polygon2D_F64 poly = new Polygon2D_F64(4);
alg.boundingPolygonCCW(grid, poly);
double w = TestSquareRegularClustersIntoGrids.DEFAULT_WIDTH;
assertTrue(poly.get(0).distance(-w / 2, -w / 2) <= 1e-8);
assertTrue(poly.get(1).distance(w / 2, -w / 2) <= 1e-8);
assertTrue(poly.get(2).distance(w / 2, w * 4 + w / 2) <= 1e-8);
assertTrue(poly.get(3).distance(-w / 2, w * 4 + w / 2) <= 1e-8);
}
Aggregations