108 lines
2.7 KiB
Python
108 lines
2.7 KiB
Python
"""Test of geometry module.
|
|
|
|
:Date: 2019-12-21
|
|
|
|
.. module:: test_geometry
|
|
:platform: *nix, Windows
|
|
:synopsis: Test of geometry module.
|
|
|
|
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
|
|
"""
|
|
import unittest
|
|
|
|
import os
|
|
import sys
|
|
import math
|
|
sys.path.insert(0, os.path.abspath('../pylib'))
|
|
from mathematics import vector
|
|
from geometry import Direction, Point, CS, Wireframe, Polygon
|
|
|
|
class TestGeometry(unittest.TestCase):
|
|
|
|
def test_Direction(self):
|
|
p = Direction()
|
|
self.assertIsInstance(
|
|
p, list)
|
|
self.assertEqual(
|
|
p, [1, 0, 0, 0])
|
|
self.assertEqual(
|
|
Direction(2, 3, 4), [2, 3, 4, 0])
|
|
|
|
self.assertIsInstance(
|
|
p, vector)
|
|
self.assertEqual(
|
|
p, vector([1, 0, 0, 0]))
|
|
self.assertEqual(
|
|
Direction(2, 3, 4), vector([2, 3, 4, 0]))
|
|
|
|
def test_Direction_xyz(self):
|
|
self.assertEqual(
|
|
Direction().xyz(), [1, 0, 0])
|
|
self.assertEqual(
|
|
Direction(1, -1, 1).xyz(), [1, -1, 1])
|
|
|
|
def test_Point(self):
|
|
p = Point()
|
|
self.assertIsInstance(
|
|
p, list)
|
|
self.assertEqual(
|
|
p, [0, 0, 0, 1])
|
|
self.assertEqual(
|
|
Point(2, 3, 4), [2, 3, 4, 1])
|
|
|
|
self.assertIsInstance(
|
|
p, vector)
|
|
self.assertEqual(
|
|
p, vector([0, 0, 0, 1]))
|
|
self.assertEqual(
|
|
Point(2, 3, 4), vector([2, 3, 4, 1]))
|
|
|
|
def test_Point_xyz(self):
|
|
self.assertEqual(
|
|
Point().xyz(), [0, 0, 0])
|
|
self.assertEqual(
|
|
Point(1, -1, 1).xyz(), [1, -1, 1])
|
|
|
|
def test_Wireframe(self):
|
|
self.assertEqual(
|
|
Wireframe().points(), [])
|
|
|
|
# it is possible to assign other objects then Points but/and the
|
|
# class will not test if Points are used, this is just assumed
|
|
self.assertEqual(
|
|
Wireframe([]).points(), [[]])
|
|
|
|
self.assertEqual(
|
|
Wireframe(Point()).points(), [[0, 0, 0, 1]])
|
|
self.assertEqual(
|
|
Wireframe(Point()).points(), [vector([0, 0, 0, 1])])
|
|
|
|
def test_Polygon(self):
|
|
p0 = Point()
|
|
p1 = Point(1, 0, 0)
|
|
p2 = Point(1, 1, 1)
|
|
p3 = Point(0, 1, 1)
|
|
pg = Polygon(p0, p1, p2, p3)
|
|
self.assertEqual(
|
|
pg.points(),
|
|
[[0, 0, 0, 1], [1, 0 , 0, 1], [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1]])
|
|
|
|
def test_Polygon_ch_cs(self):
|
|
# example object to rotate
|
|
p0 = Point()
|
|
p1 = Point(1, 0, 0)
|
|
p2 = Point(1, 1, 1)
|
|
p3 = Point(0, 1, 1)
|
|
theta = math.pi/2
|
|
test = [[0.0, 0.0, 0.0, 1], [0, 0.0, -1.0, 1], [1.0, 1.0, -1, 1],
|
|
[1.0, 1.0, 0, 1], [0.0, 0.0, 0.0, 1]]
|
|
|
|
# using a coordinate system object
|
|
pg = Polygon(p0, p1, p2, p3)
|
|
cs = CS().rotate_y(theta)
|
|
pg.ch_cs(cs)
|
|
[self.assertAlmostEqual(i, j) for i, j in zip(pg.points(), test)]
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(verbosity=2)
|