cyberbotics / webots

Webots Robot Simulator
https://cyberbotics.com
Apache License 2.0
3.11k stars 1.65k forks source link

Precision Issue When Moving/Translating Nodes with Handles #262

Closed DavidMansolino closed 5 years ago

DavidMansolino commented 5 years ago

Describe the Bug When using the rotation and translation handles the field value is then not correctly rounded when saved, e.g.:

  translation 0 0.05 -0.18999999999999972

Steps to Reproduce

  1. Open the khepera3_gripper.wbt world (in pause mode).
  2. translate the CYLINDER_LOAD Solid with the handle.
  3. Save the world.
  4. Check the value in the world file.

Expected behavior The value should be rounded when saved, exactly like what is done if you directly enter it in the scene-tree.

System

DavidMansolino commented 5 years ago

The problem is actually not only with the handles. But for example with this world:

#VRML_SIM R2019a utf8
WorldInfo {
}
Viewpoint {
  orientation 0.010609946051950602 0.9878633572769442 0.15496262902486857 3.3907274957032123
  position -0.3992181716610082 0.40240941607368513 -1.2618839874129562
}
TexturedBackground {
}
TexturedBackgroundLight {
}
Solid {
  boundingObject Box {
    size 0.1 0.1 0.1
  }
}

Changing one of the dimensions of the box to 0.3 (either with the spinboxes or whit the mouse wheel), once saved gives:

#VRML_SIM R2019a utf8
WorldInfo {
}
Viewpoint {
  orientation 0.010609946051950602 0.9878633572769442 0.15496262902486857 3.3907274957032123
  position -0.3992181716610082 0.40240941607368513 -1.2618839874129562
}
TexturedBackground {
}
TexturedBackgroundLight {
}
Solid {
  boundingObject Box {
    size 0.30000000000000004 0.1 0.1
  }
}
DavidMansolino commented 5 years ago

During the handle translation: https://github.com/omichel/webots/blob/e1040474db48abdd2ba9780a680cc6f45cce861c/src/webots/gui/WbDragTransformEvent.cpp#L213

With WbPrecision::FLOAT_MAX:

0 0.05 -0.47 + 0 0 0.01 = 0 0.05 -0.46

With WbPrecision::DOUBLE_MAX:

0 0.05 -0.47 + 0 0 0.01 = 0 0.05 -0.45999999999999996

DavidMansolino commented 5 years ago

Fixed in#266