webots icon indicating copy to clipboard operation
webots copied to clipboard

Some real values get rounded when entered from the GUI

Open ShuffleWire opened this issue 3 years ago • 1 comments
trafficstars

Describe the Bug The value entered from the GUI got altered (at least) when saving.

Steps to Reproduce

  1. Open an empty world
  2. Add a Robot, and a connector
  3. Set the axisTolerance to pi by setting 3.141592653589793 (this value is actually the closest one to PI, and "==" give true between those two values)
  4. Value get rounded on the HMI, this is fine, it does it elsewhere without causing trouble
  5. Save the world
  6. Open the file, see that axisTolerance 3.14159
  7. Change in this file axisTolerance 3.14159 to axisTolerance 3.141592653589793
  8. Save, reload world, move camera, save, reopen file
  9. See that axisTolerance 3.141592653589793

It work as well with all "Float" values, like rotationStep and friend, and I think many more

My testing show that, if I do :

oid WbConnector::updateAxisTolerance() { printf("%s\n", mAxisTolerance->toString().toStdString().c_str()); if (mAxisTolerance->clip(0.0, M_PI)) parsingWarn(tr("'axisTolerance' must be between 0 and pi.")); }

The print immediately show that the value is 3.14159 even if I entered 3.141592653589793 So maybe Qt is doing some weird rounding ? Note that this behavior is not the same with SFRotation for instance. If I set the "angle" value of the "rotation" of the "Viewpoint", the full 3.141592653589793 is written in the wrl file (and that is the correct behavior)

Expected behavior The value axisTolerance should keep his value with full precision from the start.

System

  • Operating System: Debian 11
  • Webot develop @ 0a240a599de5c8973fbbdf2214d803578ba5d2bd

Additional context https://github.com/cyberbotics/webots/discussions/4045 https://github.com/cyberbotics/webots/discussions/4328

ShuffleWire avatar Mar 08 '22 09:03 ShuffleWire

Actually it is not Qt that rounds the values but it is explicitly done in Webots code for double, vector2 and vector3 fields in the Field Editor where GUI_MEDIUM precision is used (instead of DOUBLE_MAX) https://github.com/cyberbotics/webots/blob/ab93ceff453a2c27e7d4eced3203a04bddee5e93/src/webots/scene_tree/WbDoubleEditor.cpp#L83:L84

This was introduced to fix an issue with wrong rounding when saving to file, where when setting for example the Viewpoint.far value to 0.2 from the scene tree the resulting value written in the WBT file was 0.19999999999999998 (see issue #262).

stefaniapedrazzi avatar Jun 02 '22 10:06 stefaniapedrazzi