Skip to content

Commit 6135506

Browse files
committed
double computation fixup
1 parent 4f07c05 commit 6135506

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

library/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"type": "double",
193193
"default_value": "1.0",
194194
"domain": {
195-
"range": ["-0.01", "5.01"],
195+
"range": ["0.0", "5.0"],
196196
"increment": "0.02"
197197
}
198198
}
@@ -377,7 +377,7 @@
377377
"opacity": {
378378
"type": "double",
379379
"domain": {
380-
"range": ["-0.01", "1.0"],
380+
"range": ["0.0", "1.0"],
381381
"increment": "0.05"
382382
}
383383
},

library/private/options_tools.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "vtkF3DNamedColors.h"
99

1010
#include <vtkMath.h>
11+
#include <vtkMathUtilities.h>
1112
#include <vtkSmartPointer.h>
1213

1314
#include <algorithm>
@@ -908,7 +909,28 @@ void increase(T& val, const f3d::options::domain_range_t<T>& domain, bool up)
908909

909910
newVal += dir * domain.increment;
910911

911-
// TODO this can be incorrect in case of double computation, how to address ?
912+
// Required because of double computation
913+
bool upEqual = vtkMathUtilities::FuzzyCompare(newVal, domain.range[1], T{1e-12});
914+
bool downEqual = vtkMathUtilities::FuzzyCompare(newVal, domain.range[0], T{1e-12});
915+
if ((up && (newVal < domain.range[1] || upEqual)) || (!up && (newVal > domain.range[0] || downEqual)))
916+
{
917+
val = newVal;
918+
}
919+
}
920+
921+
//----------------------------------------------------------------------------
922+
/**
923+
* Templated int specific increase method for provided val and domain.
924+
* Increase up to max or decrease down to min.
925+
*/
926+
template<>
927+
void increase(int& val, const f3d::options::domain_range_t<int>& domain, bool up)
928+
{
929+
char dir = up ? +1 : -1;
930+
int newVal = val;
931+
932+
newVal += dir * domain.increment;
933+
912934
if ((up && newVal <= domain.range[1]) || (!up && newVal >= domain.range[0]))
913935
{
914936
val = newVal;

0 commit comments

Comments
 (0)