Skip to content

Commit

Permalink
Merge pull request #5083 from nortikin/fix_5082_Polyline_has_inverted…
Browse files Browse the repository at this point in the history
…_tangents

fix #5082 (Polyline has inverted tangents)
  • Loading branch information
satabol committed Mar 2, 2024
2 parents 0980e68 + f342d9b commit 3eb0c21
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
90 changes: 45 additions & 45 deletions tests/linear_spline_tests.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion utils/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3eb0c21

Please sign in to comment.