PropertyExpressionEngine - Issue in buildGraph

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
acpopescu
Posts: 16
Joined: Thu Jan 19, 2023 11:49 pm
Contact:

PropertyExpressionEngine - Issue in buildGraph

Post by acpopescu »

Hi!

EDIT: found the other existing issue!: https://github.com/FreeCAD/FreeCAD/issues/7489
POSSIBLY related - https://github.com/FreeCAD/FreeCAD/issues/7589, https://github.com/FreeCAD/FreeCAD/issues/7390

I had an issue where a constraint's value would not update after setting it to an expression. After investigating, the issue was in PropertyExpressionEngine::buildGraph.

The DiGraph uses a node count from 0 to revNodes.size()-1, and the edges are from 0 to nodes.size()-1

revNodes has sometimes fewer items than nodes because the dependencies are _not_ added in the revNodes dictionary by buildGraphStructures.

I have a change that fixes the issue, you can check this here - https://github.com/acpopescu/FreeCAD/co ... b1975fe2c1

I can clean it up and do a PR - let me know.
Last edited by acpopescu on Sun Jan 29, 2023 2:32 am, edited 2 times in total.
acpopescu
Posts: 16
Joined: Thu Jan 19, 2023 11:49 pm
Contact:

Re: PropertyExpressionEngine - Issue in buildGraph

Post by acpopescu »

It looks like the change has some side effects in my assembly...

EDIT: The side effect looks to be because of improved precision. Due to the way double precision works, I need to offset .001 mm. Also, we don't have a pure 6mm in the constraint below, but 5.999999999999993 for AxleMountThickness


Issue:

A pad on a sketch, with a placement constraint something like "-15mm - <<Ref_POVHatMountsTOP>>.Constraints.AxleMountThickness" will cause an invalid quad to show
pic_issue.jpg
pic_issue.jpg (176.15 KiB) Viewed 681 times


If I do "-15.0001mm - <<Ref_POVHatMountsTOP>>.Constraints.AxleMountThickness " it will work:
pic_issue_2.jpg
pic_issue_2.jpg (173.75 KiB) Viewed 681 times
Any other formula referencing the local sketch ("-Placement.base.z + 14" ) will be fine.
Ref_POVHatMountsTOP is in another body, same part and document.

I suspect this is a side effect when dealing with precision issues. "<<Ref_POVHatMountsTOP>>.Constraints.AxleMountThickness" should be exactly on the tip of the curvature - see
exact.jpg
exact.jpg (47.86 KiB) Viewed 681 times
Last edited by acpopescu on Sun Jan 29, 2023 3:04 am, edited 1 time in total.
acpopescu
Posts: 16
Joined: Thu Jan 19, 2023 11:49 pm
Contact:

Re: PropertyExpressionEngine - Issue in buildGraph

Post by acpopescu »

Trying with a smaller value yields the start of some artefacts, definitely a precision issue; probably stemming from how the property is being updated after the fix.
.0000001 :
accuerror.jpeg
accuerror.jpeg (136.03 KiB) Viewed 625 times
With -0.001 (14.999):
14.9999.jpg
14.9999.jpg (160.55 KiB) Viewed 625 times
acpopescu
Posts: 16
Joined: Thu Jan 19, 2023 11:49 pm
Contact:

Re: PropertyExpressionEngine - Issue in buildGraph

Post by acpopescu »

Ok, so the actual property isn't exactly 21mm. Python console expands it to:

Code: Select all

>>> App.ActiveDocument.Sketch081.Placement.Base.y
20.999999999999986
And the result for the Axle MountThickness is

Code: Select all

>>> ActiveSketch.Constraints[19].Name
'AxleMountThickness'
>>> ActiveSketch.Constraints[19].Value
5.999999999999993
In the end the behavior that I'm seeing looks correct, if not it's higher precision
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: PropertyExpressionEngine - Issue in buildGraph

Post by onekk »

acpopescu wrote: Sun Jan 29, 2023 3:02 am ...
It is normal "IEEE floating point approximation" for short a decimal number could not have a precise binary representation.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply