add first python bindings
This commit is contained in:
62
src/Python/testing/math_pybind_test.py
Normal file
62
src/Python/testing/math_pybind_test.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
import numpy as np
|
||||
|
||||
import uLib_python
|
||||
|
||||
def vector4f0(v, target):
|
||||
diff = np.array(v) - np.array(target)
|
||||
diff[3] = 0 # ignoring w
|
||||
return np.all(np.abs(diff) < 0.001)
|
||||
|
||||
class TestMathGeometry(unittest.TestCase):
|
||||
def test_geometry(self):
|
||||
Geo = uLib_python.Math.Geometry()
|
||||
|
||||
Geo.SetPosition([1, 1, 1])
|
||||
|
||||
pt = Geo.GetLocalPoint([2, 3, 2, 1])
|
||||
wp = Geo.GetWorldPoint(pt)
|
||||
|
||||
self.assertTrue(vector4f0(wp, [2, 3, 2, 1]))
|
||||
|
||||
Geo.Scale([2, 2, 2])
|
||||
wp = Geo.GetWorldPoint([1, 1, 1, 1])
|
||||
self.assertTrue(vector4f0(wp, [3, 3, 3, 1]))
|
||||
|
||||
class TestMathContainerBox(unittest.TestCase):
|
||||
def test_container_box_local(self):
|
||||
Cnt = uLib_python.Math.ContainerBox()
|
||||
Cnt.SetOrigin([-1, -1, -1])
|
||||
Cnt.SetSize([2, 2, 2])
|
||||
|
||||
size = Cnt.GetSize()
|
||||
self.assertTrue(np.allclose(size, [2, 2, 2]))
|
||||
|
||||
def test_container_box_global(self):
|
||||
Box = uLib_python.Math.ContainerBox()
|
||||
Box.SetPosition([1, 1, 1])
|
||||
Box.SetSize([2, 2, 2])
|
||||
|
||||
pt = Box.GetLocalPoint([2, 3, 2, 1])
|
||||
wp = Box.GetWorldPoint(pt)
|
||||
self.assertTrue(vector4f0(wp, [2, 3, 2, 1]))
|
||||
|
||||
class TestMathStructuredGrid(unittest.TestCase):
|
||||
def test_structured_grid(self):
|
||||
grid = uLib_python.Math.StructuredGrid([10, 10, 10])
|
||||
grid.SetSpacing([1, 1, 1])
|
||||
|
||||
spacing = grid.GetSpacing()
|
||||
self.assertTrue(np.allclose(spacing, [1, 1, 1]))
|
||||
|
||||
class TestMathAccumulator(unittest.TestCase):
|
||||
def test_accumulator_mean(self):
|
||||
acc = uLib_python.Math.Accumulator_Mean_f()
|
||||
acc(10.0)
|
||||
acc(20.0)
|
||||
self.assertAlmostEqual(acc(), 15.0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user