add B-spline to Bezier curve decomposition
This will be useful for drawing backends with cubic bezier support like
PyQt, PyCairo and SVG.
@@ -106,6 +106,25 @@ def test_transform_interface():
assert spline.control_points[0] == (2, 2, 3)
+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)
+ ]
+
+
DBSPLINE = [
[[0.0, 0.0, 0.0], [20.0, 40.0, 40.0], [0.0, -50.0, -35.0]],
[[1.5000000000000002, 2.8593750000000004, 2.9015625000000003], [20.0, 36.25, 37.375], [0.0, -50.0, -35.0]],
