def test_translated_shape_intersection(): r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) s = _TestShape() s.set_transform(Translation(5, 0, 0)) _ = s.intersect(r) assert s.saved_ray.origin == Point(-5, 0, -5) assert s.saved_ray.direction == Vector(0, 0, 1)
def test_scaled_shape_intersection(): r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) s = _TestShape() s.set_transform(Scaling(2, 2, 2)) _ = s.intersect(r) assert s.saved_ray.origin == Point(0, 0, -2.5) assert s.saved_ray.direction == Vector(0, 0, 0.5)
def test_add_child(): g = Group() s = _TestShape() g.add_child(s) assert len(g.objects) > 0 assert s.parent == g
def test_shape_has_parent(): s = _TestShape() assert s.parent is None
def test_transformed_shape_normal(): s = _TestShape() t = Scaling(1, 0.5, 1) * RotationZ(math.pi / 5) s.set_transform(t) n = s.normal_at(Point(0, math.sqrt(2) / 2, -math.sqrt(2) / 2)) assert n == Vector(0, 0.97014, -0.24254)
def test_translated_shape_normal(): s = _TestShape() s.set_transform(Translation(0, 1, 0)) n = s.normal_at(Point(0, 1.70711, -0.70711)) assert n == Vector(0, 0.70711, -0.70711)
def test_assign_material(): s = _TestShape() m = Material() m.ambient = 1 s.set_material(m) assert s.material == m
def test_default_material(): s = _TestShape() assert s.material == Material()
def test_assign_transform(): s = _TestShape() s.set_transform(Translation(2, 3, 4)) assert s.transform == Translation(2, 3, 4)
def test_default_transform(): s = _TestShape() assert s.transform == Identity()