[ Fixed ] Annotation scale widget: problem with display of certain scales

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

[ Fixed ] Annotation scale widget: problem with display of certain scales

Post by Roy_043 »

The Annotation scale widget does not display the 5:1, 10:1 and 20:1 scales properly after a restart.

Test:
  1. Startup WB is Draft.
  2. Change the scale in the Annotation scale widget to "20:1"
  3. Restart FC.
  4. The scale is displayed as "20.0".
The problem is related to floating point accuracy and the as_integer_ratio method used in the scale_to_label function.
https://github.com/FreeCAD/FreeCAD/blob ... ar.py#L102

Code: Select all

>>> 0.2.as_integer_ratio()
(3602879701896397, 18014398509481984)
Maybe the function should look like this:

Code: Select all

def scale_to_label(scale):
    """
    transform a float number into a 1:X or X:1 scale and return it as label
    """

    f = round(scale, 2)
    if f == 1.0:
        return "1:1"
    elif f > 1.0:
        f = f.as_integer_ratio()
        if f[1] == 1:
            return str(f[0]) + ":1"
        else:
            return str(scale)
    else:
        f = 1/scale
        f = round(f, 2)
        f = f.as_integer_ratio()
        if f[1] == 1:
            return "1:" + str(f[0])
        else:
            return str(scale)

Code: Select all

OS: Windows 8.1 (6.3)
Word size of FreeCAD: 64-bit
Version: 0.20.25220 (Git)
Build type: Release
Branch: master
Hash: 46282db7c8c65d1205a4cd03499d4beadb1573c6
Python version: 3.8.10
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.2
Locale: Dutch/Netherlands (nl_NL)
Last edited by Roy_043 on Mon Sep 20, 2021 7:00 pm, edited 1 time in total.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ Fixed ] Annotation scale widget: problem with display of certain scales

Post by Roy_043 »

Merged.
User avatar
thomas-neemann
Veteran
Posts: 11800
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: [ Fixed ] Annotation scale widget: problem with display of certain scales

Post by thomas-neemann »

Roy_043 wrote: Mon Sep 20, 2021 7:01 pmMerged.
thank you for your effort to correct all these things.
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: [ Fixed ] Annotation scale widget: problem with display of certain scales

Post by Roy_043 »

Thanks, but this is really minor stuff.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [ Fixed ] Annotation scale widget: problem with display of certain scales

Post by carlopav »

Roy_043 wrote: Wed Sep 22, 2021 7:31 am Thanks, but this is really minor stuff.
It's not! There is a huge space for improvements in every single aspect of Draft, and this little fixes are very important for the overall perception of the quality of the code and of the software as a whole.

So thanks for the time you dedicate to the project, and sorry for the bugs i'm spreading around :oops:
follow my experiments on BIM modelling for architecture design
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ Fixed ] Annotation scale widget: problem with display of certain scales

Post by paullee »

Indeed, fixing bug is important ! Thanks everyone here ! :)
Post Reply