fix(canvas): prevent coordinate drift and redundant saves on navigation#11
Merged
Merged
Conversation
Polygon points were drifting by 1px per save/load cycle when navigating between images. Two bugs combined to cause this: serializer used only 3 decimal places (insufficient for sub-pixel accuracy at common resolutions), and the deserializer used truncation instead of rounding. At 4x zoom the drift was visible as a 4px jump per navigation cycle, stabilizing after 2-3 passes. Also removes redundant AutoSaveCurrentImage call from LoadImageAtIndex. The PolygonsChanged signal already triggers a synchronous save before navigation can occur, so the explicit call was dead code. Undo and Redo now check CanUndo/CanRedo before emitting PolygonsChanged, and Paste no longer emits the signal when the clipboard is empty. - Increase serializer precision from 3 to 6 decimal places - Replace static_cast<int> truncation with std::round in deserializer - Guard Undo/Redo emission behind CanUndo/CanRedo checks - Guard Paste emission behind successful paste check - Remove AutoSaveCurrentImage from LoadImageAtIndex (dead code) - Add RoundTripNonDivisibleCoordinates and RoundTripStableAcrossMultipleCycles tests - Fix KeyPressCtrlZCallsUndo test and add missing Undo/Redo/Paste signal tests
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
static_cast<int>) instead of rounding in the deserializer. At 4x zoom this appeared as a 4px jump per navigation cycle, stabilizing after 2-3 passes.AutoSaveCurrentImagewas called unconditionally inLoadImageAtIndex, but thePolygonsChangedsignal already triggers a synchronous save before navigation occurs — making the explicit call dead code.PolygonsChangedemissions:Undo/Redoemitted the signal even when there was nothing to undo/redo;Pasteemitted it even when the clipboard was empty.Changes
static_cast<int>truncation withstd::roundin deserializerUndo/Redosignal emission behindCanUndo/CanRedochecksPastesignal emission behind successful paste result checkAutoSaveCurrentImagecall fromLoadImageAtIndex(dead code)Test plan
KeyPressCtrlZCallsUndotest (was incorrectly passing withCanUndo=false)UndoSkippedWhenCanUndoFalseRedoSkippedWhenCanRedoFalsePasteEmitsPolygonsChangedOnSuccessPasteDoesNotEmitPolygonsChangedWhenClipboardEmptyRoundTripNonDivisibleCoordinates— verifies exact round-trip for coords that drift with 3dec+truncation (e.g. 105/640)RoundTripStableAcrossMultipleCycles— simulates 5 navigation cycles, verifies zero drift