diff --git a/cameraproject/src/geometries/Triangle.java b/cameraproject/src/geometries/Triangle.java index 2bf7b82..3f1fda8 100644 --- a/cameraproject/src/geometries/Triangle.java +++ b/cameraproject/src/geometries/Triangle.java @@ -1,5 +1,7 @@ package geometries; +import java.util.List; + import primitives.*; /** @@ -16,4 +18,5 @@ public class Triangle extends Polygon { public Triangle(Point3D point1, Point3D point2, Point3D point3) { super(point1, point2, point3); } + } diff --git a/cameraproject/src/unittests/geometries/PlaneTests.java b/cameraproject/src/unittests/geometries/PlaneTests.java index 2e73051..4da0e7d 100644 --- a/cameraproject/src/unittests/geometries/PlaneTests.java +++ b/cameraproject/src/unittests/geometries/PlaneTests.java @@ -28,45 +28,47 @@ public void testGetNormalPoint3D() { } @Test - public void findIntersections(Ray ray) { + public void findIntersections() { Plane p = new Plane(new Point3D(0, 0, 0), new Vector(0, 0, 1)); List expected; //EP01:Ray intersects with plane - expected = p.findIntersections(new Ray(new Point3D(1, 1, 0), new Vector(0, -1, 1))); + expected = p.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(1, -1, 1))); assertEquals("Wrong number of points", 1, expected.size()); + assertEquals("Wrong points expected",List.of(new Point3D(0,-2,0)),expected); //EP02: Ray does not intersect with the plane expected = p.findIntersections(new Ray(new Point3D(0, 0, 1), new Vector(1, 0, 0))); - assertEquals("Wrong number of points", 0, expected.size()); + assertNull("Wrong number of points", expected); // BVA01: Ray is parallel to the plane - included in plane expected = p.findIntersections(new Ray(new Point3D(0, 1, 0), new Vector(0, -1, 0))); - assertEquals("Wrong number of points", 1, expected.size()); + assertNull("Wrong number of points", expected); // BVA02: Ray is parallel to the plane - not included in plane expected = p.findIntersections(new Ray(new Point3D(0, 0, 2), new Vector(0, 0, 1))); - assertEquals("Wrong number of points", 0, expected.size()); + assertNull("Wrong number of points", expected); // BVA03: Ray is orthogonal to the plane - before it expected = p.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(0, 0, 1))); assertEquals("Wrong number of points", 1, expected.size()); + assertEquals("Wrong points expected",List.of(new Point3D(-1,-1,0)),expected); // BVA04: Ray is orthogonal to the plane - after it expected = p.findIntersections(new Ray(new Point3D(1, 1, 1), new Vector(0, 0, 1))); - assertEquals("Wrong number of points", 0, expected.size()); + assertNull("Wrong number of points", expected); // BVA05: Ray is orthogonal to the plane - starts in it expected = p.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(0, 0, 1))); - assertEquals("Wrong number of points", 1, expected.size()); + assertNull("Wrong number of points", expected); // BVA06: Ray starts at the plane, if it isn't included in the other BVAs expected = p.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0))); - assertEquals("Wrong number of points", 1, expected.size()); + assertNull("Wrong number of points", expected); // BVA07: Ray begins at the point of the plane (not its' direction) expected = p.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0))); - assertEquals("Wrong number of points", 1, expected.size()); + assertNull("Wrong number of points", expected); } } diff --git a/cameraproject/src/unittests/geometries/TriangleTest.java b/cameraproject/src/unittests/geometries/TriangleTest.java index b2fad17..ec8c0b0 100644 --- a/cameraproject/src/unittests/geometries/TriangleTest.java +++ b/cameraproject/src/unittests/geometries/TriangleTest.java @@ -29,52 +29,36 @@ public void testGetNormal() { } @Test - public void findIntersections(Ray ray) { - - Triangle t = new Triangle(new Point3D(0, 0, 0), new Point3D(2, 1, 0), new Point3D(0, 2, 0)); - List expected; - - List expectedPoints; - //EP01:Ray intersects with triangle - expected = t.findIntersections(new Ray(new Point3D(1, 1, 0), new Vector(0, -1, 1))); - assertEquals("Wrong number of points", 1, expected.size()); - - //EP02: Ray does not intersect with the triangle - expected = t.findIntersections(new Ray(new Point3D(0, 0, 1), new Vector(1, 0, 0))); - assertEquals("Wrong number of points", 0, expected.size()); - - // BVA01: Ray is parallel to the plane - included in triangle - expected = t.findIntersections(new Ray(new Point3D(0, 1, 0), new Vector(0, -1, 0))); - assertEquals("Wrong number of points", 1, expected.size()); - - // BVA02: Ray is parallel to the plane - not included in triangle - expected = t.findIntersections(new Ray(new Point3D(0, 0, 2), new Vector(0, 0, 1))); - assertEquals("Wrong number of points", 0, expected.size()); - - // BVA03: Ray is orthogonal to the triangle - before it - expected = t.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(0, 0, 1))); - assertEquals("Wrong number of points", 1, expected.size()); - - // BVA04: Ray is orthogonal to the triangle - after it - expected = t.findIntersections(new Ray(new Point3D(1, 1, 1), new Vector(0, 0, 1))); - assertEquals("Wrong number of points", 0, expected.size()); - - // BVA05: Ray is orthogonal to the triangle - starts in it - expected = t.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(0, 0, 1))); - assertEquals("Wrong number of points", 1, expected.size()); - - // BVA06: Ray starts at the triangle, if it isn't included in the other BVAs - expected = t.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0))); - assertEquals("Wrong number of points", 1, expected.size()); - - // BVA07: Ray begins at the point of the triangle (not its' direction) - expected = t.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0))); - assertEquals("Wrong number of points", 1, expected.size()); - - // BVA08: Ray is inside the plane if the triangle continued, but isnt - expected = t.findIntersections(new Ray(new Point3D(-1, -1, 3), new Vector(0, 0, -1))); - assertEquals("Wrong number of points", 0, expected.size()); - } + public void testFindIntersections() { + + Triangle t=new Triangle(new Point3D(2,1,0), new Point3D(0, 0, 0), new Point3D(0, 2, 0)); + List result; + // EP01: ray goes inside the triangle + result=t.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(2, 2, 1))); + assertEquals("Wrong point recieved",List.of(new Point3D(1,1,0)), result); + + // EP02: Outside against edge + result=t.findIntersections(new Ray(new Point3D(-1, -2, -1), new Vector(3, 4, 1))); + assertNull("Ray doesnt work when it touches the edge",result); + + //EP03: Outside against vertex + result=t.findIntersections(new Ray(new Point3D(-2, -2, -1), new Vector(5, 4, 1))); + assertNull("Ray doesnt work when it touches the vertex",result); + + + // BVA01: Ray touches the corner of the triangle + result=t.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(1, 2, 1))); + assertNull("Ray is outside against edge",result); + + // BVA02: Ray intersects with the vertex + result=t.findIntersections(new Ray(new Point3D(-1, -2, -1), new Vector(1, 4, 1))); + assertNull("Ray is outside against edge",result); + + //BVA03: Ray intersects with the continuation of the vertex + result=t.findIntersections(new Ray(new Point3D(-3, -3, -1), new Vector(1, 6, 1))); + assertNull("Ray is outside against edge",result); + + } }