示例#1
0
 def testTrafo(self):
     solver = Solver()
     A = trafo([2, 2])
     solver.eq(A.getmatrix()[0, 0], A.getmatrix()[1, 1]) # restrict to rotation + scaling + translation
     solver.eq(A.getmatrix()[0, 1], -A.getmatrix()[1, 0])
     solver.eq(A*vector([0, 1]), vector([-1, 2]))
     solver.eq(A*vector([1, 0]), vector([1, 4]))
     self.failUnlessEqual(float((A * vector([0, 0]))[0]), 1)
     self.failUnlessEqual(float((A * vector([0, 0]))[1]), 2)
     self.failUnlessEqual(float(A.getmatrix()[0, 0]), 0)
     self.failUnlessEqual(float(A.getmatrix()[0, 1]), -2)
     self.failUnlessEqual(float(A.getmatrix()[1, 0]), 2)
     self.failUnlessEqual(float(A.getmatrix()[1, 1]), 0)
     B = trafo([2, 2])
     solver.eq(A*B, identitytrafo(2))
     self.failUnlessEqual(float((B * vector([0, 0]))[0]), -1)
     self.failUnlessEqual(float((B * vector([0, 0]))[1]), 0.5)
     self.failUnlessEqual(float(B.getmatrix()[0, 0]), 0)
     self.failUnlessEqual(float(B.getmatrix()[0, 1]), 0.5)
     self.failUnlessEqual(float(B.getmatrix()[1, 0]), -0.5)
     self.failUnlessEqual(float(B.getmatrix()[1, 1]), 0)
示例#2
0
 def testAccess(self):
     m = matrix([2, 3])
     v = vector(2)
     t = trafo((m, v))
     self.failUnlessEqual(t.getmatrix(), m)
     self.failUnlessEqual(t.getvector(), v)
示例#3
0
 def testMath(self):
     self.failUnlessEqual(str(-trafo([2, 3], "A")), str(trafo((-matrix([2, 3], "A_matrix"), -vector(2, "A_vector")))))
     self.failUnlessEqual(str(trafo([2, 3], "A") + trafo([2, 3], "B")), str(trafo((matrix([2, 3], "A_matrix") + matrix([2, 3], "B_matrix"), vector(2, "A_vector") + vector(2, "B_vector")))))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, 1, trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), 1)
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, scalar(), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), scalar())
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, scalar() + scalar(), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), scalar() + scalar())
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, vector(2), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), vector(2))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, vector(3), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), vector(3))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, matrix([2, 3]), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), matrix([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), trafo([2, 4]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, trafo([2, 3]), trafo([3, 3]))
     self.failUnlessEqual(str(trafo([2, 3], "A") - trafo([2, 3], "B")), str(trafo((matrix([2, 3], "A_matrix") - matrix([2, 3], "B_matrix"), vector(2, "A_vector") - vector(2, "B_vector")))))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, 1, trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), 1)
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, scalar(), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), scalar())
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, scalar() + scalar(), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), scalar() + scalar())
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, vector(2), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), vector(2))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, vector(3), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), vector(3))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, matrix([2, 3]), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), matrix([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), trafo([2, 4]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, trafo([2, 3]), trafo([3, 3]))
     self.failUnlessEqual(str(trafo([2, 3], "A") * trafo([3, 4], "B")), str(trafo((matrix([2, 3], "A_matrix") * matrix([3, 4], "B_matrix"), vector(2, "A_vector") + matrix([2, 3], "A_matrix") * vector(3, "B_vector")))))
     self.failUnlessEqual(str(2 * trafo([2, 3], "A")), str(trafo((2 * matrix([2, 3], "A_matrix"), 2 * vector(2, "A_vector")))))
     self.failUnlessEqual(str(trafo([2, 3], "A") * 2), str(trafo((matrix([2, 3], "A_matrix") * 2, vector(2, "A_vector") * 2))))
     self.failUnlessEqual(str(scalar() * trafo([2, 3], "A")), str(trafo((scalar() * matrix([2, 3], "A_matrix"), scalar() * vector(2, "A_vector")))))
     self.failUnlessEqual(str(trafo([2, 3], "A") * scalar()), str(trafo((matrix([2, 3], "A_matrix") * scalar(), vector(2, "A_vector") * scalar()))))
     self.failUnlessEqual(str((scalar() + scalar()) * trafo([2, 3], "A")), str(trafo(((scalar() + scalar()) * matrix([2, 3], "A_matrix"), (scalar() + scalar()) * vector(2, "A_vector")))))
     self.failUnlessEqual(str(trafo([2, 3], "A") * (scalar() + scalar())), str(trafo((matrix([2, 3], "A_matrix") * (scalar() + scalar()), vector(2, "A_vector") * (scalar() + scalar())))))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__mul__, vector(2), trafo([2, 3]))
     self.failUnlessEqual(str(trafo([2, 3], "A") * vector(3, "a")), str(matrix([2, 3], "A_matrix") * vector(3, "a") + vector(2, "A_vector")))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__mul__, trafo([2, 3]), vector(2))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__mul__, matrix([3, 2]), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__mul__, trafo([2, 3]), matrix([3, 2]))
     self.failUnlessEqual(str(trafo([2, 3], "A") / 2.0), str(trafo((matrix([2, 3], "A_matrix") / 2.0, vector(2, "A_vector") / 2.0))))
     self.failUnlessEqual(str(trafo([2, 3], "A") / 2), str(trafo((matrix([2, 3], "A_matrix") / 2, vector(2, "A_vector") / 2))))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, scalar(), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, scalar() + scalar(), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, vector(1), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, matrix([2, 3]), trafo([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, trafo([2, 3]), scalar())
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, trafo([2, 3]), scalar() + scalar())
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, trafo([2, 3]), vector(1))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, trafo([2, 3]), matrix([2, 3]))
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, trafo([2, 3]), trafo([2, 3]))
示例#4
0
 def testInit(self):
     self.failUnlessEqual(str(trafo((2, 3))), "unnamed_trafo{=(matrix: unnamed_trafo_matrix{=((unnamed_trafo_matrix[0, 0], unnamed_trafo_matrix[0, 1], unnamed_trafo_matrix[0, 2]), (unnamed_trafo_matrix[1, 0], unnamed_trafo_matrix[1, 1], unnamed_trafo_matrix[1, 2]))}, vector: unnamed_trafo_vector{=(unnamed_trafo_vector[0], unnamed_trafo_vector[1])})}")
     self.failUnlessEqual(str(trafo((2, 3), "A")), "A{=(matrix: A_matrix{=((A_matrix[0, 0], A_matrix[0, 1], A_matrix[0, 2]), (A_matrix[1, 0], A_matrix[1, 1], A_matrix[1, 2]))}, vector: A_vector{=(A_vector[0], A_vector[1])})}")
     self.failUnlessEqual(str(trafo((matrix([2, 3], "B"), vector(2, "c")), "A")), "A{=(matrix: B{=((B[0, 0], B[0, 1], B[0, 2]), (B[1, 0], B[1, 1], B[1, 2]))}, vector: c{=(c[0], c[1])})}")
     self.failUnlessRaises((RuntimeError, AttributeError, TypeError), trafo, (matrix([2, 3]), vector(3)))