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

Merged, abandoned or rejected pull requests are moved here to clear the main Pull Requests forum.
Bei3lay
Posts: 34
Joined: Wed Aug 28, 2019 6:48 am

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

Post 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 8946 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 8946 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 8946 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 8946 times
Last edited by Bei3lay on Thu Oct 15, 2020 2:57 pm, edited 1 time in total.
chrisb
Veteran
Posts: 53924
Joined: Tue Mar 17, 2015 9:14 am

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

Post 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)
Attachments
nonSelectableConstraints.FCStd
(3.16 KiB) Downloaded 152 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Bei3lay
Posts: 34
Joined: Wed Aug 28, 2019 6:48 am

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

Post 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.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

Very cool!
BTW, what commit is associate with this PR?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Bei3lay
Posts: 34
Joined: Wed Aug 28, 2019 6:48 am

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

Post by Bei3lay »

Kunda1 wrote: Thu Oct 15, 2020 3:43 pm Very cool!
BTW, what commit is associate with this PR?
26cd23cb0bd26a5c79c2307dce42823e97042d3f
chrisb
Veteran
Posts: 53924
Joined: Tue Mar 17, 2015 9:14 am

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

Post by chrisb »

Perhaps the distance between two constraint icons should always be bigger than PickRadius?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Bei3lay
Posts: 34
Joined: Wed Aug 28, 2019 6:48 am

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

Post 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.
chrisb
Veteran
Posts: 53924
Joined: Tue Mar 17, 2015 9:14 am

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

Post 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!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post 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
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Bei3lay
Posts: 34
Joined: Wed Aug 28, 2019 6:48 am

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

Post 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.
Post Reply