def test_a_scaling_matrix_applied_to_a_vecor(): transform = transformations.scaling(2, 3, 4) v = vector(-4, 6, 8) expected_vector = vector(-8, 18, 32) with tf.Session() as sess: [expected, actual] = sess.run([expected_vector, transform(v)]) assert((expected == actual).all())
def test_a_scaling_matrix_applied_to_a_point(): transform = transformations.scaling(2, 3, 4) p = point(-4, 6, 8) expected_point = point(-8, 18, 32) with tf.Session() as sess: [expected, actual] = sess.run([expected_point, transform(p)]) assert((expected == actual).all())
def test_multiplying_the_inverse_of_a_scaling_matrix(): transform = transformations.scaling(2, 3, 4) inverse = transformations.invert(transform) v = vector(-4, 6, 8) expected_vector = vector(-2, 2, 2) with tf.Session() as sess: [expected, actual] = sess.run([expected_vector, inverse(v)]) assert((expected == actual).all())
def test_intersecting_a_scaled_sphere_with_a_ray(): r = Ray(point(0., 0., -5.), vector(0., 0., 1.)) s = Sphere(transformations.scaling(2, 2, 2)) xs = s.intersect(r) with tf.Session() as sess: actual_xs = sess.run(xs) assert (len(actual_xs) == 2) assert (actual_xs[0] == 3) assert (actual_xs[1] == 7)
def test_chained_transofrmations_must_be_applied_in_reverse_order(): p = point(1, 0, 1) A = transformations.rotation_x(math.pi/2) B = transformations.scaling(5, 5, 5) C = transformations.translation(10, 5, 7) CBA = transformations.concat(C, B, A) with tf.Session() as sess: [expected, actual] = sess.run([point(15, 0, 7), CBA(p)]) assert(np.allclose(expected, actual))
def test_individual_transformations_are_applied_in_sequence(): p = point(1, 0, 1) A = transformations.rotation_x(math.pi/2) B = transformations.scaling(5, 5, 5) C = transformations.translation(10, 5, 7) with tf.Session() as sess: [expected_p2, expected_p3, expected_p4, actual_p2, actual_p3, actual_p4] = sess.run( [point(1, -1, 0), point(5, -5, 0), point(15, 0, 7), A(p), B(A(p)), C(B(A(p)))]) assert(np.allclose(expected_p2, actual_p2)) assert(np.allclose(expected_p3, actual_p3)) assert(np.allclose(expected_p4, actual_p4))