public void RayMissesP2P3Edge()
        {
            var p1 = pt.Point(0, 1, 0);
            var p2 = pt.Point(-1, 0, 0);
            var p3 = pt.Point(1, 0, 0);
            var t  = new shape.Triangle(p1, p2, p3);
            var r  = new Ray(pt.Point(0, -1, -2), pt.Vector(0, 0, 1));
            var xs = t.Intersect(r);

            Assert.Empty(xs);
        }
        public void IntersectingRayParallelToTriangle()
        {
            var p1 = pt.Point(0, 1, 0);
            var p2 = pt.Point(-1, 0, 0);
            var p3 = pt.Point(1, 0, 0);
            var t  = new shape.Triangle(p1, p2, p3);
            var r  = new Ray(pt.Point(0, -1, -2), pt.Vector(0, 1, 0));
            var xs = t.Intersect(r);

            Assert.Empty(xs);
        }
        public void IntersectionCanEncapsulateUV()
        {
            var p1 = pt.Point(0, 1, 0);
            var p2 = pt.Point(-1, 0, 0);
            var p3 = pt.Point(1, 0, 0);
            var s  = new shape.Triangle(p1, p2, p3);
            var i  = Intersection.WithUV(3.5, s, 0.2, 0.4);

            Assert.Equal(0.2, i.U);
            Assert.Equal(0.4, i.V);
        }
        public void RayStrikesTriangle()
        {
            var p1 = pt.Point(0, 1, 0);
            var p2 = pt.Point(-1, 0, 0);
            var p3 = pt.Point(1, 0, 0);
            var t  = new shape.Triangle(p1, p2, p3);
            var r  = new Ray(pt.Point(0, 0.5, -2), pt.Vector(0, 0, 1));
            var xs = t.Intersect(r);

            Assert.Single(xs);
            Assert.Equal(2, xs[0].T);
        }
        public void FindingNormalOnTriangle()
        {
            var p1 = pt.Point(0, 1, 0);
            var p2 = pt.Point(-1, 0, 0);
            var p3 = pt.Point(1, 0, 0);
            var t  = new shape.Triangle(p1, p2, p3);

            var n1 = t.TestNormalLocal(pt.Point(0, 0.5, 0));
            var n2 = t.TestNormalLocal(pt.Point(-0.5, 0.75, 0));
            var n3 = t.TestNormalLocal(pt.Point(0.5, 0.25, 0));

            Assert.Equal(n1, t.Normal);
            Assert.Equal(n2, t.Normal);
            Assert.Equal(n3, t.Normal);
        }
        public void ConstructionTriangle()
        {
            var p1 = pt.Point(0, 1, 0);
            var p2 = pt.Point(-1, 0, 0);
            var p3 = pt.Point(1, 0, 0);
            var t  = new shape.Triangle(p1, p2, p3);

            Assert.Equal(p1, t.P1);
            Assert.Equal(p2, t.P2);
            Assert.Equal(p3, t.P3);

            Assert.Equal(pt.Vector(-1, -1, 0), t.Edge1);
            Assert.Equal(pt.Vector(1, -1, 0), t.Edge2);
            Assert.Equal(pt.Vector(0, 0, -1), t.Normal);
        }