From fe2847663c23ed67e296ad04a3e0d4f2903c2a54 Mon Sep 17 00:00:00 2001 From: mozman Date: Sun, 12 Jan 2025 10:53:41 +0100 Subject: [PATCH] use numpy in BSpline.bezier_decomposition() --- src/ezdxf/math/bspline.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ezdxf/math/bspline.py b/src/ezdxf/math/bspline.py index 3241bbf81..5131b630e 100644 --- a/src/ezdxf/math/bspline.py +++ b/src/ezdxf/math/bspline.py @@ -1254,23 +1254,24 @@ def bezier_decomposition(self) -> Iterable[list[Vec3]]: n = self.count - 1 p = self.degree - knots = self._basis.knots # U - control_points = self._control_points # Pw - alphas = [0.0] * len(knots) + knots = np.array(self._basis.knots) # U + control_points = np.array(self._control_points) # Pw + alphas = np.zeros(len(knots)) m = n + p + 1 a = p b = p + 1 - bezier_points = list(control_points[0 : p + 1]) # Qw + bezier_points = control_points[0 : p + 1] # Qw while b < m: - next_bezier_points = [NULLVEC] * (p + 1) + next_bezier_points = np.zeros(shape=(p + 1, 3)) + i = b - while b < m and math.isclose(knots[b + 1], knots[b]): + while b < m and np.isclose(knots[b + 1], knots[b]): b += 1 mult = b - i + 1 if mult < p: - numer = knots[b] - knots[a] + numer: float = knots[b] - knots[a] for j in range(p, mult, -1): alphas[j - mult - 1] = numer / (knots[a + j] - knots[a]) r = p - mult @@ -1284,11 +1285,12 @@ def bezier_decomposition(self) -> Iterable[list[Vec3]]: ] * (1.0 - alpha) if b < m: next_bezier_points[save] = bezier_points[p] - yield bezier_points + yield Vec3.list(bezier_points) if b < m: - for i in range(p - mult, p + 1): - next_bezier_points[i] = control_points[b - p + i] + # for i in range(p - mult, p + 1): + # next_bezier_points[i] = control_points[b - p + i] + next_bezier_points[p - mult: p + 1] = control_points[b - mult: b + 1] a = b b += 1 bezier_points = next_bezier_points