Boost logo

Boost :

From: Mark Gilbert (mark.gilbert_at_[hidden])
Date: 2005-06-09 14:23:27

In my own code, I have long used a type similar to boost::interval. In my
class, I find these functions useful:

T center() const { return (low + up) / 2; }
T extent() const { return up - low; }
T clamp(T t) const { return t < low ? low : t > up ? up : t; }
T wrap(T t) const { return fmodpos(t - low, extent()) + low; }
T evaluate(T t) const { return low + t * extent(); }
T normalize(T t) const { return (t - low) / extent(); }

clamp provides a convenient way to limit a value, changing this ugly thing:
double x = max(lower, min(upper, raw_x));
to this:
double x = interval(lower, upper).clamp(raw_x);

evaluate and normalize map the interval to a normalized interval with values
in the range [0,1].

The minor documentation error is at
(, where it
says, ". . . rounding a+b down and c+d up will suffice." Shouldn't that say
"a+c down and b+d up"?

Thanks for the good work on this class,
Mark Gilbert

Boost list run by bdawes at, gregod at, cpdaniel at, john at