Page 1 of 2

Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 3:52 am
by Bei3lay
Hello. I've made some cosmetic changes to the way constraint icons in the sketcher merge. When icons are close to each other, they merge into a single icon. The maximum distance between icons for them to merge depends on the scale factor, which changes with zoom. The initial formula was

Code: Select all

float maxDistSquared = pow(0.05 * getScaleFactor(), 2);
but with this formula icons can almost lie on top of each other and still be too far to merge.
freecad-merge-constraints-1.gif
freecad-merge-constraints-1.gif (671.26 KiB) Viewed 8942 times
To determine the actual formula I tried to determine visually at which distance they must merge. I got a set of squared distances that looked good to me and the corresponding scale factors. By plotting them in the log-log, the relationship was very close to the linear
distsqr-vs-scalefactor1.png
distsqr-vs-scalefactor1.png (23.67 KiB) Viewed 8942 times
I approximated the line as going through the origin with slope 2. I could have taken the actual formula of the line, but there is no point since my measurements weren't exact. The formula is then easy to find

Code: Select all

log(maxDistSquared) = 2*log(scaleFactor)
maxDistSquared = scaleFactor^2
It turned out that the initial formula was structurally very close to the one I got. Resulting behavior
freecad-merge-constraints-2.gif
freecad-merge-constraints-2.gif (488.17 KiB) Viewed 8942 times
Notice the jittering. It is described latter.

After fixing it, I found another problem. Even if the constraints are located exactly at the same point, if I increase zoom enough, their icons separate. The reason for this was related to the Z coordinate of icons. For some reason icons can have either z=0.009 or z=0.018. Icon coordinates are in sketch coordinate system, not global. For two icons i and j I got positions and squared distance between them

Code: Select all

i.pos(-20.000000,20.000000,0.009000),j.pos(-20.000000,20.000000,0.018000),distsquared(0.000081)
To fix it, I've decided to ignore Z coordinates when calculating the distance between icons.

Now to the jittering problem. It happens when icons are merged and I move one of the constraints. The reason is that one of the constraint icons in Coin gets reused as a merged icon. Its image is changed, but position stays the same. So, merged icon is placed at the same place as one of the original icons. First, average position of icons is calculated. The icon closest to the average position gets chosen. As you move the constraint, average position changes and, which icon is closest to the average position, also might change. The jitter is the result of this change, it switches from being in the position of one icon to the position of the other. The simplest solution is to take the first icon and use its position for the position of the merged icon. It would be more complicated to fix it by using any other solution, e.g. creating separate icon for the merged constraints or change position of the chosen icon to be the actual average position. The result looks nicer then the original.
freecad-merge-constraints-3.gif
freecad-merge-constraints-3.gif (490.56 KiB) Viewed 8942 times

Re: [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 6:37 am
by chrisb
Good to see another developer!
Perhaps this solves an issue, of which I'm not sure if it exists on MacOS only - or while working on it you may have look?: When two constraints are placed at he "same" position, none of them is selectable with the mouse.
I attach such a file, I cannot select point-on-object nor the orthogonal constraint.

OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22670 (Git)
Build type: Release
Branch: master
Hash: 12155f4aab09047c5697db0c1b3cf93b02edda03
Python version: 3.8.6
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)

Re: [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 2:56 pm
by Bei3lay
chrisb wrote: Thu Oct 15, 2020 6:37 am Good to see another developer!
Perhaps this solves an issue, of which I'm not sure if it exists on MacOS only - or while working on it you may have look?: When two constraints are placed at he "same" position, none of them is selectable with the mouse.
I attach such a file, I cannot select point-on-object nor the orthogonal constraint.

OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22670 (Git)
Build type: Release
Branch: master
Hash: 12155f4aab09047c5697db0c1b3cf93b02edda03
Python version: 3.8.6
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)
I don't have a problem with this particular file. But this problem exists if sketch is not in XY plane. I think the projection is wrong but I have not figured out yet how to fix it. Since this sketch is in XY plane, its something different. I don't know why there would be an issue on MacOS. Maybe cursor coordinates are different. They are relevant when determining which of the constraints to select.

Re: Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 3:43 pm
by Kunda1
Very cool!
BTW, what commit is associate with this PR?

Re: Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 3:53 pm
by Bei3lay
Kunda1 wrote: Thu Oct 15, 2020 3:43 pm Very cool!
BTW, what commit is associate with this PR?
26cd23cb0bd26a5c79c2307dce42823e97042d3f

Re: Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 3:58 pm
by chrisb
Perhaps the distance between two constraint icons should always be bigger than PickRadius?

Re: Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 4:08 pm
by Bei3lay
chrisb wrote: Thu Oct 15, 2020 3:58 pm Perhaps the distance between two constraint icons should always be bigger than PickRadius?
Coin does the picking and I don't think there is a pick radius with images. I believe it only uses radius when picking points and edges. With everything else, it just chooses the first element intersected by a ray coming from the camera at cursor position.

Re: Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 4:09 pm
by chrisb
Bei3lay wrote: Thu Oct 15, 2020 4:08 pm Coin does the picking and I don't think there is a pick radius with images. I believe it only uses radius when picking points and edges. With everything else, it just chooses the first element intersected by a ray coming from the camera at cursor position.
Thanks for the information anyway!

Re: Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 4:20 pm
by Kunda1
Bei3lay wrote: Thu Oct 15, 2020 3:53 pm
Kunda1 wrote: Thu Oct 15, 2020 3:43 pm Very cool!
BTW, what commit is associate with this PR?
26cd23cb0bd26a5c79c2307dce42823e97042d3f
FYI, You can put in between commit tags
git commit 26cd23cb0bd

Re: Merged [PR #3963] Sketcher: Changes to drawing of constraint icons.

Posted: Thu Oct 15, 2020 4:36 pm
by Bei3lay
chrisb wrote: Thu Oct 15, 2020 4:09 pm
Bei3lay wrote: Thu Oct 15, 2020 4:08 pm Coin does the picking and I don't think there is a pick radius with images. I believe it only uses radius when picking points and edges. With everything else, it just chooses the first element intersected by a ray coming from the camera at cursor position.
Thanks for the information anyway!
Also, when constraint icons are merged into a single icon, Coin is only responsible for selecting the merged icon, it can't select individual constraints. It is done separately by projecting icon onto the screen and using cursor coordinates to determine to which constraint it points. There are bounding boxes saved for each constraint image in the icon. If cursor coordinates and projection to the screen for some reason use different coordinate systems in MacOS, then this problem can occur. But I don't see why would it be true and I don't have any other possible explanation of why it works differently in MacOS.