CVR-Lib last update 20 Sep 2009

cvr::interval< T > Class Template Reference
[Geometry Data Structures]

A one dimensional interval, giving the from and to values. More...

#include <cvrInterval.h>

List of all members.

Public Types

typedef T value_type
typedef int size_type

Public Member Functions

 interval (const T newx=T(), const T newy=T())
template<typename U >
 interval (const interval< U > &p)
template<typename U >
interval< T > & castFrom (const interval< U > &p)
interval< T > & set (const T tx, const T ty)
void get (T &tx, T &ty) const
template<typename U >
interval< T > & multiply (const U c)
template<typename U >
interval< T > operator* (const U c) const
template<typename U >
interval< T > & multiply (const interval< T > &other, const U c)
template<typename U >
interval< T > & operator*= (const U c)
interval< T > & emultiply (const interval< T > &c)
interval< T > & emultiply (const interval< T > &a, const interval< T > &b)
template<typename U >
interval< T > & divide (const U c)
template<typename U >
interval< T > & divide (const interval< T > &other, const U c)
template<typename U >
interval< T > operator/ (const U c) const
template<typename U >
interval< T > & operator/= (const U c)
interval< T > & edivide (const interval< T > &c)
interval< T > & edivide (const interval< T > &a, const interval< T > &b)
interval< T > operator% (const int c) const
interval< T > & join (const interval< T > &p)
interval< T > & join (const interval< T > &a, const interval< T > &b)
interval< T > & subtract (const interval< T > &p)
interval< T > & subtract (const interval< T > &a, const interval< T > &b)
interval< T > operator- (const interval< T > &p) const
interval< T > & operator-= (const interval< T > &p)
interval< T > & copy (const interval< T > &p)
interval< T > & operator= (const interval< T > &p)
bool operator== (const interval< T > &p) const
bool operator!= (const interval< T > &p) const
length () const
bool contains (const T val) const
bool contains (const interval< T > &val) const
closest (const T val) const
Access as vector
T & operator[] (const int i)
const T & operator[] (const int i) const
size_type size () const

Public Attributes

union {
   value_type   data [2]
}; 
value_type from
value_type to


Detailed Description

template<typename T>
class cvr::interval< T >

A one dimensional interval, giving the from and to values.

The template type T will be the one used for each limit value. For example interval<float> uses float for from and to.

This data structure simplifies the manipulation of one dimensional intervals providing simple interfaces for adding, substracting, distance (L2), and more.

There are some alias to shorten the notation:

An inteval with a from value greater than the to value is considered as invalid. So, methods which return such configuration can be interpreted as empty intervals.


Member Typedef Documentation

template<typename T>
typedef int cvr::interval< T >::size_type

Return type of the size() member.

template<typename T>
typedef T cvr::interval< T >::value_type

Used for the template-based interface for pixels as vectors.


Constructor & Destructor Documentation

template<typename T>
cvr::interval< T >::interval ( const T  newx = T(),
const T  newy = T() 
) [explicit]

Default constructor.

template<typename T>
template<typename U >
cvr::interval< T >::interval ( const interval< U > &  p  )  [inline]

Copy constructor.


Member Function Documentation

template<typename T>
template<typename U >
interval<T>& cvr::interval< T >::castFrom ( const interval< U > &  p  )  [inline]

Copy constructor.

template<typename T>
T cvr::interval< T >::closest ( const T  val  )  const [inline]

Return the closest value of type T which lies on the interval.

This method returns the same value of the argument iff that value lies within the interval, from if the given value is less than it, or to if it is greater.

template<typename T>
bool cvr::interval< T >::contains ( const interval< T > &  val  )  const [inline]

Check if the given interval is fully contained in the interval.

Return true if the given value is contained within the container. This method assumes that the intervall represents a closed interval, so that the boundaries are considered as part of it.

template<typename T>
bool cvr::interval< T >::contains ( const T  val  )  const [inline]

Check if element is contained in the interval.

Return true if the given value is contained within the container. This method assumes that the intervall represents a closed interval, so that the boundaries are considered as part of it.

template<typename T>
interval<T>& cvr::interval< T >::copy ( const interval< T > &  p  )  [inline]

Copy operator.

template<typename T>
template<typename U >
interval<T>& cvr::interval< T >::divide ( const interval< T > &  other,
const U  c 
) [inline]

Divide each component of other other interval<T> with a given factor.

template<typename T>
template<typename U >
interval<T>& cvr::interval< T >::divide ( const U  c  )  [inline]

Divide each component of interval<T> with a given factor.

template<typename T>
interval<T>& cvr::interval< T >::edivide ( const interval< T > &  a,
const interval< T > &  b 
) [inline]

Elementwise division of each component of the intervals.

template<typename T>
interval<T>& cvr::interval< T >::edivide ( const interval< T > &  c  )  [inline]

Elementwise division of each component of the intervals.

template<typename T>
interval<T>& cvr::interval< T >::emultiply ( const interval< T > &  a,
const interval< T > &  b 
) [inline]

Multiplies elementwise the components of a and b and leave the result here.

template<typename T>
interval<T>& cvr::interval< T >::emultiply ( const interval< T > &  c  )  [inline]

Multiplies elementwise the components of this and the interval c, and leave the result here.

template<typename T>
void cvr::interval< T >::get ( T &  tx,
T &  ty 
) const [inline]

Get the limit values.

template<typename T>
interval<T>& cvr::interval< T >::join ( const interval< T > &  a,
const interval< T > &  b 
) [inline]

Add the two other intervals and leave the result here.

Parameters:
a first interval to be added
b second interval to be added
Returns:
a reference to this interval, which will contain a+b

template<typename T>
interval<T>& cvr::interval< T >::join ( const interval< T > &  p  )  [inline]

Find the smallest interval which contains all points of both, this interval and the given one.

Since the intervals may not overlap, the result

Parameters:
p the other interval to be added to this one
Returns:
a reference to this interval

template<typename T>
T cvr::interval< T >::length (  )  const [inline]

Length of the interval.

For this method, the intervals are considered closed. This is specially important for integer types, which will return from-to+1, while for floating-point types it just return from-to.

template<typename T>
template<typename U >
interval<T>& cvr::interval< T >::multiply ( const interval< T > &  other,
const U  c 
) [inline]

Multiply the other interval interval<T> with a given scale factor.

The type U has to be compatible with the type T in the sense that they can be multiplied and casted to T. This applies to most build in type like int, float, etc.

template<typename T>
template<typename U >
interval<T>& cvr::interval< T >::multiply ( const U  c  )  [inline]

Scale an interval, multiplying each limit by the given scalar.

The type U has to be compatible with the type T in the sense that they can be multiplied and casted to T. This applies to most build in type like int, float, etc.

template<typename T>
bool cvr::interval< T >::operator!= ( const interval< T > &  p  )  const [inline]

Operator !=.

template<typename T>
interval<T> cvr::interval< T >::operator% ( const int  c  )  const [inline]

Modulo c of the integer part of each component of the interval.

template<typename T>
template<typename U >
interval<T> cvr::interval< T >::operator* ( const U  c  )  const [inline]

Scale an interval, multiplying each limit by the given scalar.

The type U has to be compatible with the type T in the sense that they can be multiplied and casted to T. This applies to most build in type like int, float, etc.

template<typename T>
template<typename U >
interval<T>& cvr::interval< T >::operator*= ( const U  c  )  [inline]

Multiply interval<T> with a given factor.

The type U has to be compatible with the type T in the sense that they can be multiplied and casted to T. This applies to most build in type like int, float, etc.

template<typename T>
interval<T> cvr::interval< T >::operator- ( const interval< T > &  p  )  const [inline]

Operator -.

template<typename T>
interval<T>& cvr::interval< T >::operator-= ( const interval< T > &  p  )  [inline]

Operator -=.

template<typename T>
template<typename U >
interval<T> cvr::interval< T >::operator/ ( const U  c  )  const [inline]

Divide each component of interval<T> by a given factor.

template<typename T>
template<typename U >
interval<T>& cvr::interval< T >::operator/= ( const U  c  )  [inline]

Divide each component of interval<T> by a given factor.

template<typename T>
interval<T>& cvr::interval< T >::operator= ( const interval< T > &  p  )  [inline]

Operator =.

template<typename T>
bool cvr::interval< T >::operator== ( const interval< T > &  p  )  const [inline]

Operator ==.

template<typename T>
const T& cvr::interval< T >::operator[] ( const int  i  )  const [inline]

Used to simulate read-only vector access.

It allows the use of interval in templates expecting a vector-like structure.

The correspondence between the elements of the vector and the components will be [0] for x and [1] for y

template<typename T>
T& cvr::interval< T >::operator[] ( const int  i  )  [inline]

Used to simulate vector access.

It allows the use of interval in templates expecting a vector-like structure.

The correspondence between the elements of the vector and the components will be [0] for x and [1] for y

template<typename T>
interval<T>& cvr::interval< T >::set ( const T  tx,
const T  ty 
) [inline]

Set the coordinate values and return a reference to this interval.

template<typename T>
size_type cvr::interval< T >::size (  )  const [inline]

Used to simulate the vector size.

template<typename T>
interval<T>& cvr::interval< T >::subtract ( const interval< T > &  a,
const interval< T > &  b 
) [inline]

Subtract the two other intervals and leave the result here.

Here, the subtraction means the smallest interval which contains all the points of the set-subtraction of this interval minus all the elements of the given one.

Parameters:
a first interval
b interval to be subtracted from the first one
Returns:
a reference to this interval, which will contain a-b

template<typename T>
interval<T>& cvr::interval< T >::subtract ( const interval< T > &  p  )  [inline]

Set subtraction of this and the given interval.

Here, the subtraction means the smallest interval which contains all the points of the set-subtraction of this interval minus all the elements of the given one.


Member Data Documentation

union { ... }

Anonymous union to allow the fastes access to the elements as semantic tokes (x and y) and as array as well.

template<typename T>
value_type cvr::interval< T >::data[2]

Array that shares the same memory with from and to.

template<typename T>
value_type cvr::interval< T >::from

From value.

template<typename T>
value_type cvr::interval< T >::to

To value.


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

Generated on Sun Sep 20 22:09:08 2009 for CVR-Lib by Doxygen 1.5.8