コード例 #1
0
        public void ARayMissesASphere()
        {
            var r = new Ray(Tuple.Point(0, 2, -5), Tuple.Vector(0, 0, 1));
            var s = new Sphere();

            var intersections = IntersectionHelpers.Intersections(s, r);

            Assert.Empty(intersections);
        }
コード例 #2
0
        public void ARayIntersectsASphereAtATangent()
        {
            var r = new Ray(Tuple.Point(0, 1, -5), Tuple.Vector(0, 0, 1));
            var s = new Sphere();

            var intersections = IntersectionHelpers.Intersections(s, r);

            Assert.Equal(2, intersections.Count);
            Assert.Equal(5f, intersections[0].T);
            Assert.Equal(5f, intersections[1].T);
        }
コード例 #3
0
        public void ASphereIsBehindARay()
        {
            var r = new Ray(Tuple.Point(0, 0, 5), Tuple.Vector(0, 0, 1));
            var s = new Sphere();

            var intersections = IntersectionHelpers.Intersections(s, r);

            Assert.Equal(2, intersections.Count);
            Assert.Equal(-6f, intersections[0].T);
            Assert.Equal(-4f, intersections[1].T);
        }
コード例 #4
0
        public void ARayOriginatesInsideASphere()
        {
            var r = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1));
            var s = new Sphere();

            var intersections = IntersectionHelpers.Intersections(s, r);

            Assert.Equal(2, intersections.Count);
            Assert.Equal(-1f, intersections[0].T);
            Assert.Equal(1f, intersections[1].T);
        }
コード例 #5
0
        public void HitWhenSomeIntersectionsHaveNegativeT()
        {
            var s  = new Sphere();
            var i1 = new Intersection(-1, s);
            var i2 = new Intersection(1, s);

            var xs = IntersectionHelpers.Intersections(i1, i2);

            var i = xs.Hit();

            Assert.Equal(i2, i);
        }
コード例 #6
0
        public void HitWhenAllIntersectionsHavePositiveT()
        {
            var s  = new Sphere();
            var i1 = new Intersection(1, s);
            var i2 = new Intersection(2, s);

            var xs = IntersectionHelpers.Intersections(i1, i2);

            var i = xs.Hit();

            Assert.Equal(i1, i);
        }
コード例 #7
0
        public void HitWhenAllIntersectionsHaveNegativeT()
        {
            var s  = new Sphere();
            var i1 = new Intersection(-2, s);
            var i2 = new Intersection(-2, s);

            var xs = IntersectionHelpers.Intersections(i1, i2);

            var i = xs.Hit();

            Assert.Null(i);
        }
コード例 #8
0
        public void AggregatingIntersections()
        {
            var s = new Sphere();

            var i1 = new Intersection(1, s);
            var i2 = new Intersection(2, s);

            var xs = IntersectionHelpers.Intersections(i1, i2);

            Assert.Equal(2, xs.Count);
            Assert.Equal(1, xs[0].T);
            Assert.Equal(2, xs[1].T);
        }
コード例 #9
0
        public void HitIsAlwaysLowestNonNegativeIntersection()
        {
            var s  = new Sphere();
            var i1 = new Intersection(5, s);
            var i2 = new Intersection(7, s);
            var i3 = new Intersection(3, s);
            var i4 = new Intersection(2, s);

            var xs = IntersectionHelpers.Intersections(i1, i2, i3, i4);

            var i = xs.Hit();

            Assert.Equal(i4, i);
        }
コード例 #10
0
        public void ARayIntersectsASphereWithTwoPoints()
        {
            var r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1));
            var s = new Sphere();

            var intersections = IntersectionHelpers.Intersections(s, r);

            Assert.Equal(2, intersections.Count);
            Assert.Equal(4f, intersections[0].T);
            Assert.Equal(s, intersections[0].Object);

            Assert.Equal(6f, intersections[1].T);
            Assert.Equal(s, intersections[1].Object);
        }