Search in sources :

Example 1 with LineSegmentf

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);
}
Also used : LineSegmentf(org.terasology.joml.geom.LineSegmentf) Vector2f(org.joml.Vector2f) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Vector2f (org.joml.Vector2f)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 LineSegmentf (org.terasology.joml.geom.LineSegmentf)1