def test_rational_spline_from_circular_arc_has_same_end_points(): arc = ConstructionArc( start_angle=30, end_angle=330) spline = rational_bspline_from_arc( start_angle=arc.start_angle, end_angle=arc.end_angle) assert arc.start_point.isclose(spline.control_points[0]) assert arc.end_point.isclose(spline.control_points[-1])
def test_rational_spline_curve_points_by_nurbs_python(): arc = ConstructionArc(end_angle=90) spline = rational_bspline_from_arc(end_angle=arc.end_angle) curve = spline.to_nurbs_python_curve() t = list(linspace(0, 1, 10)) points = list(spline.points(t)) expected = list(curve.evaluate_list(t)) for p, e in zip(points, expected): assert p.isclose(e)
def test_rational_spline_derivatives_by_nurbs_python(): arc = ConstructionArc(end_angle=90) spline = rational_bspline_from_arc(end_angle=arc.end_angle) curve = spline.to_nurbs_python_curve() t = list(linspace(0, 1, 10)) derivatives = list(spline.derivatives(t, n=1)) expected = [curve.derivatives(u, 1) for u in t] for (p, d1), (e, ed1) in zip(derivatives, expected): assert p.isclose(e) assert d1.isclose(ed1)
def test_from_ezdxf_bspline_to_nurbs_python_curve_rational(): bspline = rational_bspline_from_arc(center=Vec3(0, 0), radius=2, start_angle=0, end_angle=90) # to NURBS-Python curve = bspline.to_nurbs_python_curve() assert curve.degree == 2 assert len(curve.ctrlpts) == 3 assert len(curve.knotvector) == 6 # count + order assert curve.rational is True assert curve.weights == [1.0, 0.7071067811865476, 1.0] # and back to ezdxf spline = BSpline.from_nurbs_python_curve(curve) assert spline.degree == 2 assert len(spline.control_points) == 3 assert len(spline.knots()) == 6 # count + order assert spline.weights() == (1.0, 0.7071067811865476, 1.0)
def test_rational_spline_from_circular_arc_has_expected_parameters(): arc = ConstructionArc(end_angle=90) spline = rational_bspline_from_arc(end_angle=arc.end_angle) assert spline.degree == 2 cpoints = spline.control_points assert len(cpoints) == 3 assert cpoints[0].isclose((1, 0, 0)) assert cpoints[1].isclose((1, 1, 0)) assert cpoints[2].isclose((0, 1, 0)) weights = spline.weights() assert len(weights) == 3 assert weights[0] == 1.0 assert weights[1] == math.cos(math.pi / 4) assert weights[2] == 1.0 # as BSpline constructor() s2 = BSpline.from_arc(arc) assert spline.control_points == s2.control_points