Skip to content

Fix selection box positioning and alignment when document is PTZ'd#3718

Open
krVatsal wants to merge 11 commits intoGraphiteEditor:masterfrom
krVatsal:fix-cooridnate-system-mismatch-during-an-active-box-selection
Open

Fix selection box positioning and alignment when document is PTZ'd#3718
krVatsal wants to merge 11 commits intoGraphiteEditor:masterfrom
krVatsal:fix-cooridnate-system-mismatch-during-an-active-box-selection

Conversation

@krVatsal
Copy link
Contributor

@krVatsal krVatsal commented Feb 4, 2026

Fixes #2391

When performing a box selection with the Select tool, panning (via scroll wheel) would cause the selection rectangle's starting point to move with the viewport instead of staying fixed on the canvas.

Solution
Store the drag start position in document coordinates (drag_start_document) rather than viewport coordinates
Transform this document anchored point back to viewport space when computing the selection box
Remove the viewport shift compensation for the start point during auto panning since the start is now properly anchored to document space

Still confused about the expected outcome for zooming, can you clarify more for what should be the output for it?

Recording.2026-02-04.235848.mp4

@Keavon
Copy link
Member

Keavon commented Feb 4, 2026

Still confused about the expected outcome for zooming, can you clarify more for what should be the output for it?

In all cases, the document-space start point and document-space current pointer position should determine the bounding box shown, as well as the current document tilt. You can always take those three parameters (start point, current point, current tilt) and draw a rectangle matching the document space coordinates of them (but transformed into viewport space for the final drawing of the rectangle, since overlays are in viewport space).

@krVatsal
Copy link
Contributor Author

krVatsal commented Feb 5, 2026

Still confused about the expected outcome for zooming, can you clarify more for what should be the output for it?

In all cases, the document-space start point and document-space current pointer position should determine the bounding box shown, as well as the current document tilt. You can always take those three parameters (start point, current point, current tilt) and draw a rectangle matching the document space coordinates of them (but transformed into viewport space for the final drawing of the rectangle, since overlays are in viewport space).

Thanks for the clarification! I think the current implementation already handles this correctly for both panning and zooming.

@krVatsal krVatsal marked this pull request as ready for review February 5, 2026 09:39
pub fn selection_box(&self) -> [DVec2; 2] {
if self.drag_current == self.drag_start {
pub fn selection_box(&self, metadata: &DocumentMetadata) -> [DVec2; 2] {
// If we have a document-anchored start point, transform it to viewport
Copy link
Member

Choose a reason for hiding this comment

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

Why is this an "if" scenario? Why isn't it always the case that the start point is document-anchored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out, you are correct it should always be document anchored i have fixed this in next commit.

snap_candidates: Vec<SnapCandidatePoint>,
auto_panning: AutoPanning,
drag_start_center: ViewportPosition,
drag_start_document: Option<DVec2>,
Copy link
Member

Choose a reason for hiding this comment

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

See other comment. I'm possibly a bit concerned that this is an Option. When would it be None? Can you make sure that this is built (if it's not already) in such a way that it makes invalid state unrepresentable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the tool is not always in a dragging state (e.g., when it is [Ready]). However, the variants themselves (like [Dragging], [Drawing], [ResizingBounds], etc.) now store [drag_start] as a mandatory, non-optional field(in the new commit i am pushing in some time).

@Keavon
Copy link
Member

Keavon commented Feb 13, 2026

Select tool behavior is good from my QA test. Just see my concern from my code review comments. It might represent an opportunity to simplify the code if there is some kind of extra conditionality going on right now.

The equivalent implementation is missing from the Path tool.

There is also one small bug I've noticed that this implementation seems to consistent trigger, which is that the box selection (upon initially clicking down but not yet dragging) draws a tiny square (#2595). I've observed this in a few other occasions but now your branch appears to be making this happen all the time, which is good since that should make it easier to debug and fix the root cause.

capture_12_.mp4

Please mark as Ready for Review when you respond so I don't miss this while it's a draft.

@Keavon Keavon marked this pull request as draft February 13, 2026 01:08
@Keavon Keavon changed the title Fixed Box selection with the Select tool and Path tool to follow canv… Fix selection box positioning and alignment when document is PTZ'd Feb 13, 2026
@krVatsal krVatsal marked this pull request as ready for review February 14, 2026 11:41
@Keavon
Copy link
Member

Keavon commented Feb 15, 2026

Can you please help me understand how you went from +29-18 lines of changes before my code review that requested a potential simplification, to a staggering +196-89 after the new commit? It is too many changes for me to try to read and understand, but this doesn't make sense to me at all and it makes me think it was either written by an LLM or— actually I don't have any other theories that could explain how my change requests resulted in 6x the changes from before then. And this doesn't even include the requested Path tool changes, which would be the only thing I requested that I would expect a ~doubling (not 6x'ing) of the code. But before you apply this to the Path tool, let's make sure we first figure out what the problem is here that I'm pointing out.

@Keavon Keavon marked this pull request as draft February 15, 2026 07:14
@krVatsal
Copy link
Contributor Author

Can you please help me understand how you went from +29-18 lines of changes before my code review that requested a potential simplification, to a staggering +196-89 after the new commit? It is too many changes for me to try to read and understand, but this doesn't make sense to me at all and it makes me think it was either written by an LLM or— actually I don't have any other theories that could explain how my change requests resulted in 6x the changes from before then. And this doesn't even include the requested Path tool changes, which would be the only thing I requested that I would expect a ~doubling (not 6x'ing) of the code. But before you apply this to the Path tool, let's make sure we first figure out what the problem is here that I'm pointing out.

Yeah, i was a bit blank about how should i simplify this further, that's why i took help of llm apologies for that. I'll look into this again and update with a much cleaner version. Thankyou for your patience.

@Keavon
Copy link
Member

Keavon commented Feb 15, 2026

Undisclosed LLM usage is a violation of our acceptable AI usage policy. Consider this your one warning.

@krVatsal
Copy link
Contributor Author

Sure, this won't happen again.

@Keavon
Copy link
Member

Keavon commented Feb 22, 2026

Do you have any updates on reverting this to the original state and then taking action on my original comments?

@krVatsal
Copy link
Contributor Author

krVatsal commented Feb 22, 2026

Yeah was working on this pr actually my mid semester exams are going on so there was some blockage of time, will update this by EOD.

@krVatsal
Copy link
Contributor Author

I think i should open a new PR as this one is getting a bit messy for me to manage.

@Keavon
Copy link
Member

Keavon commented Feb 22, 2026

Please do not, there is no reason to do so.

@krVatsal krVatsal force-pushed the fix-cooridnate-system-mismatch-during-an-active-box-selection branch from 0271292 to e044f13 Compare March 1, 2026 13:15
@krVatsal krVatsal marked this pull request as ready for review March 1, 2026 17:41
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/tool/tool_messages/select_tool.rs">

<violation number="1" location="editor/src/messages/tool/tool_messages/select_tool.rs:448">
P2: Floating-point equality comparison after coordinate-space roundtrip will virtually never be true. `start_viewport` is computed by roundtripping through document space (`viewport→document→viewport`), introducing floating-point drift, while `drag_current` comes directly from mouse input. Use a distance-based threshold comparison instead of exact equality to preserve the click-selection tolerance fallback.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/tool/tool_messages/select_tool.rs">

<violation number="1" location="editor/src/messages/tool/tool_messages/select_tool.rs:447">
P2: The `roundtrip_epsilon` of `10. * f64::EPSILON` (~2.2e-15) is far too small for comparing viewport coordinates that have been round-tripped through an affine transform. Floating-point error from `M * M⁻¹ * p` scales with coordinate magnitude, so for typical pixel values (hundreds to thousands), the per-component error is ~1e-13, vastly exceeding this threshold. This makes the epsilon check effectively equivalent to the original exact `==` comparison.

Use a small absolute epsilon that's meaningful in pixel space (e.g. a tiny fraction of a pixel) rather than a multiple of machine epsilon.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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.

Box/lasso selection should be compatible with PTZ

3 participants