Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def test_add_child():
    g = Group()
    s = _TestShape()
    g.add_child(s)
    assert len(g.objects) > 0
    assert s.parent == g
Ejemplo n.º 4
0
def test_shape_has_parent():
    s = _TestShape()
    assert s.parent is None
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def test_assign_material():
    s = _TestShape()
    m = Material()
    m.ambient = 1
    s.set_material(m)
    assert s.material == m
Ejemplo n.º 8
0
def test_default_material():
    s = _TestShape()
    assert s.material == Material()
Ejemplo n.º 9
0
def test_assign_transform():
    s = _TestShape()
    s.set_transform(Translation(2, 3, 4))
    assert s.transform == Translation(2, 3, 4)
Ejemplo n.º 10
0
def test_default_transform():
    s = _TestShape()
    assert s.transform == Identity()