diff --git a/AmpScan/core.py b/AmpScan/core.py index 0b204237181f03f71712457711a78043599d7cd7..1b648663c1882ee3e17e02c5a1c0ddceee6286b2 100644 --- a/AmpScan/core.py +++ b/AmpScan/core.py @@ -341,7 +341,7 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin): >>> ang = [np.pi/2, -np.pi/4, np.pi/3] >>> amp.rotateAng(ang, ang='rad') """ - if type(rot)==type([]): + if isinstance(rot, (tuple, list, np.ndarray)): R = self.rotMatrix(rot, ang) self.rotate(R, norms) else: diff --git a/AmpScan/trim.py b/AmpScan/trim.py index 76509e125764a001c276498d08753e9d073986ee..3e198b8e2d7c8ae1c4b39797df5f1cd654f89fdb 100644 --- a/AmpScan/trim.py +++ b/AmpScan/trim.py @@ -30,22 +30,25 @@ class trimMixin(object): >>> amp.planarTrim(100, 2) """ - # planar values for each vert on face - fv = self.vert[self.faces, plane] - # Number points on each face are above cut plane - fvlogic = (fv > height).sum(axis=1) - # Faces with points both above and below cut plane - adjf = self.faces[np.logical_or(fvlogic == 2, fvlogic == 1)] - # Get adjacent vertices - adjv = np.unique(adjf) - # Get vert above height and set to height - abvInd = adjv[self.vert[adjv, plane] > height] - self.vert[abvInd, plane] = height - # Find all verts above plane - delv = self.vert[:, plane] > height - # Reorder verts to account for deleted one - vInd = np.cumsum(~delv) - 1 - self.faces = self.faces[fvlogic != 3, :] - self.faces = vInd[self.faces] - self.vert = self.vert[~delv, :] - self.calcStruct() \ No newline at end of file + if type(height)==float: + # planar values for each vert on face + fv = self.vert[self.faces, plane] + # Number points on each face are above cut plane + fvlogic = (fv > height).sum(axis=1) + # Faces with points both above and below cut plane + adjf = self.faces[np.logical_or(fvlogic == 2, fvlogic == 1)] + # Get adjacent vertices + adjv = np.unique(adjf) + # Get vert above height and set to height + abvInd = adjv[self.vert[adjv, plane] > height] + self.vert[abvInd, plane] = height + # Find all verts above plane + delv = self.vert[:, plane] > height + # Reorder verts to account for deleted one + vInd = np.cumsum(~delv) - 1 + self.faces = self.faces[fvlogic != 3, :] + self.faces = vInd[self.faces] + self.vert = self.vert[~delv, :] + self.calcStruct() + else: + raise TypeError("height arg must be a float") \ No newline at end of file diff --git a/tests/sample_test.py b/tests/sample_test.py index a5d4fb70477d7e9231fecd484e8daf9c0d7443ae..73131ad57bc0e95ca3f1f49cc2ef6411cfd4a5b3 100644 --- a/tests/sample_test.py +++ b/tests/sample_test.py @@ -3,14 +3,16 @@ import os import sys class TestBasicFunction(unittest.TestCase): + + def SetUp(self): + modPath = os.path.abspath(os.getcwd()) + sys.path.insert(0, modPath) def test_running(self): print("Running sample_test.py") self.assertTrue(True) def test_python_imports(self): - modPath = os.path.abspath(os.getcwd()) - sys.path.insert(0, modPath) import numpy, scipy, matplotlib, vtk, AmpScan.core s = str(type(numpy)) self.assertEqual(s, "<class 'module'>") @@ -28,9 +30,7 @@ class TestBasicFunction(unittest.TestCase): s = str(type("string")) self.assertEqual(s, "<class 'module'>") - def test_import_stl(self): - modPath = os.path.abspath(os.getcwd()) - sys.path.insert(0, modPath) + def test_rotate(self): stlPath = os.path.abspath(os.getcwd()) + "\\tests\\sample_stl_sphere_BIN.stl" from AmpScan.core import AmpObject Amp = AmpObject(stlPath) @@ -40,5 +40,14 @@ class TestBasicFunction(unittest.TestCase): Amp.rotateAng(7) Amp.rotateAng({}) + def test_trim(self): + # a new test for the trim module + stlPath = os.path.abspath(os.getcwd()) + "\\tests\\sample_stl_sphere_BIN.stl" + from AmpScan.core import AmpObject + Amp = AmpObject(stlPath) + #with self.assertRaises(TypeError): + #Amp.planarTrim([], plane=[]) + + if __name__ == '__main__': unittest.main()