Skip to content

Support distance constraints for higher sketch geometry#11403

Merged
franknoirot merged 13 commits into
mainfrom
franknoirot/adhoc/distance-constraint-pairs
May 11, 2026
Merged

Support distance constraints for higher sketch geometry#11403
franknoirot merged 13 commits into
mainfrom
franknoirot/adhoc/distance-constraint-pairs

Conversation

@franknoirot
Copy link
Copy Markdown
Contributor

@franknoirot franknoirot commented May 2, 2026

Adds distance constraints for point-line, line-line, point-arc/circle, line-arc/circle, and arc/circle pairs by lowering them into supported solver constraints with hidden construction geometry where needed.

Also preserves labelPosition across the new lowered distance variants, updates point-and-click distance previews/annotations, and keeps non-parallel line-line point-and-click behavior falling back to angle constraints while KCL distance lowering remains available.

Here is a list of how each lowering works, with some diagrams:

  • point-line: create a hidden support point on the line, make the segment from the point to that support point perpendicular to the line, then constrain that segment length.

  • line-line: force the lines parallel, pick a point on one line, create a hidden support point on the other line, make the connecting segment perpendicular, then constrain its length.

  • point-circular: create a hidden circle centered on the point with radius equal to the requested distance, then make it exterior-tangent to the target arc/circle.

  • line-circular: create a hidden support point on the line at the projection of the circular center, make that support segment perpendicular to the line, then use the point-circular lowering from the support point.

  • circular-circular: create a hidden spacer circle with radius distance / 2, constrain its center onto the line between the two circular centers, then make it exterior-tangent to both target circular geometries.

Untitled

Demo

Screenshare.-.2026-05-02.1_04_20.AM-compressed.mp4

@franknoirot franknoirot requested review from a team as code owners May 2, 2026 05:01
@vercel
Copy link
Copy Markdown

vercel Bot commented May 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
modeling-app Ready Ready Preview, Comment May 11, 2026 7:56pm

Request Review

)));
}

let t = ((point[0] - line_start[0]) * dx + (point[1] - line_start[1]) * dy) / len_sq;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand what this math is actually doing, some comments here would help contextualize this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah makes sense. This one is getting an initial solver point for the hidden supporting geometry for a point-line distance constraint, the example I mention in your next comment. I've added some comments here and elsewhere where "datum" or support geometry is added and calculations like this are made.

})
}

fn circular_circular_support_initial_position(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the point of all this "initial" stuff? Is it so that when users hit the distance constraint, the constraint is initially set to the current distance between the two geometry, and the user can edit it later?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nah all these new distance variants rely on hidden constraint inputs: like the point-line distance uses a hidden line coincident with the line and the point for example, and constrains it to be perpendicular to the target line. These helpers provide initial values to those hidden "lowering" geometries to ensure they're solved in the expected orientation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The point-line lowering for example, is here https://github.com/KittyCAD/modeling-app/tree/franknoirot/adhoc/distance-constraint-pairs/rust/kcl-lib/src/execution/exec_ast.rs#L3620-L3633, I've added comments to each of them to describe the support geometry they use.

Comment thread rust/kcl-lib/src/std/constraints.rs Outdated
| (UnsolvedSegmentKind::Circle { .. }, UnsolvedSegmentKind::Point { .. }) => {
(unsolved1, unsolved0)
}
_ => unreachable!(),
Copy link
Copy Markdown
Contributor

@adamchalmers adamchalmers May 5, 2026

Choose a reason for hiding this comment

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

Please don't put unreachable!() in, it leads to panics which are hard to figure out later in production. If you really, really have to panic, please put a unique error message. But instead it's better to return a proper KclError, or structure the match so that this error state is impossible.

Same for the unreachable!()s below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yup apologies, I've correct it here and added a note to the Rust AGENTS.md if that's cool with you.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 5, 2026

Merging this PR will not alter performance

✅ 117 untouched benchmarks
⏩ 150 skipped benchmarks1


Comparing franknoirot/adhoc/distance-constraint-pairs (5ceab58) with main (b5c3605)2

Open in CodSpeed

Footnotes

  1. 150 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (796d17c) during the generation of this report, so b5c3605 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@franknoirot franknoirot merged commit 9a27a20 into main May 11, 2026
77 checks passed
@franknoirot franknoirot deleted the franknoirot/adhoc/distance-constraint-pairs branch May 11, 2026 20:38
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