Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by Roy_043 »

Maybe this image helps:
Two lines created from the center of a circle with their end snapped to the edge of the circle with Near snap:
Red circle: R = 1 mm
White line: L = 0.999990 mm
Black line: L = 0.996803 mm
Attachments
circle-near-snap.png
circle-near-snap.png (4.84 KiB) Viewed 1165 times
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by yorik »

Hmm I see... The problem is indeed here:
https://github.com/FreeCAD/FreeCAD/blob ... r.py#L1051
The near point is actually the point returned by the 3D view...indeed we should project it onto the edge.
Basically I think get the snapped subelement like here:
https://github.com/FreeCAD/FreeCAD/blob ... er.py#L355
then project onto it.
I'll try to do that tomorrow, but if anyone feels like trying before that, go for it ;)
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by yorik »

Hmm the case is more complex than I thought... Projecting onto the shape still gives a small offset
User avatar
NewJoker
Veteran
Posts: 3018
Joined: Sun Oct 11, 2020 7:49 pm

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by NewJoker »

yorik wrote: Tue Jun 21, 2022 12:23 pm Hmm the case is more complex than I thought... Projecting onto the shape still gives a small offset
If accurate snap near can't be realized directly for curves, maybe this tool could automatically extend the line being snapped to a curve and trim it. Of course, this would have to be done internally, showing just the final result. I don't know if it makes sense in terms of coding, it's just a loose idea.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by Roy_043 »

Here is my solution. It still needs some work, but AFAICT the results are accurate (of course the usual floating point tolerances apply). Near snap should work for edges and faces, so please test with both.

Some other things that I have changed:
  • To snap to a Draft_Point, Draft_Snap_Endpoint has to be used instead of Draft_Snap_Near. This was done to make things compatible with snapping to points in a point cloud.
  • The snapToPerpendicular function was simplified and should now work for all edges, but is still limited to finding only one point per edge.
  • There was a strange behavior if the "Always snap (disable snap mod)" preference was set to off. Near snap would work without the need to press the Ctrl key. I have removed that (to simplify the code). I do not know if many users use Ctrl+Snap, and if some of them rely on this functionality in their workflow, but my guess is that there are very few.
There are some sections in the code I do not fully understand, some seem to be obsolete. I'll ask some questions later.

Instructions:
  1. Look for /Mod/Draft/draftguitools/gui_snapper.py in your FreeCAD installation folder.
  2. Rename that file.
  3. Place the attached file in the same folder.
  4. Restart FreeCAD.
Attachments
gui_snapper.py
(72.42 KiB) Downloaded 17 times
Last edited by Roy_043 on Sat Jun 25, 2022 9:48 am, edited 2 times in total.
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by thomas-neemann »

Roy_043 wrote: Sat Jun 25, 2022 9:40 am ...
that sounds good. Many Thanks
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by Roy_043 »

... Here are the questions I have:

1.
The Snapper has an active property. But AFAICT it is always set to True. What is its purpose?
https://github.com/FreeCAD/FreeCAD/blob ... er.py#L112

2.
What is the purpose of oldActive? When does the code linked to below run?
https://github.com/FreeCAD/FreeCAD/blob ... #L277-L283
https://github.com/FreeCAD/FreeCAD/blob ... #L505-L509

3.
Which objects are targeted here? It must be objects without faces, edges and vertexes that can be selected in the 3D view.
https://github.com/FreeCAD/FreeCAD/blob ... #L441-L446
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by yorik »

Roy_043 wrote: Thu Jun 30, 2022 11:16 am The Snapper has an active property. But AFAICT it is always set to True. What is its purpose?
This "active/inactive" mode was when Draft was always snapping,OR you had to press Ctrl to enable snapping. I don't think this is used a lot, though...
Roy_043 wrote: Thu Jun 30, 2022 11:16 am What is the purpose of oldActive? When does the code linked to below run?
IIRC there were some modes that were able to override the active state. Therefore it had to be restored afterwards
Roy_043 wrote: Thu Jun 30, 2022 11:16 am Which objects are targeted here? It must be objects without faces, edges and vertexes that can be selected in the 3D view.
IIRC again, there were objects with their coin nodes not properly implemented, for which the component string was blank
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by Roy_043 »

Thanks for your answers. It seems better to leave those confusing bits in then.

https://github.com/FreeCAD/FreeCAD/pull/7132
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves

Post by Roy_043 »

Roy_043 wrote: Thu Jun 30, 2022 11:16 am 2.
What is the purpose of oldActive? When does the code linked to below run?
https://github.com/FreeCAD/FreeCAD/blob ... #L277-L283
https://github.com/FreeCAD/FreeCAD/blob ... #L505-L509
Upon retesting I see that this code must be removed. In some cases it substitutes the projected, accurate, near point. We obviously need to avoid that. I'll update my PR.
Post Reply