2 if sys
.path
[0] != "../..":
3 sys
.path
.insert(0, "../..")
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
.assertAlmostEqual(unit
.topt(b1
.boxdistance(b2
)), unit
.topt(2))
23 self
.assertAlmostEqual(unit
.topt(b1
.boxdistance(b3
)), unit
.topt(math
.sqrt(9*(1 + math
.tan(math
.pi
/6)**2)) - math
.sqrt(3)/2))
24 self
.assertAlmostEqual(unit
.topt(b1
.boxdistance(b4
)), unit
.topt(3 - math
.sqrt(3)/2))
25 self
.assertAlmostEqual(unit
.topt(b2
.boxdistance(b1
)), unit
.topt(2))
26 self
.assertAlmostEqual(unit
.topt(b3
.boxdistance(b1
)), unit
.topt(math
.sqrt(9*(1 + math
.tan(math
.pi
/6)**2)) - math
.sqrt(3)/2))
27 self
.assertAlmostEqual(unit
.topt(b4
.boxdistance(b1
)), unit
.topt(3 - math
.sqrt(3)/2))
28 self
.assertRaises(box
.BoxCrossError
, b1
.boxdistance
, b5
)
29 self
.assertRaises(box
.BoxCrossError
, b5
.boxdistance
, b1
)
32 if __name__
== "__main__":