Skip to content

Commit

Permalink
use numpy in BSpline.bezier_decomposition()
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Jan 12, 2025
1 parent 1506f9d commit fe28476
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/ezdxf/math/bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fe28476

Please sign in to comment.