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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }