13#ifndef INKSCAPE_HELPER_MATHFNS_H
14#define INKSCAPE_HELPER_MATHFNS_H
31 return std::floor((x - c0) / c1 + 0.5) * c1 + c0;
43 return std::floor((x - c0) / c1) * c1 + c0;
55 return std::ceil((x - c0) / c1) * c1 + c0;
73template <typename T, typename std::enable_if<std::is_integral<T>::value,
bool>::type =
true>
77 return a < 0 ? a + b : a;
81template <typename T, typename std::enable_if<std::is_integral<T>::value,
bool>::type =
true>
88template <typename T, typename std::enable_if<std::is_integral<T>::value,
bool>::type =
true>
101 if (val < lo)
return lo;
102 if (val > hi)
return hi;
Cartesian point / 2D vector and related operations.
Miscellaneous supporting code.
T safeclamp(T val, T lo, T hi)
Just like std::clamp, except it doesn't deliberately crash if lo > hi due to rounding errors,...
int constexpr floorlog2(T x)
Returns floor(log_2(x)), assuming x >= 1.
T constexpr safemod(T a, T b)
Returns a mod b, always in the range 0..b-1, assuming b >= 1.
T constexpr round_down(T a, T b)
Returns a rounded down to the nearest multiple of b, assuming b >= 1.
T constexpr round_up(T a, T b)
Returns a rounded up to the nearest multiple of b, assuming b >= 1.
double round_to_upper_multiple_plus(double x, double const c1, double const c0=0)
double round_to_nearest_multiple_plus(double x, double c1, double c0)
double round_to_lower_multiple_plus(double x, double c1, double c0=0.0)
Helper class to stream background task notifications as a series of messages.