Skip to content

Commit d6aae2f

Browse files
committed
Simplify and generalize BezierSegment.
As it turns out, it is simpler to write the d-dimensional version than the 2-dimensional special case.
1 parent 8d62769 commit d6aae2f

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

examples/user_interfaces/embedding_in_wx4_sgskip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, canvas, cankill):
2525
# for simplicity I'm going to reuse a bitmap from wx, you'll
2626
# probably want to add your own.
2727
tool = self.AddTool(wx.ID_ANY, 'Click me', _load_bitmap('back.png'),
28-
'Activate custom contol')
28+
'Activate custom control')
2929
self.Bind(wx.EVT_TOOL, self._on_custom, id=tool.GetId())
3030

3131
def _on_custom(self, evt):

lib/matplotlib/bezier.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def find_bezier_t_intersecting_with_closedpath(
145145

146146
class BezierSegment(object):
147147
"""
148-
A simple class of a 2-dimensional bezier segment
148+
A D-dimensional Bezier segment.
149149
"""
150150

151151
# Higher order bezier lines can be supported by simplying adding
@@ -156,24 +156,21 @@ class BezierSegment(object):
156156

157157
def __init__(self, control_points):
158158
"""
159-
*control_points* : location of contol points. It needs have a
160-
shape of n * 2, where n is the order of the bezier line. 1<=
161-
n <= 3 is supported.
159+
Parameters
160+
----------
161+
control_points : (N, D) array
162+
Location of control points. N = 2, 3 and 4 (linear, quadratic, and
163+
cubic Beziers) are supported.
162164
"""
163165
_o = len(control_points)
164166
self._orders = np.arange(_o)
165-
166167
_coeff = BezierSegment._binom_coeff[_o - 1]
167-
xx, yy = np.asarray(control_points).T
168-
self._px = xx * _coeff
169-
self._py = yy * _coeff
168+
self._px = np.asarray(control_points).T * _coeff
170169

171170
def point_at_t(self, t):
172-
"evaluate a point at t"
173-
tt = ((1 - t) ** self._orders)[::-1] * t ** self._orders
174-
_x = np.dot(tt, self._px)
175-
_y = np.dot(tt, self._py)
176-
return _x, _y
171+
"""Return the point on the Bezier curve for parameter *t*."""
172+
return tuple(
173+
self._px @ (((1 - t) ** self._orders)[::-1] * t ** self._orders))
177174

178175

179176
@cbook._rename_parameter("3.1", "tolerence", "tolerance")

0 commit comments

Comments
 (0)