File: TestPlane.py

package info (click to toggle)
uranium 5.0.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,304 kB
  • sloc: python: 31,765; sh: 132; makefile: 12
file content (49 lines) | stat: -rw-r--r-- 1,363 bytes parent folder | download | duplicates (4)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the LGPLv3 or higher.

from UM.Math.Plane import Plane
from UM.Math.Vector import Vector
from UM.Math.Ray import Ray

import unittest

class TestPlane(unittest.TestCase):
    def setUp(self):
        # Called before the first testfunction is executed
        pass

    def tearDown(self):
        # Called after the last testfunction was executed
        pass

    def test_create(self):
        p = Plane()
        self.assertEqual(Vector(), p.normal)
        self.assertEqual(0.0, p.distance)

        p = Plane(Vector.Unit_Y, 1.0)
        self.assertEqual(Vector.Unit_Y, p.normal)
        self.assertEqual(1.0, p.distance)

    def test_intersects(self):
        p = Plane(Vector.Unit_Y, 0.0)

        r = Ray(Vector(0, 10, 0), -Vector.Unit_Y)
        result = p.intersectsRay(r)
        self.assertNotEqual(False, result)
        self.assertEqual(10.0, result)

        r = Ray(Vector(0, -10, 0), Vector.Unit_Y)
        result = p.intersectsRay(r)
        self.assertNotEqual(False, result)
        self.assertEqual(10.0, result)

        r = Ray(Vector(0, 10, 0), Vector.Unit_Y)
        self.assertEqual(False, p.intersectsRay(r))

        r = Ray(Vector(0, 0, 0), Vector.Unit_X)
        self.assertEqual(False, p.intersectsRay(r))


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