Open Search
    Range< T > Class Template Reference

    #include <range.h>

    Detailed Description

    template<typename T>
    class maxon::Range< T >

    A Range represents a closed interval of values min ... max (both bounds are inclusive). If T is a vector type, this is actually a multi-dimensional interval such as a rectangle for two-dimensional vectors or an axis-aligned (bounding) box in three dimensions.

    To compare T values, range uses a.LessThanOrEqual(b) if possible, otherwise a <= b. The corresponding order may be a partial order (as it is the case for vectors).

    Template Parameters
    TThe underlying datatype, either a scalar type, or a vector type where T::ValueType specifies the type of the vector elements.

    Public Types

    using ScalarType = decltype(PrivateRangeValueTypeHelper< T >(OVERLOAD_MAX_RANK))
     

    Public Member Functions

    constexpr Range ()
     
    constexpr Range (const T &v)
     
    constexpr Range (const T &rangeMin, const T &rangeMax)
     
    void Reset ()
     
    void Set (const T &v)
     
    void Set (const T &rangeMin, const T &rangeMax)
     
    void Add (const T &p)
     
    void Add (const T &rangeMin, const T &rangeMax)
     
    void Add (const Range &range)
     
    void Intersect (const T &rangeMin, const T &rangeMax)
     
    void Intersect (const Range &range)
     
    Rangeoperator+= (const T &shift)
     
    Rangeoperator-= (const T &shift)
     
    Range operator+ (const T &shift) const
     
    Range operator- (const T &shift) const
     
    Bool IsIntersecting (const Range &range) const
     
    Bool IsEmpty () const
     
    Bool IsPopulated () const
     
    GetMin () const
     
    GetMax () const
     
    GetCenter () const
     
    GetDimension () const
     
    Bool Contains (const T &value) const
     
    Bool Contains (const Range< T > &value) const
     
     MAXON_OPERATOR_EQUALITY_HASHCODE (Range, minValue, maxValue)
     
    SFINAEHelper< String, T >::type ToString (const FormatStatement *format=nullptr) const
     

    Public Attributes

    minValue
     
    maxValue
     

    Member Typedef Documentation

    ◆ ScalarType

    Constructor & Destructor Documentation

    ◆ Range() [1/3]

    constexpr Range ( )
    constexpr

    Constructs an empty range. min is set to the maximum possible value, max to the minimum possible value.

    ◆ Range() [2/3]

    constexpr Range ( const T &  v)
    explicitconstexpr

    Constructs a singleton range containing exactly v.

    Parameters
    [in]vInitial value for the range.

    ◆ Range() [3/3]

    constexpr Range ( const T &  rangeMin,
    const T &  rangeMax 
    )
    constexpr

    Constructs the range rangeMin ... rangeMax. If rangeMin is not less than or equal to rangeMax, the range will be empty.

    Parameters
    [in]rangeMinInitial minimum value for the range.
    [in]rangeMaxInitial maximum value for the range.

    Member Function Documentation

    ◆ Reset()

    void Reset ( )

    Resets the range to its initial state, i.e., to an empty range where min is set to the maximum possible value, max to the minimum possible value.

    ◆ Set() [1/2]

    void Set ( const T &  v)

    Sets this range to a singleton range containing exactly v.

    Parameters
    [in]vSingleton value for the range.

    ◆ Set() [2/2]

    void Set ( const T &  rangeMin,
    const T &  rangeMax 
    )

    Sets this range to rangeMin ... rangeMax. If rangeMin is not less than or equal to rangeMax, the range will be empty.

    Parameters
    [in]rangeMinMinimum value for the range.
    [in]rangeMaxMaximum value for the range.

    ◆ Add() [1/3]

    void Add ( const T &  p)

    Extends this range if necessary so that it encloses p.

    Parameters
    [in]pValue to include in this range.

    ◆ Add() [2/3]

    void Add ( const T &  rangeMin,
    const T &  rangeMax 
    )

    Extends this range if necessary so that it encloses the range given by rangeMin ... rangeMax. It that range is empty, nothing happens.

    Parameters
    [in]rangeMinMinimum value of the other range to include.
    [in]rangeMaxMaximum value of the other range to include.

    ◆ Add() [3/3]

    void Add ( const Range< T > &  range)

    Extends this range if necessary so that it encloses the other range. It that range is empty, nothing happens.

    Parameters
    [in]rangeAnother range to include in this range.

    ◆ Intersect() [1/2]

    void Intersect ( const T &  rangeMin,
    const T &  rangeMax 
    )

    Intersects this range with the range given by rangeMin ... rangeMax.

    Parameters
    [in]rangeMinMinimum value of the other range for intersection.
    [in]rangeMaxMaximum value of the other range for intersection.

    ◆ Intersect() [2/2]

    void Intersect ( const Range< T > &  range)

    Intersects this range with the other range.

    Parameters
    [in]rangeAnother range to intersect with.

    ◆ operator+=()

    Range& operator+= ( const T &  shift)

    Shifts this range by #shift. The value of #shift is added to the minimum and maximum value.

    Parameters
    [in]shiftValue to add to the bounds.

    ◆ operator-=()

    Range& operator-= ( const T &  shift)

    Shifts this range by #shift. The value of #shift is substracted from the minimum and maximum value.

    Parameters
    [in]shiftValue to subtract from the bounds.

    ◆ operator+()

    Range operator+ ( const T &  shift) const

    Returns a new range which is given by this range, shifted by #shift. The value of #shift is added to the minimum and maximum value.

    Parameters
    [in]shiftValue to add to the bounds.
    Returns
    New range with shifted bounds.

    ◆ operator-()

    Range operator- ( const T &  shift) const

    Returns a new range which is given by this range, shifted by #shift. The value of #shift is subtracted from the minimum and maximum value.

    Parameters
    [in]shiftValue to subtract from the bounds.
    Returns
    New range with shifted bounds.

    ◆ IsIntersecting()

    Bool IsIntersecting ( const Range< T > &  range) const

    Tests if this range intersects with the other range

    Parameters
    [in]rangeAnother range to test the intersect with.
    Returns
    Return true if the ranges intersect, false otherwise

    ◆ IsEmpty()

    Bool IsEmpty ( ) const

    Returns true if this range is empty. In that case GetMin(), GetMax(), GetCenter(), GetDimension() will return a guaranteed, but incorrect value of 0.

    Returns
    True if range is empty.

    ◆ IsPopulated()

    Bool IsPopulated ( ) const

    Returns true if this range is populated.

    Returns
    True if range is not empty.

    ◆ GetMin()

    T GetMin ( ) const

    Returns the minimum boundary. For an empty range, this will return T(0).

    Returns
    Minimum boundary, or T(0) for an empty range.

    ◆ GetMax()

    T GetMax ( ) const

    Returns the maximum boundary. For an empty range, this will return T(0).

    Returns
    Maximum boundary, or T(0) for an empty range.

    ◆ GetCenter()

    T GetCenter ( ) const

    Returns the center of the range. For an empty range, this will return T(0).

    Returns
    Center of the range, or T(0) for an empty range.

    ◆ GetDimension()

    T GetDimension ( ) const

    Returns the dimension of range. For an empty range, this will return T(0), otherwise the difference of maximum and minimum value. Note that for integral datatypes this does not calculate the number of elements (which is maxValue - minValue + 1). To do so you need to add 1 manually.

    Returns
    Dimension of the range, or T(0) for an empty range.

    ◆ Contains() [1/2]

    Bool Contains ( const T &  value) const

    Tests if the given value is contained in this range.

    Parameters
    [in]valueValue to check.
    Returns
    True if the value is contained in the range.

    ◆ Contains() [2/2]

    Bool Contains ( const Range< T > &  value) const

    Tests if the given value is contained in this range.

    Parameters
    [in]valueValue to check.
    Returns
    True if the value is contained in the range.

    ◆ MAXON_OPERATOR_EQUALITY_HASHCODE()

    MAXON_OPERATOR_EQUALITY_HASHCODE ( Range< T >  ,
    minValue  ,
    maxValue   
    )

    ◆ ToString()

    SFINAEHelper<String, T>::type ToString ( const FormatStatement format = nullptr) const

    Member Data Documentation

    ◆ minValue

    T minValue

    The inclusive minimum boundary of this range.

    ◆ maxValue

    T maxValue

    The inclusive maximum boundary of this range. If the minimum boundary is not less than or equal to this, the range is empty.