-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make BezierSegment support N-dimensional beziers #9686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We can simply take the dimension from that of the first control point. There is no functional change for existing callers. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
@@ -163,31 +163,29 @@ class BezierSegment(object): | |||
def __init__(self, control_points): | |||
""" | |||
*control_points* : location of contol points. It needs have a | |||
shpae of n * 2, where n is the order of the bezier line. 1<= | |||
n <= 3 is supported. | |||
shpae of n * D, where n is the order of the bezier line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"It needs to have a shape"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be simplified with some NumPy functions. It also needs a test.
self._orders = np.arange(_o) | ||
_coeff = BezierSegment._binom_coeff[_o - 1] | ||
|
||
_control_points = np.asarray(control_points) | ||
xx = _control_points[:, 0] | ||
yy = _control_points[:, 1] | ||
xyz = [_control_points[:, i] for i in range(0, dim)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is an array, then isn't this just _contrrol_points.T
?
|
||
self._px = xx * _coeff | ||
self._py = yy * _coeff | ||
self._pxyz = [xx * _coeff for xx in xyz] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this is xyz * _coeff
.
_y = sum(tt * self._py) | ||
|
||
return _x, _y | ||
_xyz = [sum(tt * px) for px in self._pxyz] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this is np.sum(tt * px, axis=1)
.
I'm happy to update this as you suggest. Also, I'd be happy to write a test but the test suite does not run for me. See error message below. I would try running just the existing test to see if I can extend it but AFAICT there is no existing unit test for this class. |
Using I'm not sure if there's an existing test; it might just be done implicitly through other usage. |
Closing as superseded by #13355. Thanks for the PR! |
Here is a simple patch that generalises matplotlib.bezier.BezierSegment to N-dimensional segments. I needed this for my own activities, not for anything in matplotlib, but the matplotlib bezier was convenient.
I have forward ported this patch from Debian's matplotlib 2.0.0+dfsg1-2. I have tested this change only in the context of 2.0.0, and only ad-hoc. But it's very straightforward so I'm hoping that the CI will be happy.