Skip to content
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

#5339 Add tangent snapping to straight segment tool #5995

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

andrewvarga
Copy link
Contributor

@andrewvarga andrewvarga commented Mar 25, 2025

Implements #5339

When drawing a straight segment, if the previous segment was an arc, the straight segment is snapping to the outgoing tangent direction of that previous arc.

When both axis and tangent direction intersects then the snapped point is that intersection.

I used a threshold in screen space pixel size to determine snapping and introduced a few hotkeys:

  • ctrl / alt: disable snapping
  • shift: force snapping to previous arc even if the current position is out of the snapping threshold

Possible further improvements:

  • When pressing / releasing shift / ctrl the drawing doesn't update immediately as snapping logic only runs when the mouse is moved. This could be changed for a better UX
  • When forcing tangent snapping with shift, the snapping is still calculated using the mouse position, not the actual end position of the draft straight segment - I think the latter would be a bit better
    Both of these can be done but I wanted to make sure it's worth the time spent on it, especially as these hotkeys were not even in the spec for the original issue.

There is potentially a more general task here about unifying snapping logic:

  • Should ctrl also disable snapping for axes and other profiles?
  • Axis intersection is still handled by three.js Raycaster but probably easier to move it to this new code so they are in a unified place

Copy link

vercel bot commented Mar 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Mar 28, 2025 1:20pm

Copy link

qa-wolf bot commented Mar 25, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@andrewvarga andrewvarga changed the title WIP: #5339 Add tangent snapping to straight segment tool #5339 Add tangent snapping to straight segment tool Mar 27, 2025
@franknoirot
Copy link
Collaborator

Thanks for the thorough write-up on this! Reviewing now

@pierremtb
Copy link
Collaborator

This is super exciting. Checking out locally now

@franknoirot
Copy link
Collaborator

Really promising stuff. I think that the code mod that gets written just needs to be changed a little bit. Right now you're writing code like line(end = [5, 5]) but I think you need to make use of our tangentEnd standard library function to write code like:

sketch001 = startSketchOn(XZ)
profile001 = startProfileAt([0, 0], sketch001)
  |> line(end = [3, 2])
  |> tangentialArcTo([5, -10], %, $arc001)
  |> angledLine({ angle = tangentToEnd(arc001), length = 12 }, %)

There should be helper functions for generating a tag for the previous segment for use in the angledLine call within modifyAst.ts

Screenshare.-.2025-03-28.9_26_12.AM-compressed.mp4

@franknoirot
Copy link
Collaborator

I'd also love to have a test for some of this functionality. There are examples of snapping logic tests in the code base like this one that could be extended or copied from, and getTanPreviousPoint and closestPointOnRay could have a unit test or two. I'm happy to pair on either of those if you want a hand.

@andrewvarga
Copy link
Contributor Author

Really promising stuff. I think that the code mod that gets written just needs to be changed a little bit. Right now you're writing code like line(end = [5, 5]) but I think you need to make use of our tangentEnd standard library function to write code like:

sketch001 = startSketchOn(XZ)
profile001 = startProfileAt([0, 0], sketch001)
  |> line(end = [3, 2])
  |> tangentialArcTo([5, -10], %, $arc001)
  |> angledLine({ angle = tangentToEnd(arc001), length = 12 }, %)

There should be helper functions for generating a tag for the previous segment for use in the angledLine call within modifyAst.ts

Screenshare.-.2025-03-28.9_26_12.AM-compressed.mp4

@franknoirot thanks that's very useful!

To confirm, I should only use angledLine if the current draft segment snaps to the tangent direction, otherwise it's still just a line, right?
I guess another option would be to only snap to tangent with a shift key, which would save some calculations but then users might not discover this feature so easily.

Also good point about snapping to horizontal / vertical axes, let me know if I should add that to this PR? It doesn't seem too big to implement. I was thinking of drawing an extra long (dashed?) line as well in the tangent direction to emphasize the snapping.

And yes, adding tests to this as well.

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.

3 participants