def test_multiplication(self): m1 = Transformation( m=[ [1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 9.0, 8.0, 7.0], [6.0, 5.0, 4.0, 1.0], ], invm=[ [-3.75, 2.75, -1, 0], [4.375, -3.875, 2.0, -0.5], [0.5, 0.5, -1.0, 1.0], [-1.375, 0.875, 0.0, -0.5], ], ) assert m1.is_consistent() m2 = Transformation( m=[ [3.0, 5.0, 2.0, 4.0], [4.0, 1.0, 0.0, 5.0], [6.0, 3.0, 2.0, 0.0], [1.0, 4.0, 2.0, 1.0], ], invm=[ [0.4, -0.2, 0.2, -0.6], [2.9, -1.7, 0.2, -3.1], [-5.55, 3.15, -0.4, 6.45], [-0.9, 0.7, -0.2, 1.1], ], ) assert m2.is_consistent() expected = Transformation( m=[ [33.0, 32.0, 16.0, 18.0], [89.0, 84.0, 40.0, 58.0], [118.0, 106.0, 48.0, 88.0], [63.0, 51.0, 22.0, 50.0], ], invm=[ [-1.45, 1.45, -1.0, 0.6], [-13.95, 11.95, -6.5, 2.6], [25.525, -22.025, 12.25, -5.2], [4.825, -4.325, 2.5, -1.1], ], ) assert expected.is_consistent() assert expected.is_close(m1 * m2)
def test_vec_point_multiplication(self): m = Transformation( m=[ [1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 9.0, 8.0, 7.0], [0.0, 0.0, 0.0, 1.0], ], invm=[ [-3.75, 2.75, -1, 0], [5.75, -4.75, 2.0, 1.0], [-2.25, 2.25, -1.0, -2.0], [0.0, 0.0, 0.0, 1.0], ], ) assert m.is_consistent() expected_v = Vec(14.0, 38.0, 51.0) assert expected_v.is_close(m * Vec(1.0, 2.0, 3.0)) expected_p = Point(18.0, 46.0, 58.0) assert expected_p.is_close(m * Point(1.0, 2.0, 3.0)) expected_n = Normal(-8.75, 7.75, -3.0) assert expected_n.is_close(m * Normal(3.0, 2.0, 4.0))
def test_is_close(self): m1 = Transformation( m=[ [1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 9.0, 8.0, 7.0], [6.0, 5.0, 4.0, 1.0], ], invm=[ [-3.75, 2.75, -1, 0], [4.375, -3.875, 2.0, -0.5], [0.5, 0.5, -1.0, 1.0], [-1.375, 0.875, 0.0, -0.5], ], ) assert m1.is_consistent() # Not using "deepcopy" here would make Python pass a pointer to the *same* matrices and vectors m2 = Transformation(m=deepcopy(m1.m), invm=deepcopy(m1.invm)) assert m1.is_close(m2) m3 = Transformation(m=deepcopy(m1.m), invm=deepcopy(m1.invm)) m3.m[2][ 2] += 1.0 # Note: this makes "m3" not consistent (m3.is_consistent() == False) assert not m1.is_close(m3) m4 = Transformation(m=deepcopy(m1.m), invm=deepcopy(m1.invm)) m4.invm[2][ 2] += 1.0 # Note: this makes "m4" not consistent (m4.is_consistent() == False) assert not m1.is_close(m4)