fix: resolve QPoint/QPointF mismatch in bounded_move_shapes#241
Merged
Conversation
bounded_move_shapes() mixed QPointF (pos, from mouse events) with QPoint literals when clamping a dragged shape to the pixmap border, raising a TypeError when a selected shape is dragged near the image edge. This is the same class of bug as #237/#240 (intersection_point returning QPoint) but an independent instance, since this path never calls intersection_point(). Co-authored-by: chaosbee <chaosbee@163.com>
There was a problem hiding this comment.
Pull request overview
Fixes a remaining crash path caused by mixing QtCore.QPoint (int) and QtCore.QPointF (float) arithmetic when dragging whole selected shapes near the image edge, by ensuring the clamping math in bounded_move_shapes() operates on QPointF values.
Changes:
- Replaced
QtCore.QPoint(...)clamp deltas withQtCore.QPointF(...)inbounded_move_shapes()to avoidQPointF/QPointoperator TypeErrors. - Kept clamping logic localized to
canvas.pywithout touchingintersection_point()or vertex-move paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+635
to
+637
| pos -= QtCore.QPointF( | ||
| float(min(0, int(o1.x()))), float(min(0, int(o1.y()))) | ||
| ) |
Comment on lines
+640
to
643
| pos += QtCore.QPointF( | ||
| float(min(0, int(self.pixmap.width() - o2.x()))), | ||
| float(min(0, int(self.pixmap.height() - o2.y()))), | ||
| ) |
2 tasks
vietanhdev
added a commit
that referenced
this pull request
Jul 11, 2026
…242) Copilot's review of #241 flagged that the left/top clamp still did int(o1.x()) before wrapping in QPointF, so sub-pixel overflows (e.g. -0.3) truncate to 0 and silently fail to correct the position. Verifying that fix surfaced a second, independent bug in the same lines: the right/bottom clamp corrects against pixmap.width()/height() instead of (width() - 1)/(height() - 1), which is the bound out_off_pixmap() actually enforces — so a shape overflowing the right or bottom edge stayed uncorrected regardless of the int() truncation. Both are pre-existing (predate #237/#238/#240/#241); this PR only touches the four lines already modified by #241. Adds a regression test covering both edges plus the original TypeError crash path.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third and last crash path in the
QPoint/QPointFmismatch bug class (see #237, #240, #238):intersection_point()at the source, closing the "draw a shape to the image edge" andbounded_move_vertex(bug: during labeling, while points or shape over the canvas, program will broken #237) crashes.bounded_move_shapes()has an independent instance of the same mismatch — it never callsintersection_point(), so fix: Crash when bounding box touches image edge #240 didn't cover it. It crashes withTypeError: unsupported operand type(s) for -=: 'QPointF' and 'QPoint'when dragging a whole selected shape (not just a vertex) near the image edge.This applies the same fix @ChaosBee already wrote for this exact hunk in #238, extracted into its own PR so it can land independently of the (now partially redundant)
bounded_move_vertexchange in that PR. Co-authored-by trailer credits the original fix.Fix
Convert the
QPointliterals used to clampposinbounded_move_shapestoQPointF, matching the type used everywhere else in the drawing pipeline.Test plan
mainpre-fix (dragging a selected shape to the image edge)CLAUDE.md(unrelated, environment-dependent), no new failures