|
Motive Animation System
An open source project by
FPL.
|
Represent an interval on a number line. More...
#include <range.h>
Represent an interval on a number line.
Classes | |
| struct | RangeArray |
| struct | TArray |
Public Member Functions | |
| RangeT (const T point) | |
| RangeT (const T start, const T end) | |
| bool | Valid () const |
| A range is valid if it contains at least one number. | |
| T | Middle () const |
| T | Length () const |
| T | Clamp (const T x) const |
| T | ClampAfterStart (const T x) const |
| T | ClampBeforeEnd (const T x) const |
| T | DistanceFrom (const T x) const |
| T | Lerp (const float percent) const |
| float | Percent (const T x) const |
| T | PercentClamped (const T x) const |
| T | Normalize (T x) const |
| T | NormalizeCloseValue (T x) const |
| T | NormalizeWildValue (T x) const |
| T | ModularAdjustment (T x) const |
| float | ModDiffClose (T a, T b) const |
| float | ModDiffFar (T a, T b) const |
| Return the farthest difference from 'a' to 'b' under modular arithmetic. | |
| float | ModDiffPositive (T a, T b) const |
| float | ModDiffNegative (T a, T b) const |
| float | ModDiff (T a, T b, ModularDirection direction) const |
| bool | Contains (const T x) const |
Return true if x is in [start_, end_], i.e. the inclusive range. | |
| bool | ContainsExcludingStart (const T x) const |
| bool | ContainsExcludingEnd (const T x) const |
| bool | StrictlyContains (const T x) const |
Return true if x is in (start_, end_), i.e. the exclusive range. | |
| bool | ContainsWithTolerance (const T x, const T percent) const |
| RangeT | Invert () const |
| RangeT | Lengthen (const float percent) const |
| RangeT | Include (const T x) const |
| bool | operator== (const RangeT &rhs) const |
| Equality is strict. No epsilon checking here. | |
| bool | operator!= (const RangeT &rhs) const |
| RangeT | operator* (const float s) const |
| Scale by multiplying by a scalar. | |
| T | start () const |
| Accessors. | |
| T | end () const |
| void | set_start (const T start) |
| void | set_end (const T end) |
Static Public Member Functions | |
| static RangeT | Intersect (const RangeT &a, const RangeT &b) |
| static RangeT | Union (const RangeT &a, const RangeT &b) |
| Return the smallest range that covers all of 'a' and 'b'. | |
| static size_t | ValuesInRange (const RangeT &range, T epsilon, size_t num_values, T *values) |
| template<size_t kMaxLen> | |
| static void | ValuesInRange (const RangeT &range, T epsilon, TArray< kMaxLen > *values) |
| static size_t | IntersectRanges (const RangeT *a, size_t len_a, const RangeT *b, size_t len_b, RangeT *intersections, RangeT *gaps=nullptr, size_t *len_gaps=nullptr) |
| template<size_t kMaxLen> | |
| static void | IntersectRanges (const RangeArray< kMaxLen > &a, const RangeArray< kMaxLen > &b, RangeArray< kMaxLen *kMaxLen > *intersections, RangeArray< kMaxLen *kMaxLen > *gaps=nullptr) |
| static size_t | IndexOfLongest (const RangeT *ranges, size_t len) |
Return the index of the longest range in ranges. | |
| template<size_t kMaxLen> | |
| static size_t | IndexOfLongest (const RangeArray< kMaxLen > &ranges) |
| static size_t | IndexOfShortest (const RangeT *ranges, size_t len) |
Return the index of the shortest range in ranges. | |
| template<size_t kMaxLen> | |
| static size_t | IndexOfShortest (const RangeArray< kMaxLen > &ranges) |
| static T | ClampToClosest (T x, const RangeT *ranges, size_t len) |
Return the index of the shortest range in ranges. | |
| template<size_t kMaxLen> | |
| static T | ClampToClosest (T x, const RangeArray< kMaxLen > &ranges) |
| template<typename S , typename F > | |
| static RangeT< T > | CoversLambda (const S *array, size_t len, const F &f) |
| static RangeT< T > | Covers (const T *array, size_t len) |
Return the range that covers all values in array. | |
| static RangeT< T > | Full () |
| Returns the complete range. Every T is contained in this range. | |
| static RangeT< T > | Empty () |
| static RangeT< T > | Positive () |
| Returns the range of positive numbers: [0, +infinity]. | |
| static RangeT< T > | Negative () |
| Returns the range of negative numbers.: [-infinity, 0]. | |
|
inline |
Returns x if it is within the range. Otherwise, returns start_ or end_, whichever is closer to x. Behavior is undefined for invalid regions.
|
inline |
Clamp x so it is inside the start bound. Can save cycles if you already know that x is inside the end bound.
|
inline |
Clamp x so it is inside the end bound. Can save cycles if you already know that x is inside the start bound.
|
inline |
Return true if x is in [start_, end_), i.e. the range that includes the start bound but not the end bound.
|
inline |
Return true if x is in (start_, end_], i.e. the range that includes the end bound but not the start bound.
|
inline |
Return true if x is in [start_ - tolerance, end_ + tolerance], where tolerance = Length() * percent.
|
inlinestatic |
Returns the range that covers all values in f(array). f is a lambda to calculate T from S. See Covers() for a simple example. In general, if your S has a function T GetValue(), then your lambda can look something like, const RangeT<T> range = RangeT<T>::CoversLambda( s_array, len, [](const S& s) { return s.GetValue(); });
|
inline |
Returns distance outside of the range. If inside the range, returns 0. Behavior is undefined for invalid regions.
|
inlinestatic |
Returns the most empty range possible. The lower bound is greater than everything, and the upper bound is less than everything. Useful when finding the min/max values of an array of numbers.
|
inline |
Returns the smallest range that contains both x and the range in this.
|
inlinestatic |
Return the overlap of 'a' and 'b', or an invalid range if they do not overlap at all. When 'a' and 'b' don't overlap at all, calling Invert on the returned range will give the gap between 'a' and 'b'.
|
inlinestatic |
Intersect every element of 'a' with every element of 'b'. Append intersections to 'intersections'. Note that 'intersections' is not reset at the start of the call.
|
inline |
Swap start and end. When 'a' and 'b' don't overlap, if you invert the return value of Range::Intersect(a, b), you'll get the gap between 'a' and 'b'.
|
inline |
Returns the span of the range. Returns 0 when only one number in range. Behavior is undefined for invalid regions.
|
inline |
Returns a range that is 'percent' longer. If 'percent' is < 1.0, then returned range will actually be shorter.
|
inline |
Lerps between the start and the end. 'percent' of 0 returns start. 'percent' of 1 returns end. Behavior is undefined for invalid regions.
|
inline |
Returns the mid-point of the range, rounded down for integers. Behavior is undefined for invalid regions.
|
inline |
Return the difference from 'a' to 'b' that satisfies the 'direction' criteria.
|
inline |
In modular arithmetic, you can get from 'a' to 'b' by going directly, or by wrapping around. Return the closest difference from 'a' to 'b' under modular arithmetic.
|
inline |
Return the difference from 'a' to 'b' under modular arithmetic that is negative.
|
inline |
Return the difference from 'a' to 'b' under modular arithmetic that is positive.
|
inline |
Returns: Length() if x is below the valid range -Length() if x is above the valid range 0 if x is within the valid range.
|
inline |
Ensure x is within the valid constraint range, by subtracting or adding Length() to it. x must be within +-Length() of the range bounds. This is a reasonable restriction in most cases (such as after an arithmetic operation). For cases where x may be wildly outside the range, use NormalizeCloseValue() or NormalizeWildValue() instead.
|
inline |
Ensure x is within the valid constraint range, by subtracting or adding Length() to it repeatedly. x must be within +-kMaxAdjustments * Length() of the range bounds for this function to be effective. If its greater, we end up calling NormalizeWildValue(), so you'd be better off calling NormalizeWildValue() from the beginning. This function is intended to be called in situations where x is almost always within one or two lengths of being normalized, so we don't want to incur the division cost of NormalizeWildValue(). It's still guaranteed to return a normalized value, however.
|
inline |
Ensure x is within the valid constraint range, by subtracting multiples of Length() from it until it is. x can be any value.
|
inline |
|
inline |
Returns percent 0~1, from start to end. Clamped to 0~1. 0 ==> start or earlier; 1 ==> end or later; 0.5 ==> Middle()
|
inlinestatic |
Only keep entries in 'values' if they are in (range.start - epsition, range.end + epsilon). Any values that are kept are clamped to 'range'.
This function is useful when floating point precision error might put a value slightly outside 'range' even though mathematically it should be inside 'range'. This often happens with values right on the border of the valid range.