fix for bug #1429524, a bit ugly though
[PyX/mjg.git] / test / unit / test_box.py
blob88134befedd8eb1bb01a728bc4e8fbe840b2de83
1 import sys
2 if sys.path[0] != "../..":
3 sys.path.insert(0, "../..")
5 import unittest
7 import math
8 from pyx import *
10 class BoxTestCase(unittest.TestCase):
12 def testDistance(self):
13 b1 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
14 b2 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
15 b2.transform(trafo.translate(3, 0))
16 b3 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
17 b3.transform(trafo.translate(3, 3 * math.tan(math.pi/6)))
18 b4 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
19 b4.transform(trafo.translate(0, 3))
20 b5 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
21 b5.transform(trafo.translate(0.5, 0.5))
22 self.failUnlessAlmostEqual(unit.topt(b1.boxdistance(b2)), unit.topt(2))
23 self.failUnlessAlmostEqual(unit.topt(b1.boxdistance(b3)), unit.topt(math.sqrt(9*(1 + math.tan(math.pi/6)**2)) - math.sqrt(3)/2))
24 self.failUnlessAlmostEqual(unit.topt(b1.boxdistance(b4)), unit.topt(3 - math.sqrt(3)/2))
25 self.failUnlessAlmostEqual(unit.topt(b2.boxdistance(b1)), unit.topt(2))
26 self.failUnlessAlmostEqual(unit.topt(b3.boxdistance(b1)), unit.topt(math.sqrt(9*(1 + math.tan(math.pi/6)**2)) - math.sqrt(3)/2))
27 self.failUnlessAlmostEqual(unit.topt(b4.boxdistance(b1)), unit.topt(3 - math.sqrt(3)/2))
28 self.failUnlessRaises(box.BoxCrossError, b1.boxdistance, b5)
29 self.failUnlessRaises(box.BoxCrossError, b5.boxdistance, b1)
32 if __name__ == "__main__":
33 unittest.main()