Skip to content

Commit 8f4f3bd

Browse files
committed
add first test for slicing
1 parent 84397cb commit 8f4f3bd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_curve.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
66
Requires "pytest" to run.
77
"""
8+
import math
89

910
from pytest import fixture, mark
1011
from geomdl import BSpline
12+
from geomdl import NURBS
1113
from geomdl import evaluators
1214
from geomdl import helpers
1315
from geomdl import convert
@@ -234,6 +236,13 @@ def nurbs_curve(spline_curve):
234236
curve.weights = [0.5, 1.0, 0.75, 1.0, 0.25, 1.0]
235237
return curve
236238

239+
@fixture
240+
def unit_circle_tri_ctrlpts():
241+
r = 1.
242+
a, h = 3. * r / math.sqrt(3.), 1.5 * r
243+
ctrlpts = [(0., -r), (-a,-r), (-a/2,-r+h), (0., 2*h-r), (a/2, -r+h), (a, -r), (0., -r)]
244+
return ctrlpts
245+
237246

238247
def test_nurbs_curve2d_weights(nurbs_curve):
239248
assert nurbs_curve.weights == [0.5, 1.0, 0.75, 1.0, 0.25, 1.0]
@@ -252,6 +261,24 @@ def test_nurbs_curve2d_eval(nurbs_curve, param, res):
252261
assert abs(evalpt[1] - res[1]) < GEOMDL_DELTA
253262

254263

264+
@mark.parametrize("param, res", [
265+
(0.0, (0.0, -1.0)),
266+
(0.2, (-0.9571859726038534, -0.2894736842105261)),
267+
(0.5, (1.1102230246251568e-16, 1.0)),
268+
(0.95, (0.27544074447012257, -0.9613180515759312))
269+
])
270+
def test_nurbs_curve2d_slice_eval(unit_circle_tri_ctrlpts, param, res):
271+
crv = NURBS.Curve()
272+
crv.degree = 2
273+
crv.ctrlpts = unit_circle_tri_ctrlpts
274+
crv.knotvector = [0.,0.,0., 1./3, 1./3, 2./3, 2./3, 1.,1.,1.]
275+
crv.weights[1::2] = [0.5, 0.5, 0.5]
276+
277+
evalpt = crv.evaluate_single(param)
278+
279+
assert abs(evalpt[0] - res[0]) < GEOMDL_DELTA
280+
assert abs(evalpt[1] - res[1]) < GEOMDL_DELTA
281+
255282
@mark.parametrize("param, order, res", [
256283
(0.0, 1, ((5.0, 5.0), (90.9090, 90.9090))),
257284
(0.2, 2, ((13.8181, 11.5103), (40.0602, 17.3878), (104.4062, -29.3672))),

0 commit comments

Comments
 (0)