Skip to content
Snippets Groups Projects
Commit a17e8f93 authored by jack-parsons's avatar jack-parsons
Browse files

Adding test for translating (may want to move to separate file)

parent 2baf041b
No related branches found
No related tags found
1 merge request!23Merge in Jack's changes
Pipeline #845 passed
......@@ -314,7 +314,16 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
Translation in [x, y, z]
"""
self.vert[:] += trans
# Check that trans is array like
if isinstance(trans, (list, np.ndarray)):
# Check that trans has exactly 3 dimensions
if len(trans) == 3:
self.vert[:] += trans
else:
raise ValueError("Translation has incorrect dimensions. Expected 3 but found: " + str(len(trans)))
else:
raise TypeError("Translation is not array_like: " + trans)
def centre(self):
r"""
......
......@@ -2,7 +2,9 @@ import unittest
import os
import sys
class TestBasicFunction(unittest.TestCase):
ACCURACY = 3 # The number of decimal places to value accuracy for
def SetUp(self):
modPath = os.path.abspath(os.getcwd())
......@@ -48,6 +50,31 @@ class TestBasicFunction(unittest.TestCase):
#with self.assertRaises(TypeError):
#Amp.planarTrim([], plane=[])
def test_translate(self):
from AmpScan.core import AmpObject
stlPath = self.get_path("sample_stl_sphere_BIN.stl")
amp = AmpObject(stlPath)
# Check that everything has been translated by 1
start = amp.vert.mean(axis=0)[:]
amp.translate([1, -1, 0])
end = amp.vert.mean(axis=0)[:]
self.assertAlmostEqual(start[0], end[0]-1, places=TestBasicFunction.ACCURACY)
self.assertAlmostEqual(start[1], end[1]+1, places=TestBasicFunction.ACCURACY)
self.assertAlmostEqual(start[2], end[2], places=TestBasicFunction.ACCURACY)
# Check that translating raises TypeError when translating with an invalid type
with self.assertRaises(Exception):
amp.translate("")
# Check that translating raises ValueError when translating with 2 dimensions
with self.assertRaises(ValueError):
amp.translate([0, 0])
# Check that translating raises ValueError when translating with 4 dimensions
with self.assertRaises(ValueError):
amp.translate([0, 0, 0, 0])
def get_path(self, filename):
"""
Method to get the absolute path to the testing files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment