File: test_box.py

package info (click to toggle)
pyx3 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: python: 27,656; makefile: 225; ansic: 130; sh: 17
file content (33 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
if sys.path[0] != "../..":
    sys.path.insert(0, "../..")

import unittest

import math
from pyx import *

class BoxTestCase(unittest.TestCase):

    def testDistance(self):
        b1 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
        b2 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
        b2.transform(trafo.translate(3, 0))
        b3 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
        b3.transform(trafo.translate(3, 3 * math.tan(math.pi/6)))
        b4 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
        b4.transform(trafo.translate(0, 3))
        b5 = box.polygon(center=(0.5, math.sqrt(3)/6), corners=((0, 0), (1, 0), (0.5, math.sqrt(3)/2)))
        b5.transform(trafo.translate(0.5, 0.5))
        self.assertAlmostEqual(unit.topt(b1.boxdistance(b2)), unit.topt(2))
        self.assertAlmostEqual(unit.topt(b1.boxdistance(b3)), unit.topt(math.sqrt(9*(1 + math.tan(math.pi/6)**2)) - math.sqrt(3)/2))
        self.assertAlmostEqual(unit.topt(b1.boxdistance(b4)), unit.topt(3 - math.sqrt(3)/2))
        self.assertAlmostEqual(unit.topt(b2.boxdistance(b1)), unit.topt(2))
        self.assertAlmostEqual(unit.topt(b3.boxdistance(b1)), unit.topt(math.sqrt(9*(1 + math.tan(math.pi/6)**2)) - math.sqrt(3)/2))
        self.assertAlmostEqual(unit.topt(b4.boxdistance(b1)), unit.topt(3 - math.sqrt(3)/2))
        self.assertRaises(box.BoxCrossError, b1.boxdistance, b5)
        self.assertRaises(box.BoxCrossError, b5.boxdistance, b1)


if __name__ == "__main__":
    unittest.main()