Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

ijackson
Copy link

@ijackson ijackson commented Nov 4, 2017

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.

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
Copy link
Contributor

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"?

Copy link
Member

@QuLogic QuLogic left a 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)]
Copy link
Member

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]
Copy link
Member

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]
Copy link
Member

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).

@ijackson
Copy link
Author

ijackson commented Nov 4, 2017

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.

transcript.txt

@QuLogic
Copy link
Member

QuLogic commented Nov 4, 2017

Using PYTHONPATH is broken and won't find any of the built C libraries. Using an editable install or following the instructions in the developers' guide instead should work (I use the former in a conda environment.)

I'm not sure if there's an existing test; it might just be done implicitly through other usage.

@anntzer
Copy link
Contributor

anntzer commented Jan 27, 2019

@ijackson Do you still want to push this through?
I actually think the implicit testing of bezier through the rest of the codebase is sufficient, but at least the points raised by @QuLogic need to be addressed.

@anntzer
Copy link
Contributor

anntzer commented Mar 1, 2019

Closing as superseded by #13355. Thanks for the PR!

@anntzer anntzer closed this Mar 1, 2019
@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants