mozman / ezdxf

Python interface to DXF
https://ezdxf.mozman.at
MIT License
906 stars 189 forks source link

DIMENSION decimal rounding problem #566

Closed mozman closed 2 years ago

mozman commented 2 years ago

Discussed in https://github.com/mozman/ezdxf/discussions/565

Originally posted by **k3rn3l3rr0r** October 25, 2021 I'm experimenting with the native Dimension entities. (Thanks for that functionality!) I've noticed a problem with how the rounding/formatting of decimal values works. `override={}` ![image](https://user-images.githubusercontent.com/3663357/138614321-fb0960de-584c-4d06-83e1-debae9a705a7.png) `override={'dimdec': 1}` ![image](https://user-images.githubusercontent.com/3663357/138614342-0e5eb75d-0063-4ed7-9745-ffdae6d0247f.png) `override={'dimdec': 0}` ![image](https://user-images.githubusercontent.com/3663357/138614352-553d7314-eb26-4019-84d0-3c5343c21f46.png) Notice the missing trailing 0 in "1050" in the last example. Could this be caused through some misconfiguration on my side?
mozman commented 2 years ago

This is already fixed in issue #557 and will be included in the next release v0.17.1.

k3rn3l3rr0r commented 2 years ago

Thanks a lot Manfred. I really appreciate it.

mozman commented 2 years ago

This is really strange: I received 2 bug reports on a long existing error within a very short time - unfortunately in the wrong order. Your bug report would have saved me a lot of time.

k3rn3l3rr0r commented 2 years ago

For your info - I've just tried it out with code from the current master branch and the result is the same as previously reported (still with trimmed 0).

mozman commented 2 years ago

Can't reproduce this issue, this script creates the expected measurement text and does not remove the trailing "0":

from pathlib import Path
import ezdxf

DIR = Path("~/Desktop/Outbox").expanduser()
doc = ezdxf.new(setup=True)
msp = doc.modelspace()

def add_dims(x1, x2):
    msp.add_aligned_dim((x1, 0), (x2, 0), 2).render()  # default dimdec=2
    msp.add_aligned_dim((x1, 0), (x2, 0), 4, override={"dimdec": 1}).render()
    msp.add_aligned_dim((x1, 0), (x2, 0), 6, override={"dimdec": 0}).render()

add_dims(0, 9.55555)
add_dims(10, 20.5)
doc.saveas(DIR / "issue566.dxf")

image

k3rn3l3rr0r commented 2 years ago

This is interesting, I just copy&pasted the provided script and I get different result:

image

I'm on Fedora 32 (5.10.19-100.fc32.x86_64) and opening the file in BricsCAD v18.

mozman commented 2 years ago

Check if you really pulled from "master".

mozman commented 2 years ago

Please exec following lines:

"." in str(3.14)  # should be True
print(ord("."))  # should be 46
k3rn3l3rr0r commented 2 years ago

I've now double-checked I have the code from master. The used version was master@3a649b9 from today's morning.

Now on current master@67bdec0 the behaviour is the same.

Here the test exec:

Python 3.8.7 (default, Jan 20 2021, 00:00:00) 
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> "." in str(3.14)
True
>>> print(ord("."))
46
mozman commented 2 years ago

Running the code on WSL2 (Windows Subsystem for Linux) creates the same correct result:

image

Maybe remove ezdxf complete and reinstall it or run it in a virtual environment to check how a fresh install behaves.

k3rn3l3rr0r commented 2 years ago

Finally, I'm getting the same result as you! Sorry for this, I only removed and installed the package before, now after installing it inside of a fresh venv both my app and your test example script are producing correct output.