Skip to content

Commit 1c23899

Browse files
committed
vectorize bezier.__call__, keep point_at_t
1 parent a98a12e commit 1c23899

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/matplotlib/bezier.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,20 @@ def __init__(self, control_points):
239239
coeff = [math.factorial(self._N - 1)
240240
// (math.factorial(i) * math.factorial(self._N - 1 - i))
241241
for i in range(self._N)]
242-
self._px = self._cpoints.T * coeff
242+
self._px = (self._cpoints.T * coeff).T
243243

244244
def __call__(self, t):
245-
return self.point_at_t(t)
245+
t = np.array(t)
246+
orders_shape = (1,)*t.ndim + self._orders.shape
247+
t_shape = t.shape + (1,) # self._orders.ndim == 1
248+
orders = np.reshape(self._orders, orders_shape)
249+
rev_orders = np.reshape(self._orders[::-1], orders_shape)
250+
t = np.reshape(t, t_shape)
251+
return ((1 - t)**rev_orders * t**orders) @ self._px
246252

247253
def point_at_t(self, t):
248254
"""Return the point on the Bezier curve for parameter *t*."""
249-
return tuple(
250-
self._px @ (((1 - t) ** self._orders)[::-1] * t ** self._orders))
255+
return tuple(self(t))
251256

252257
@property
253258
def control_points(self):

0 commit comments

Comments
 (0)