I'm a fairly new user of FreeCAD, but am interested in implementing a change to make point-to-line (P2L) constraints preserve the orientation/sign of the distance. The fact that it doesn't has already caused me some annoyance (and an incorrect cut on a CNC router) and it looks like it's been discussed
years ago and at least some times
more recently, as well as having this behavior called out in some tutorials on the sketcher that I've read - along with the workaround of adding 180 degree angle constraints (but which feels cumbersome to have to use for a very common construction). It looks like it's a trivial change to the back-end of the sketcher, so I think it would be worthwhile unless more experienced people in this community know a good reason to preserve the existing behavior.
As far as I can tell, making the P2L constraint signed just requires remove the call to
std::abs in
double ConstraintP2LDistance::error() and removing the lines
from
double ConstraintP2LDistance::grad(double*) - at least, after making those changes and recompiling, the sketcher had the expected behavior that the sign of the constraint controlled which side of the line the point would be constrained on. This is basically all the technical feature - I think the main question for me is how to intuitively let the user take advantage of this.
I would think that a reasonable user interface for this would be
- Add a property to P2L constraints signifying whether it is signed/oriented - modify error/grad calculations as above when this is true.
- Upon creating (or adding signed behavior to) a P2L constraint, choose orientations/signs such that positive distances correspond to the side of the line that the point is already on. Allow the user some way in the interface to flip the orientations of a constraint if they prefer the opposite convention.
Some of the changes would also potentially apply to tangencies between lines and circles/arcs, which are internally represented in the same way. I believe that the P2L constraint is the only one which artificially has an absolute value added - and I believe that the horizontal/vertical distance already work similarly to this (but I haven't fully traced through how those work). Backwards compatibility should be reasonably easy to maintain by just disabling signed behavior for older files - but it would need to save new properties, so would probably break forwards compatibility.
Is this a reasonable change to make? Are there any things to consider further about it?