use of org.terasology.joml.geom.LineSegmentf in project Terasology by MovingBlocks.
the class BlockRegionTest method testIntersectionLineSegment.
@Test
void testIntersectionLineSegment() {
BlockRegion a = new BlockRegion(0, 0, 0, 1, 1, 1);
// no intersection
assertEquals(a.intersectLineSegment(3f, 3f, 3f, 2f, 3f, 3f, new Vector2f()), -1);
LineSegmentf l1 = new LineSegmentf(3f, 2f, 3f, 2f, 3f, 2f);
assertEquals(a.intersectLineSegment(l1, new Vector2f()), -1);
// one intersection
assertEquals(a.intersectLineSegment(1.2f, 1.2f, 1.2f, 1.6f, 1.6f, 1.6f, new Vector2f()), 1);
LineSegmentf l2 = new LineSegmentf(-0.6f, 0f, 0f, -0.2f, 1.2f, 0f);
assertEquals(a.intersectLineSegment(l2, new Vector2f()), 1);
// two intersections
assertEquals(a.intersectLineSegment(1.2f, 1.2f, 2f, -0.6f, 0f, -0.2f, new Vector2f()), 2);
LineSegmentf l3 = new LineSegmentf(2f, 2f, 2f, -0.6f, -2f, 0f);
assertEquals(a.intersectLineSegment(l3, new Vector2f()), 2);
// segment inside the BlocRegion
assertEquals(a.intersectLineSegment(0f, 1f, 1.2f, 1f, -0.2f, 0.2f, new Vector2f()), 3);
LineSegmentf l4 = new LineSegmentf(1f, 1f, 1.2f, -0.2f, 0f, 1f);
assertEquals(a.intersectLineSegment(l4, new Vector2f()), 3);
}
Aggregations