def test_cp1(): p = Point(1 + 0j) q = Point(0 + 1j) m = Transformation([[np.e**(np.pi / 2 * 1j), 0], [0, 1]]) assert m * p == q c = crossratio(p, q, m * q, m * m * q) assert np.isclose(np.real(c), c)
def test_pow(self): t = translation(1, 2) assert t**0 == Transformation(np.eye(3)) assert t**1 == t assert t**2 == translation(2, 4) assert t**3 == translation(3, 6) assert t**(-2) == translation(-2, -4)
def test_from_points(self): p1 = Point(0, 0) p2 = Point(1, 0) p3 = Point(0, 1) p4 = Point(3, 5) l = Line(p1, p3) M = Transformation.from_points((p1, p1 + Point(1, 1)), (p2, p2 + Point(1, 1)), (p3, p3 + Point(1, 1)), (p4, p4 + Point(1, 1))) assert M*p3 == Point(1, 2) assert (M*l).contains(M*p1) assert (M*l).contains(M*p3)
def test_from_points_and_conics(self): c1 = Circle() p1 = Point(0, -1) p2 = Point(0, 1) p3 = Point(1, 0) c2 = Circle(Point(0, 2), 2) q1 = Point(0, 0) q2 = Point(0, 4) q3 = Point(2, 2) t = Transformation.from_points_and_conics([p1, p2, p3], [q1, q2, q3], c1, c2) assert t * p1 == q1 assert t * p2 == q2 assert t * p2 == q2 assert t.apply(c1) == c2
def test_inverse(self): E = Transformation(np.eye(4)) M = rotation(np.pi, axis=Point(0, 1, 0)) assert M.inverse() * M == E