summaryrefslogtreecommitdiff
path: root/basegfx/source/numeric
diff options
context:
space:
mode:
Diffstat (limited to 'basegfx/source/numeric')
-rw-r--r--basegfx/source/numeric/ftools.cxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/basegfx/source/numeric/ftools.cxx b/basegfx/source/numeric/ftools.cxx
index 994bd29e30eb..d1eca66ca2fc 100644
--- a/basegfx/source/numeric/ftools.cxx
+++ b/basegfx/source/numeric/ftools.cxx
@@ -45,6 +45,59 @@ namespace basegfx
}
}
+ double snapToZeroRange(double v, double fWidth)
+ {
+ if(fTools::equalZero(fWidth))
+ {
+ // with no range all snaps to range bound
+ return 0.0;
+ }
+ else
+ {
+ if(v < 0.0 || v > fWidth)
+ {
+ double fRetval(fmod(v, fWidth));
+
+ if(fRetval < 0.0)
+ {
+ fRetval += fWidth;
+ }
+
+ return fRetval;
+ }
+ else
+ {
+ return v;
+ }
+ }
+ }
+
+ double snapToRange(double v, double fLow, double fHigh)
+ {
+ if(fTools::equal(fLow, fHigh))
+ {
+ // with no range all snaps to range bound
+ return 0.0;
+ }
+ else
+ {
+ if(fLow > fHigh)
+ {
+ // correct range order. Evtl. assert this (?)
+ std::swap(fLow, fHigh);
+ }
+
+ if(v < fLow || v > fHigh)
+ {
+ return snapToZeroRange(v - fLow, fHigh - fLow) + fLow;
+ }
+ else
+ {
+ return v;
+ }
+ }
+ }
+
double normalizeToRange(double v, const double fRange)
{
if(fTools::lessOrEqual(fRange, 0.0))