diff --git a/tests/linear_spline_tests.py b/tests/linear_spline_tests.py index abe6b07b9c..4652fbfc49 100644 --- a/tests/linear_spline_tests.py +++ b/tests/linear_spline_tests.py @@ -1,45 +1,45 @@ - -import numpy as np -from sverchok.utils.testing import * -from sverchok.utils.geom import LinearSpline - - -class LinearSplineTests(SverchokTestCase): - def setUp(self): - super().setUp() - vertices = [(-1, -1, 0), (0, 0, 0), (1, 2, 0), (2, 3, 0)] - self.control_points = np.array(vertices) - self.spline = LinearSpline(vertices, metric="DISTANCE") - - def test_eval(self): - t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0]) - result = self.spline.eval(t_in) - expected_result = np.array( - [[-1.0, -1.0, 0.0 ], - [-0.64188612, -0.64188612, 0.0 ], - [ 0.27350889, 0.54701779, 0.0 ], - [ 0.5, 1.0, 0.0 ], - [ 0.95298221, 1.90596443, 0.0 ], - [ 2.0, 3.0, 0.0 ]]) - #info(result) - self.assert_numpy_arrays_equal(result, expected_result, precision=8) - - def test_tangent(self): - t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0]) - result = self.spline.tangent(t_in) - #info(result) - expected_result = np.array( - [[-1, -1, 0], - [-1, -1, 0], - [-1, -2, 0], - [-1, -2, 0], - [-1, -2, 0], - [-1, -1, 0]]) - self.assert_numpy_arrays_equal(result, expected_result) - - def test_control_points(self): - points = self.spline.get_control_points() - self.assertEquals(points.shape, (3,2,3)) - expected = np.array(list(zip(self.control_points, self.control_points[1:]))) - self.assert_numpy_arrays_equal(points, expected) - + +import numpy as np +from sverchok.utils.testing import * +from sverchok.utils.geom import LinearSpline + + +class LinearSplineTests(SverchokTestCase): + def setUp(self): + super().setUp() + vertices = [(-1, -1, 0), (0, 0, 0), (1, 2, 0), (2, 3, 0)] + self.control_points = np.array(vertices) + self.spline = LinearSpline(vertices, metric="DISTANCE") + + def test_eval(self): + t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0]) + result = self.spline.eval(t_in) + expected_result = np.array( + [[-1.0, -1.0, 0.0 ], + [-0.64188612, -0.64188612, 0.0 ], + [ 0.27350889, 0.54701779, 0.0 ], + [ 0.5, 1.0, 0.0 ], + [ 0.95298221, 1.90596443, 0.0 ], + [ 2.0, 3.0, 0.0 ]]) + #info(result) + self.assert_numpy_arrays_equal(result, expected_result, precision=8) + + def test_tangent(self): + t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0]) + result = self.spline.tangent(t_in) + #info(result) + expected_result = np.array( + [[ 1, 1, 0], + [ 1, 1, 0], + [ 1, 2, 0], + [ 1, 2, 0], + [ 1, 2, 0], + [ 1, 1, 0]]) + self.assert_numpy_arrays_equal(result, expected_result) + + def test_control_points(self): + points = self.spline.get_control_points() + self.assertEquals(points.shape, (3,2,3)) + expected = np.array(list(zip(self.control_points, self.control_points[1:]))) + self.assert_numpy_arrays_equal(points, expected) + diff --git a/utils/geom.py b/utils/geom.py index ede0bae5e5..258e4998b6 100644 --- a/utils/geom.py +++ b/utils/geom.py @@ -662,7 +662,7 @@ def get_seq_len(self, vlist): add_to_sumlist = self.summed_lengths.append current_length = 0.0 for idx in range(len(vlist)-1): - v = vlist[idx][0]-vlist[idx+1][0], vlist[idx][1]-vlist[idx+1][1], vlist[idx][2]-vlist[idx+1][2] + v = vlist[idx+1][0]-vlist[idx][0], vlist[idx+1][1]-vlist[idx][1], vlist[idx+1][2]-vlist[idx][2] length = math.sqrt((v[0]*v[0]) + (v[1]*v[1]) + (v[2]*v[2])) add_normal(v) add_len(length)