summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/source/numeric/ftools.cxx34
1 files changed, 34 insertions, 0 deletions
diff --git a/basegfx/source/numeric/ftools.cxx b/basegfx/source/numeric/ftools.cxx
index a67bc56bd74e..994bd29e30eb 100644
--- a/basegfx/source/numeric/ftools.cxx
+++ b/basegfx/source/numeric/ftools.cxx
@@ -44,6 +44,40 @@ namespace basegfx
}
}
}
+
+ double normalizeToRange(double v, const double fRange)
+ {
+ if(fTools::lessOrEqual(fRange, 0.0))
+ {
+ // with a zero (or less) range, all normalizes to 0.0
+ return 0.0;
+ }
+
+ const bool bNegative(fTools::less(v, 0.0));
+
+ if(bNegative)
+ {
+ if(fTools::moreOrEqual(v, -fRange))
+ {
+ // in range [-fRange, 0.0[, shift one step
+ return v + fRange;
+ }
+
+ // re-calculate
+ return v - (floor(v/fRange)*fRange);
+ }
+ else
+ {
+ if(fTools::less(v, fRange))
+ {
+ // already in range [0.0, fRange[, nothing to do
+ return v;
+ }
+
+ // re-calculate
+ return v - (floor(v/fRange)*fRange);
+ }
+ }
} // end of namespace basegfx
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */