Пример #1
0
    def from_spline(
        cls,
        spline: BSpline,
        start_width: float,
        end_width: float,
        segments: int,
    ) -> "CurvedTrace":
        """
        Create curved trace from a B-spline.

        Args:
            spline: :class:`~ezdxf.math.BSpline` object
            start_width: start width
            end_width: end width
            segments: count of segments for approximation

        """
        curve_trace = cls()
        count = segments + 1
        t = linspace(0, spline.max_t, count)
        for ((point, derivative),
             width) in zip(spline.derivatives(t, n=1),
                           linspace(start_width, end_width, count)):
            normal = Vec2(derivative).orthogonal(True)
            curve_trace._append(Vec2(point), normal, width)
        return curve_trace
Пример #2
0
def test_bspline_point_calculation_against_derivative_calculation():
    # point calculation and derivative calculation are not the same functions
    # for optimization reasons. The derivatives() function returns the curve
    # point and n derivatives, check if both functions return the
    # same curve point:
    spline = BSpline(DEFPOINTS, order=4)
    curve_points = [p[0] for p in spline.derivatives(PARAMS, n=1)]
    for p, expected in zip(curve_points, spline.points(PARAMS)):
        assert p.isclose(expected)
Пример #3
0
def test_bspline_derivative_calculation_to_pre_calculated_results():
    spline = BSpline(DEFPOINTS, order=4)
    for points, expected in zip(spline.derivatives(PARAMS, n=2),
                                DERIVATIVES_ORDER_4):
        for p, e in zip(points, expected):
            assert p.isclose(e)
Пример #4
0
 def test_derivative_calculation_is_correct(self):
     spline = BSpline(DEFPOINTS, order=4).to_nurbs_python_curve()
     for t, expected in zip(PARAMS, DERIVATIVES_ORDER_4):
         results = spline.derivatives(t, order=2)
         for e, p in zip(expected, results):
             assert e.isclose(p)