Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
frechet::data::Interval Class Reference

Detailed Description

an interval of two double values.

Contains methods for intersection, union, and more.

This is one of the most-used basic classes in free-space and reachability algorithms.

It is up to the user of an interval object, whether the interval is interpreted as a closed, open or semi-open interval. (e.g. when constructing a free-space diagram, intervals are usually meant to be closed). The Interval class just manages two interval borders, without imposing an interpretation.

Invalid intervals are indicated by NAN values.

Empty intervals have lower bound == upper bound. Those intervals can be interpreted as empty, or as containing exactly one point.

Empty intervals with lower bound > upper are valid to, but are usually to be avoided.

Since Interval objects are small (two words) it is perfectly alright to pass them by value.

Author
Peter Schäfer

Definition at line 31 of file interval.h.

#include <interval.h>

Inherited by frechet::k::MappedInterval, and frechet::reach::BoundarySegment.

Public Member Functions

 Interval ()
 Default constructor. Creates an invalid Interval. More...
 
 Interval (double lower, double upper)
 Constructor from boundary values. More...
 
 Interval (const Interval &that)
 Copy constructor. More...
 
 Interval (const Interval &that, double shift)
 Copy constructor with shift offset. More...
 
double size () const
 size of the interval (upper - lower). More...
 
bool valid () const
 validity test More...
 
bool empty () const
 empty test More...
 
 operator bool () const
 
bool operator! () const
 
double lower () const
 
double upper () const
 
double & lower ()
 
double & upper ()
 
IntervalsetLower (double value)
 update lower bound More...
 
IntervalsetUpper (double value)
 update upper bound More...
 
double mid () const
 
Intervaloperator= (const Interval &that)
 assignment operator More...
 
bool operator== (const Interval &that) const
 equality comparator More...
 
bool equals (const Interval &that, double precision) const
 equalality comparator with tolerance More...
 
bool operator!= (const Interval &that) const
 non-equality comparator More...
 
Interval normalized () const
 normalized More...
 
Intervalnormalize ()
 make sure that lower <= upper, swapping bounds, if necessary More...
 
Intervalclear ()
 make this an invalid interval More...
 
bool contains (double x) const
 containment test (assumes closed interval, bounds inclusive) More...
 
bool contains (double x, double precision) const
 containment test with tolerance (assumes closed interval, bounds inclusive) More...
 
bool contains (const Interval &that) const
 containment test (closed interval, bounds inclusive) More...
 
bool intersects (const Interval &that) const
 intersection test (closed interval, bounds inclusive) More...
 
bool intersects_proper (const Interval &that) const
 intersection test (open interval, bounds exclusive) More...
 
bool bordersTo (const Interval &that) const
 adjacency test More...
 
double mapToUnitInterval (double x) const
 re-map a value from this interval to the unit interval More...
 
double mapFromUnitInterval (double x) const
 re-map a value from the unit interval to this interval More...
 
double mapTo (double x, const Interval &other) const
 re-map a value to another interval More...
 
double mapFrom (double x, const Interval &other) const
 re-map a value from another interval to this interval More...
 
Interval operator+ (double offset) const
 shift the interval by a fixed offset More...
 
Intervaloperator+= (double offset)
 shift the interval by a fixed offset More...
 
Interval operator- (double offset) const
 shift the interval by a fixed offset More...
 
Intervaloperator-= (double offset)
 shift the interval by a fixed offset More...
 
Interval operator * (double factor) const
 multiply by a factor More...
 
Intervaloperator *= (double factor)
 multiply by a factor More...
 
Interval operator/ (double factor) const
 divide by a factor More...
 
Intervaloperator/= (double factor)
 multiply by a factor More...
 
Interval operator+ (const Interval &that) const
 union operator More...
 
Intervaloperator+= (const Interval &that)
 union operator More...
 
Interval operator- (const Interval &that) const
 difference operator More...
 
Interval operator-= (const Interval &that)
 difference operator More...
 
Interval operator & (const Interval &that) const
 intersection operator More...
 
Intervaloperator&= (const Interval &that)
 intersection operator More...
 
Intervalunion_lf (const Interval &that)
 lock-free union operator; not used and not tested More...
 

Static Public Member Functions

static bool equals (double a, double b)
 equality comparator More...
 

Static Public Attributes

static const Interval UNIT
 the unit interval [0,1] More...
 
static const Interval INVALID = Interval ()
 an invalid interval (contains NAN values) More...
 

Private Member Functions

Intervalassign (double lower, double upper)
 assign new bounds More...
 

Static Private Member Functions

static void assign_min_lf (volatile double *value, double update_value)
 lock-free assigment; not used and not tested More...
 
static void assign_max_lf (volatile double *value, double update_value)
 lock-free assigment; not used and not tested More...
 
static int64_t compare_and_swap (volatile int64_t *value, int64_t old_value, int64_t update_value)
 lock-free compare-and-swap; not used and not tested More...
 

Private Attributes

double _lower
 lower and upper border of the interval More...
 
double _upper
 

Constructor & Destructor Documentation

◆ Interval() [1/4]

frechet::data::Interval::Interval ( )
inline

Default constructor. Creates an invalid Interval.

Definition at line 44 of file interval.h.

◆ Interval() [2/4]

frechet::data::Interval::Interval ( double  lower,
double  upper 
)
inline

Constructor from boundary values.

Parameters
lowerlower bound
upperupper bound

Definition at line 50 of file interval.h.

◆ Interval() [3/4]

frechet::data::Interval::Interval ( const Interval that)
inline

Copy constructor.

Parameters
thatobject to copy from

Definition at line 55 of file interval.h.

◆ Interval() [4/4]

frechet::data::Interval::Interval ( const Interval that,
double  shift 
)
inline

Copy constructor with shift offset.

Parameters
thatobject to copy from
shiftoffset resulting interval by this value

Definition at line 61 of file interval.h.

Member Function Documentation

◆ assign()

Interval& frechet::data::Interval::assign ( double  lower,
double  upper 
)
inlineprivate

assign new bounds

Parameters
lowernew lower bound
uppernew upper bound
Returns
this interval, with new bounds

Definition at line 434 of file interval.h.

◆ assign_max_lf()

void Interval::assign_max_lf ( volatile double *  value,
double  update_value 
)
staticprivate

lock-free assigment; not used and not tested

Definition at line 46 of file interval.cpp.

◆ assign_min_lf()

void Interval::assign_min_lf ( volatile double *  value,
double  update_value 
)
staticprivate

lock-free assigment; not used and not tested

Definition at line 28 of file interval.cpp.

◆ bordersTo()

bool frechet::data::Interval::bordersTo ( const Interval that) const
inline

adjacency test

Parameters
thatinterval to compare to
Returns
true, if both intervals are adjacent

Definition at line 252 of file interval.h.

◆ clear()

Interval& frechet::data::Interval::clear ( )
inline

make this an invalid interval

Returns
this interval, now invalid

Definition at line 197 of file interval.h.

◆ compare_and_swap()

int64_t Interval::compare_and_swap ( volatile int64_t *  value,
int64_t  old_value,
int64_t  update_value 
)
staticprivate

lock-free compare-and-swap; not used and not tested

Definition at line 64 of file interval.cpp.

◆ contains() [1/3]

bool frechet::data::Interval::contains ( double  x) const
inline

containment test (assumes closed interval, bounds inclusive)

Parameters
xa value
Returns
true, if x >= lower and x <= upper.

Definition at line 206 of file interval.h.

◆ contains() [2/3]

bool frechet::data::Interval::contains ( double  x,
double  precision 
) const
inline

containment test with tolerance (assumes closed interval, bounds inclusive)

Parameters
xa value
precisiontolerance
Returns
true, if x >= lower-precision and x <= upper+precision.

Definition at line 216 of file interval.h.

◆ contains() [3/3]

bool frechet::data::Interval::contains ( const Interval that) const
inline

containment test (closed interval, bounds inclusive)

Parameters
thatinterval to test for
Returns
true if that subseteq this

Definition at line 225 of file interval.h.

◆ empty()

bool frechet::data::Interval::empty ( ) const
inline

empty test

Returns
true, if lower > upper

Definition at line 79 of file interval.h.

◆ equals() [1/2]

static bool frechet::data::Interval::equals ( double  a,
double  b 
)
inlinestatic

equality comparator

Returns
true, if a == b, or if both values are NAN

Definition at line 137 of file interval.h.

◆ equals() [2/2]

bool frechet::data::Interval::equals ( const Interval that,
double  precision 
) const
inline

equalality comparator with tolerance

Parameters
thatinterval to compare to
precisiontolerance
Returns
true, if both intervals are equal with regard to the given tolerance.

Definition at line 159 of file interval.h.

◆ intersects()

bool frechet::data::Interval::intersects ( const Interval that) const
inline

intersection test (closed interval, bounds inclusive)

Parameters
thatinterval to test for
Returns
true if that intersected with this is not empty

Definition at line 234 of file interval.h.

◆ intersects_proper()

bool frechet::data::Interval::intersects_proper ( const Interval that) const
inline

intersection test (open interval, bounds exclusive)

Parameters
thatinterval to test for
Returns
true if that intersected with this is not empty

Definition at line 243 of file interval.h.

◆ lower() [1/2]

double frechet::data::Interval::lower ( ) const
inline
Returns
the lower bound of the interval

Definition at line 92 of file interval.h.

◆ lower() [2/2]

double& frechet::data::Interval::lower ( )
inline
Returns
an updatable reference to the lower bound

Definition at line 101 of file interval.h.

◆ mapFrom()

double frechet::data::Interval::mapFrom ( double  x,
const Interval other 
) const
inline

re-map a value from another interval to this interval

Parameters
xa value (possibly contained in this interval)
otheranother interval
Returns
x remapped to this interval

Definition at line 293 of file interval.h.

◆ mapFromUnitInterval()

double frechet::data::Interval::mapFromUnitInterval ( double  x) const
inline

re-map a value from the unit interval to this interval

Parameters
xa value (possibly contained in this interval)
Returns
x remapped to the this interval

Definition at line 273 of file interval.h.

◆ mapTo()

double frechet::data::Interval::mapTo ( double  x,
const Interval other 
) const
inline

re-map a value to another interval

Parameters
xa value (possibly contained in this interval)
otheranother interval
Returns
x remapped to the otehr interval

Definition at line 283 of file interval.h.

◆ mapToUnitInterval()

double frechet::data::Interval::mapToUnitInterval ( double  x) const
inline

re-map a value from this interval to the unit interval

Parameters
xa value (possibly contained in this interval)
Returns
x remapped to the unit interval

Definition at line 260 of file interval.h.

◆ mid()

double frechet::data::Interval::mid ( ) const
inline
Returns
the middle of the interval, (lower+upper)/2

Definition at line 121 of file interval.h.

◆ normalize()

Interval& frechet::data::Interval::normalize ( )
inline

make sure that lower <= upper, swapping bounds, if necessary

Returns
this interval, possibly after swapping bounds

Definition at line 187 of file interval.h.

◆ normalized()

Interval frechet::data::Interval::normalized ( ) const
inline

normalized

Returns

Definition at line 177 of file interval.h.

◆ operator &()

Interval frechet::data::Interval::operator & ( const Interval that) const
inline

intersection operator

Parameters
thatanother interval
Returns
the intersection of both intervals

Definition at line 405 of file interval.h.

◆ operator *()

Interval frechet::data::Interval::operator * ( double  factor) const
inline

multiply by a factor

Returns
copy of this interval, with bounds multiplied

Definition at line 330 of file interval.h.

◆ operator *=()

Interval& frechet::data::Interval::operator *= ( double  factor)
inline

multiply by a factor

Returns
this interval, after bounds multiplied

Definition at line 337 of file interval.h.

◆ operator bool()

frechet::data::Interval::operator bool ( ) const
inline
Returns
true, if valid and not empty

Definition at line 83 of file interval.h.

◆ operator!()

bool frechet::data::Interval::operator! ( ) const
inline
Returns
true, if not valid or empty

Definition at line 87 of file interval.h.

◆ operator!=()

bool frechet::data::Interval::operator!= ( const Interval that) const
inline

non-equality comparator

Parameters
thatinterval to compare to
Returns
true, if both intervals are not equal

Definition at line 167 of file interval.h.

◆ operator&=()

Interval& frechet::data::Interval::operator&= ( const Interval that)
inline

intersection operator

Parameters
thatanother interval
Returns
this interval, containng the intersection of both intervals

Definition at line 416 of file interval.h.

◆ operator+() [1/2]

Interval frechet::data::Interval::operator+ ( double  offset) const
inline

shift the interval by a fixed offset

Returns
copy of this interval, shifted by offset

Definition at line 301 of file interval.h.

◆ operator+() [2/2]

Interval frechet::data::Interval::operator+ ( const Interval that) const
inline

union operator

Parameters
thatanother interval
Returns
the union of both intervals

Definition at line 361 of file interval.h.

◆ operator+=() [1/2]

Interval& frechet::data::Interval::operator+= ( double  offset)
inline

shift the interval by a fixed offset

Returns
this interval, after being shifted by offset

Definition at line 308 of file interval.h.

◆ operator+=() [2/2]

Interval& frechet::data::Interval::operator+= ( const Interval that)
inline

union operator

Parameters
thatanother interval
Returns
this interval, containing the union of both intervals

Definition at line 372 of file interval.h.

◆ operator-() [1/2]

Interval frechet::data::Interval::operator- ( double  offset) const
inline

shift the interval by a fixed offset

Returns
copy of this interval, shifted by offset

Definition at line 316 of file interval.h.

◆ operator-() [2/2]

Interval frechet::data::Interval::operator- ( const Interval that) const
inline

difference operator

Parameters
thatanother interval
Returns
the difference (this-that)

Definition at line 383 of file interval.h.

◆ operator-=() [1/2]

Interval& frechet::data::Interval::operator-= ( double  offset)
inline

shift the interval by a fixed offset

Returns
this interval, after being shifted by offset

Definition at line 323 of file interval.h.

◆ operator-=() [2/2]

Interval frechet::data::Interval::operator-= ( const Interval that)
inline

difference operator

Parameters
thatanother interval
Returns
this interval, containing the difference (this-that)

Definition at line 394 of file interval.h.

◆ operator/()

Interval frechet::data::Interval::operator/ ( double  factor) const
inline

divide by a factor

Returns
copy of this interval, with bounds updated

Definition at line 345 of file interval.h.

◆ operator/=()

Interval& frechet::data::Interval::operator/= ( double  factor)
inline

multiply by a factor

Returns
this interval, after bounds updated

Definition at line 352 of file interval.h.

◆ operator=()

Interval& frechet::data::Interval::operator= ( const Interval that)
inline

assignment operator

Parameters
thatinterval to copy from
Returns
this interval, after being updated

Definition at line 130 of file interval.h.

◆ operator==()

bool frechet::data::Interval::operator== ( const Interval that) const
inline

equality comparator

Parameters
thatinterval to compare to
Returns
true, if both intervals are equal

Definition at line 149 of file interval.h.

◆ setLower()

Interval& frechet::data::Interval::setLower ( double  value)
inline

update lower bound

Parameters
valuenew value for lower bound
Returns
this object, after being updated

Definition at line 111 of file interval.h.

◆ setUpper()

Interval& frechet::data::Interval::setUpper ( double  value)
inline

update upper bound

Parameters
valuenew value for upper bound
Returns
this object, after being updated

Definition at line 117 of file interval.h.

◆ size()

double frechet::data::Interval::size ( ) const
inline

size of the interval (upper - lower).

Returns
upper - lower

Definition at line 67 of file interval.h.

◆ union_lf()

Interval & Interval::union_lf ( const Interval that)

lock-free union operator; not used and not tested

Sketch for a lock-free union operator

Definition at line 19 of file interval.cpp.

◆ upper() [1/2]

double frechet::data::Interval::upper ( ) const
inline
Returns
the upper bound of the interval

Definition at line 96 of file interval.h.

◆ upper() [2/2]

double& frechet::data::Interval::upper ( )
inline
Returns
an updatable reference to the upper bound

Definition at line 105 of file interval.h.

◆ valid()

bool frechet::data::Interval::valid ( ) const
inline

validity test

Returns
true if both values are valid (!= NAN)
Deprecated:
use operator bool instead

Definition at line 74 of file interval.h.

Member Data Documentation

◆ _lower

double frechet::data::Interval::_lower
private

lower and upper border of the interval

Definition at line 34 of file interval.h.

◆ _upper

double frechet::data::Interval::_upper
private

Definition at line 34 of file interval.h.

◆ INVALID

const Interval Interval::INVALID = Interval ()
static

an invalid interval (contains NAN values)

Definition at line 39 of file interval.h.

◆ UNIT

const Interval Interval::UNIT
static

the unit interval [0,1]

Definition at line 37 of file interval.h.


The documentation for this class was generated from the following files: