-
Notifications
You must be signed in to change notification settings - Fork 124
Bug Fix Closed Loop #3522
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
base: master
Are you sure you want to change the base?
Bug Fix Closed Loop #3522
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ def __init__( | |
| outline_color: QtGui.QColor = Colors.DEFAULT_GRAPHICS_COLOR, | ||
| fill_color: Optional[QtGui.QColor] = None, | ||
| line_width: float = LINE_WIDTH, | ||
| closed: bool = False, | ||
| ) -> None: | ||
| """Initialize the GLPolygon | ||
|
|
||
|
|
@@ -30,6 +31,8 @@ def __init__( | |
| :param outline_color: The color of the polygon's outline | ||
| :param fill_color: The color used to fill the polygon, or None if no fill | ||
| :param line_width: The line width of the polygon's outline | ||
| :param closed: If true, connect the first and the last point to form a | ||
| closed shape. Otherwise, the shape is left open. | ||
| """ | ||
| super().__init__( | ||
| parent_item=parent_item, | ||
|
|
@@ -38,6 +41,7 @@ def __init__( | |
| line_width=line_width, | ||
| ) | ||
|
|
||
| self.is_closed = closed | ||
| self.set_points(points) | ||
|
|
||
| def set_points(self, points: list[tuple[float, float]]) -> None: | ||
|
|
@@ -62,7 +66,10 @@ def _update_shape_data(self) -> None: | |
| if not self.points: | ||
| return | ||
|
Comment on lines
66
to
67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are your thoughts on logging something here as an error/warning? I think this error could easily be buried otherwise if we just silently return early. |
||
|
|
||
| vertices = [(point[0], point[1], 0) for point in self.points + [self.points[0]]] | ||
| render_points = ( | ||
| self.points + [self.points[0]] if self.is_closed else self.points | ||
| ) | ||
| vertices = [(point[0], point[1], 0) for point in render_points] | ||
| self.setData(pos=vertices) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should vertices contain the duplicate self.points[0] when the polygon is closed? I thought vertices means independent vertices so it should copy from points instead of render_points.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I believe the answer is yes. The vertices for the following must be [A, B, D, C, A] If the vertices are [A, B, D, C], it will render the following:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I have done a bit more digging, you did bring up a fairly interesting point. The inheritance diagram works like the following: The fundamental problem here is that we probably want a
I am not sure if there is a easy fix without sending a patch to pyqtgraph. CC: @williamckha
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you are getting me thinking about this class, I feel like there should be a clearer definition for what is a "polygon" especially since we can form an "open looped" shape. The notion of an "open" polygon feels a bit strange and leaves some ambiguity about how this class may handle lists of points with <3 points in them (since geometrically, that cannot form a polygon. I think we should either be more explicit with the fact that this class can support any number of points greater than 0, and guard against cases where a closed loop is used with fewer than 3 points (since this can have unintended rendering consequences for the caller). Otherwise, the more software-y approach here would be to abstract the class into some GL Line class (unless this is what GLLinePlotItem is, but I haven't looked into that class yet). Hence, we can clearly define polygons as ALWAYS closed loops and have their rendering inherit from GL Line.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I agree that this should be a different class that better describes a series of line segments, cause my first thought of rendering for example the path of a robot would definitely not be a polygon |
||
| if self.fill_graphic: | ||
|
|
||

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 am a bit confused by why the initialization of is_closed. Have we used the constructor parameter "closed" at all, and is there a reason why we set is_closed after calling set_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.
Thanks, I think you just discovered a bug that is not caught!
I will move
self.is_closedone line aboveself.set_points(points).My guess is that
set_pointsis called after the construction of this class so this bug is never discovered.