Skip to content

fix: resolve QPoint/QPointF mismatch in bounded_move_shapes#241

Merged
vietanhdev merged 1 commit into
mainfrom
fix/bounded-move-shapes-edge-crash
Jul 11, 2026
Merged

fix: resolve QPoint/QPointF mismatch in bounded_move_shapes#241
vietanhdev merged 1 commit into
mainfrom
fix/bounded-move-shapes-edge-crash

Conversation

@vietanhdev

Copy link
Copy Markdown
Owner

Summary

Third and last crash path in the QPoint/QPointF mismatch bug class (see #237, #240, #238):

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_vertex change in that PR. Co-authored-by trailer credits the original fix.

Fix

Convert the QPoint literals used to clamp pos in bounded_move_shapes to QPointF, matching the type used everywhere else in the drawing pipeline.

Test plan

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>
Copilot AI review requested due to automatic review settings July 11, 2026 04:46
@vietanhdev
vietanhdev merged commit d91d959 into main Jul 11, 2026
10 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with QtCore.QPointF(...) in bounded_move_shapes() to avoid QPointF/QPoint operator TypeErrors.
  • Kept clamping logic localized to canvas.py without touching intersection_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()))),
)
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants