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
Allow Line.points definition to be a mix of lists/tuples #3866
Conversation
Fix for issue kivy#3481 Line.points can be defined as list of lists, tuples and coordinates (float values) setter method modified to check each element of the argument list and append it to self._points accordingly Line example file /examples/canvas/line.py updated with the new possible way of defining points
Forgot to remove it after experimenting, sorry 👅
def __set__(self, points): | ||
self._points = list(points) | ||
tmp = [] | ||
for p in points: |
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.
I haven't tested, but it looks like a slow implementation. I think mixing lists/tuples with plain values is not a priority. points
could be either a plain list/tuple, a list/tuple of lists, a list/tuple of tuples, or a list/tuple of lists and tuples (possibly mixed). This way, a faster algo could be used, something like what @kived proposed in the issue.
Ignores the case when self._points is a mix of list/tuple/float Only works in cases where self._points is a list of iterables
@dessant I made the changes you requested. I agree the previous algorithm was slower. Given the conditions you mentioned we can use kived's algorithm |
def __set__(self, points): | ||
self._points = list(points) | ||
import itertools |
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.
Is there a reason for doing the import in the method?
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.
I just realised that will slow things down :P
Moved import to top of module Added case when points is a plain list
👍 |
Allow Line.points definition to be a mix of lists/tuples
Fix for issue #3481
Line.points
can be defined as list of lists, tuples and coordinates (float values).Setter method modified to check each element of the argument list and append it to
self._points
accordingly.Line example file /examples/canvas/line.py updated with the new possible way of defining points.
Note: appending a tuple to
points
causes problems