add issequence function to data and plot functions and examples for geometry
This commit is contained in:
@@ -13,69 +13,85 @@ 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
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
from pylib.geometry import Direction, Point, CS, Wireframe, Line, Polygon, Circle
|
||||
|
||||
class TestGeometry(unittest.TestCase):
|
||||
|
||||
def test_Direction(self):
|
||||
p = Direction()
|
||||
self.assertIsInstance(
|
||||
p, list)
|
||||
p,
|
||||
list)
|
||||
self.assertEqual(
|
||||
p, [1, 0, 0, 0])
|
||||
p,
|
||||
[1, 0, 0, 0])
|
||||
self.assertEqual(
|
||||
Direction(2, 3, 4), [2, 3, 4, 0])
|
||||
Direction(2, 3, 4),
|
||||
[2, 3, 4, 0])
|
||||
|
||||
self.assertIsInstance(
|
||||
p, vector)
|
||||
def test_Direction_getitem(self):
|
||||
self.assertEqual(
|
||||
p, vector([1, 0, 0, 0]))
|
||||
Direction()[:3],
|
||||
[1, 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])
|
||||
Direction(1, -1, 1)[:3],
|
||||
[1, -1, 1])
|
||||
|
||||
def test_Point(self):
|
||||
p = Point()
|
||||
self.assertIsInstance(
|
||||
p, list)
|
||||
p,
|
||||
list)
|
||||
self.assertEqual(
|
||||
p, [0, 0, 0, 1])
|
||||
p,
|
||||
[0, 0, 0, 1])
|
||||
self.assertEqual(
|
||||
Point(2, 3, 4), [2, 3, 4, 1])
|
||||
Point(2, 3, 4),
|
||||
[2, 3, 4, 1])
|
||||
|
||||
self.assertIsInstance(
|
||||
p, vector)
|
||||
def test_Point_getitem(self):
|
||||
self.assertEqual(
|
||||
p, vector([0, 0, 0, 1]))
|
||||
Point()[:3],
|
||||
[0, 0, 0])
|
||||
self.assertEqual(
|
||||
Point(2, 3, 4), vector([2, 3, 4, 1]))
|
||||
Point(1, -1, 1)[:3],
|
||||
[1, -1, 1])
|
||||
|
||||
def test_Point_xyz(self):
|
||||
def test_Point_rotate(self):
|
||||
[self.assertAlmostEqual(i, j) for i, j in
|
||||
zip(Point(1, 1, 1).rotate_x(math.pi/4), [1, 0, 1.414213562373095, 1])]
|
||||
|
||||
def test_CS(self):
|
||||
self.assertEqual(
|
||||
Point().xyz(), [0, 0, 0])
|
||||
self.assertEqual(
|
||||
Point(1, -1, 1).xyz(), [1, -1, 1])
|
||||
CS(),
|
||||
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
|
||||
|
||||
def test_CS_rotate(self):
|
||||
[self.assertAlmostEqual(k, l) for i, j in
|
||||
zip(CS().rotate_y(-math.pi/2),
|
||||
[[0, 0.0, -1.0, 0.0], [0, 1, 0, 0], [1.0, 0.0, 0, 0.0], [0, 0, 0, 1]])
|
||||
for k, l in zip(i, j)]
|
||||
|
||||
def test_Wireframe(self):
|
||||
self.assertEqual(
|
||||
Wireframe().points(), [])
|
||||
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(), [[]])
|
||||
Wireframe([]).points(),
|
||||
[[]])
|
||||
|
||||
self.assertEqual(
|
||||
Wireframe(Point()).points(), [[0, 0, 0, 1]])
|
||||
Wireframe(Point()).points(),
|
||||
[[0, 0, 0, 1]])
|
||||
|
||||
def test_Line(self):
|
||||
self.assertEqual(
|
||||
Wireframe(Point()).points(), [vector([0, 0, 0, 1])])
|
||||
Line().points(),
|
||||
[[-1, 0, 0, 1], [1, 0, 0, 1]])
|
||||
|
||||
def test_Polygon(self):
|
||||
p0 = Point()
|
||||
@@ -87,6 +103,14 @@ class TestGeometry(unittest.TestCase):
|
||||
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_rotate(self):
|
||||
pg = Polygon(Point(1, 1, 1)).rotate_x(math.pi/4)
|
||||
[self.assertAlmostEqual(i, j) for i, j in
|
||||
zip(pg.points()[0], [1, 0, 1.414213562373095, 1])]
|
||||
[self.assertAlmostEqual(k, l) for i, j in
|
||||
zip(pg.xyz(), ((1, 1), (0, 0), (1.414213562373095, 1.414213562373095)))
|
||||
for k, l in zip(i, j)]
|
||||
|
||||
def test_Polygon_ch_cs(self):
|
||||
# example object to rotate
|
||||
p0 = Point()
|
||||
@@ -103,5 +127,23 @@ class TestGeometry(unittest.TestCase):
|
||||
pg.ch_cs(cs)
|
||||
[self.assertAlmostEqual(i, j) for i, j in zip(pg.points(), test)]
|
||||
|
||||
def test_Circle(self):
|
||||
cs = Circle(n=4).points()
|
||||
test = [[1, 0, 0, 1], [0, 1, 0, 1], [-1, 0, 0, 1], [0, -1, 0 ,1], [1, 0, 0, 1]]
|
||||
[self.assertAlmostEqual(i, j) for i, j in zip(cs, test)]
|
||||
|
||||
cs = Circle().points()
|
||||
test = [[1.0, 0.0, 0, 1],
|
||||
[0.8090169943749475, 0.5877852522924731, 0, 1],
|
||||
[0.30901699437494745, 0.9510565162951535, 0, 1],
|
||||
[-0.30901699437494734, 0.9510565162951536, 0, 1],
|
||||
[-0.8090169943749473, 0.5877852522924732, 0, 1],
|
||||
[-1.0, 1.2246467991473532e-16, 0, 1],
|
||||
[-0.8090169943749476, -0.587785252292473, 0, 1],
|
||||
[-0.30901699437494756, -0.9510565162951535, 0, 1],
|
||||
[0.30901699437494723, -0.9510565162951536, 0, 1],
|
||||
[0.8090169943749473, -0.5877852522924734, 0, 1]]
|
||||
[self.assertAlmostEqual(k, l) for i, j in zip(cs, test) for k, l in zip(i, j) ]
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
Reference in New Issue
Block a user