Improve slider precision and range clamping, fixes #3206

Add clamping to slider values in both ImGui widgets and mjUI to ensure they remain within the defined min/max ranges, preventing potential floating point inaccuracies from causing values to slightly exceed the bounds.

PiperOrigin-RevId: 902660458
Change-Id: Ia153ae7907f07b890f2b5ac2e3a4be93ecae7bd3
This commit is contained in:
Yuval Tassa
2026-04-20 08:53:28 -07:00
committed by Copybara-Service
parent a8a5afc8dc
commit b2281883dd
3 changed files with 6 additions and 5 deletions
+2 -2
View File
@@ -1192,7 +1192,7 @@ void MakeJointSection(mj::Simulate* sim) {
// set range
if (sim->jnt_range_[i].has_value())
mju::sprintf_arr(defSlider[0].other, "%.4g %.4g",
mju::sprintf_arr(defSlider[0].other, "%.17g %.17g",
sim->jnt_range_[i]->first, sim->jnt_range_[i]->second);
else if (sim->jnt_type_[i]==mjJNT_SLIDE) {
mju::strcpy_arr(defSlider[0].other, "-1 1");
@@ -1251,7 +1251,7 @@ void MakeControlSection(mj::Simulate* sim) {
// set range
if (sim->actuator_ctrlrange_[i].has_value())
mju::sprintf_arr(defSlider[0].other, "%.4g %.4g",
mju::sprintf_arr(defSlider[0].other, "%.17g %.17g",
sim->actuator_ctrlrange_[i]->first, sim->actuator_ctrlrange_[i]->second);
else {
mju::strcpy_arr(defSlider[0].other, "-1 1");