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