def test_cubic_bezier_approximation(): bspline = BSpline.from_fit_points([(0, 0), (10, 20), (30, 10), (40, 10), (50, 0), (60, 20), (70, 50), (80, 70)]) bezier_segments = list(bspline.cubic_bezier_approximation(level=3)) assert len(bezier_segments) == 28 bezier_segments = list(bspline.cubic_bezier_approximation(segments=40)) assert len(bezier_segments) == 40
def test_bezier_decomposition(): bspline = BSpline.from_fit_points([(0, 0), (10, 20), (30, 10), (40, 10), (50, 0), (60, 20), (70, 50), (80, 70)]) bezier_segments = list(bspline.bezier_decomposition()) assert len(bezier_segments) == 5 # results visually checked to be correct assert bezier_segments[0] == [(0.0, 0.0, 0.0), (2.02070813064438, 39.58989657555839, 0.0), (14.645958536022286, 10.410103424441612, 0.0), (30.0, 10.0, 0.0)] assert bezier_segments[-1] == [(60.0, 20.0, 0.0), (66.33216513897267, 43.20202388489432, 0.0), (69.54617236126121, 50.37880459351478, 0.0), (80.0, 70.0, 0.0)]
def construction_tool(self) -> BSpline: """ Returns construction tool :class:`ezdxf.math.BSpline`. .. versionadded:: 0.13 """ if self.control_point_count(): weights = self.weights if len(self.weights) else None knots = self.knots if len(self.knots) else None return BSpline(control_points=self.control_points, order=self.dxf.degree + 1, knots=knots, weights=weights) elif self.fit_point_count(): return BSpline.from_fit_points(self.fit_points, degree=self.dxf.degree) else: raise ValueError( 'Construction tool requires control- or fit points.')
def test_flattening(): fitpoints = [(0, 0), (1, 3), (2, 0), (3, 3)] bspline = BSpline.from_fit_points(fitpoints) assert list(bspline.flattening(0.01, segments=4)) == EXPECTED_FLATTENING