Sketcher: Harden against flip with signed constraints#26518
Sketcher: Harden against flip with signed constraints#26518chennes merged 3 commits intoFreeCAD:mainfrom
Conversation
be9a4ab to
8757b68
Compare
18378b1 to
f1269e8
Compare
2a482d4 to
29ee990
Compare
|
What about parallel lines? I noticed that the offset is often broken in the sketch. Even for simple rectangles, I'm not talking about polygons. |
do you mean like this? To my understanding, that should result in a point-line distance which should be covered by this PR. |
But when setting the size, you can specify two vertices, you can specify a vertex and a straight line, or you can specify two straight lines. Is it always considered as a constraint between a point and a straight line? |
|
A rectangle with dimensions looks like this when horizontal and vertical constraints are removed and vertices moved around:
So a normal rectangle has point-point constraints. @theo-vt I think there's a case here we might be able to handle. Another option would be to change so rectangles gets line-point constraints by default. |
|
the current offset tool https://wiki .freecad.org/Sketcher_Offset Additionally, it draws auxiliary geometry — perpendicular segments (if you specify to create parametricity by setting the offset distance by size). In fact, you can force the distance from a point to a straight line to be tracked there. It's worth checking out |
|
Yes, the geometries created with this tool already have point-line constraints which are covered :) |
Which does not prevent you from flipping in most cases. |
Yes, but that's what I think this PR takes care of |
This is handled in #25645 the constraints are iteratively reduced to simpler constraints and it tries to use as many ConstraintDifference (signed) as possible Currently this only works for axis aligned lines, but I want to extend it in 2 ways
But I am marking it as draft because after the discussion in the cad-topic, I think this algorithm should be moved to App level rather than solver level to do smarter things, handle external geometries and eventually include other algorithms |
a7bb8d1 to
de5b05c
Compare
|
Here are builds if people want to test! |
I tested it and didn't see any difference trim.FDA88948-1A6C-4562-B39E-5D09361AD467.MOV |
|
Discord suggested what's the matter, but then you need to redo the Offset tool itself. 2026-03-03.15-23-14.mp4 |
|
These issues are because point-to-point constraints are created and not the constraints modified in this PR. I think we should change how the constraints are set up for rectangles, offsets etc, but that would be best in a follow up PR |
Sketcher: Make circle-circle distance signed Sketcher: Make circle-line distance signed Apply review suggestions
d6e429f to
7771ecf
Compare
for more information, see https://pre-commit.ci
maxwxyz
left a comment
There was a problem hiding this comment.
I have played around a bit and did not find any issues
|
I've tried testing it with the first example shown here, and it still flipped, but maybe I used the wrong constraints? |
|
This is expected! Flipping is pretty vaporous problem so it can't be solved with a single pr, the example flip still does flip and I have future plans to solve it somewhat! |
|
@theo-vt this is breaking two of my integration test files. Can you look at these two cases? Recompute fails: Large volume change: |
this PR fixes flipping when constraints are based on more than two points (three points or point+line) |


This PR adds a concept of orientation to
to make sketches harder to flip
The orientation is saved to file and handled by the App::Constraint rather than the planegcs::Constraint to better capture design intent (it allows to react to external geometry movement, which the solver is blind to)
The orientation is computed on sketch restore so older files are upgraded seamlessly
The constraints can still be made driven or deactivated and their orientation is recomputed when made driving/reactivated so the user can manually flip them
Point-Line distance
This PR makes point-line constraints signed which prevents flips when constraints values change drastically or a reference geometry moves around
Before:
Screencast.From.2025-12-16.15-49-43.mp4
After:
Screencast.From.2025-12-16.15-50-50.mp4
Circle-Circle distance
This PR adds a concept of relative size for circle-circle distance which allows to keep an inner circle and an outer circle when one of the circles is completely within the other
Before:
Screencast.From.2025-12-18.23-16-07.mp4
After:
Screencast.From.2025-12-18.23-15-23.mp4
Circle-Line distance
This PR adds an orientation concept to circle-line distances. 4 possible orientations are established with 2 flags: ccw and internal.
A ccw orientation means that the sequence [line.pt1, line.pt2, circle.center] is and should remain ccw, this is the same as the point-line distance orientation from https://github.com/FreeCAD/FreeCAD/pull/26228/changes
An internal orientation means that the line is and should remain closer to the center then the radius of the circle
Before:
Screencast.From.2025-12-29.10-04-07.mp4
After:
Screencast.From.2025-12-29.10-05-23.mp4
Issues
Fix: #26634
Fix #17579