Gnash  0.8.10
gnash::geometry::Range2d Class Reference

2d Range template class More...

`#include <Range2d.h>`

List of all members.

## Public Member Functions

Range2d (RangeKind kind=nullRange)
Construct a Range2d of the given kind.
Range2d (T xmin, T ymin, T xmax, T ymax)
Construct a finite Range2d with the given values.
template<typename U >
Range2d (const Range2d< U > &from)
Templated copy constructor, for casting between range types.
bool isNull () const
Returns true if this is the NULL Range2d.
Range2d< T > & setNull ()
Set the Range2d to the NULL value.
bool isWorld () const
Returns true if this is the WORLD Range2d.
bool isFinite () const
Returns true if this is a finite Range2d.
Range2d< T > & setWorld ()
Set the Range2d to the WORLD value.
template<typename U >
bool contains (U x, U y) const
Return true if this rectangle contains the point with given coordinates (boundaries are inclusive).
bool contains (const Range2d< T > &other) const
Return true if this rectangle contains the given rectangle.
bool intersects (const Range2d< T > &other) const
Return true if this rectangle intersects the point with given coordinates (boundaries are inclusive).
Range2d< T > & expandTo (T x, T y)
Expand this Range2d to enclose the given point.
Range2d< T > & expandToCircle (T x, T y, T radius)
Expand this Range2d to enclose the given circle.
Range2d< T > & setTo (T x, T y)
Set ourself to bound the given point.
Range2d< T > & setTo (T xmin, T ymin, T xmax, T ymax)
Set coordinates to given values.
width () const
Return width this Range2d.
height () const
Return height this Range2dangle.
Range2d< T > & shiftX (T offset)
Shift this Range2dangle horizontally.
Range2d< T > & shiftY (T offset)
Shift this Range2dangle vertically.
Range2d< T > & scaleX (float factor)
Scale this Range2d horizontally.
Range2d< T > & scaleY (float factor)
Scale this Range2d vertically.
Range2d< T > & scale (float xfactor, float yfactor)
Scale this Range2d.
Range2d< T > & scale (float factor)
Scale this Range2d in both directions with the same factor.
Range2d< T > & growBy (T amount)
Grow this range by the given amout in all directions.
Range2d< T > & shrinkBy (T amount)
Shirnk this range by the given amout in all directions.
getMinX () const
Get min X ordinate.
getMaxX () const
Get max X ordinate.
getMinY () const
Get min Y ordinate.
getMaxY () const
Get max Y ordinate.
getArea () const
void expandTo (const Range2d< T > &r)
Expand this range to include the given Range2d.
template<>
int getArea () const
template<>
unsigned int getArea () const

## Friends

template<typename U >
std::ostream & operator<< (std::ostream &os, const Range2d< U > &rect)
Ouput operator.
template<typename U >
bool operator== (const Range2d< U > &r1, const Range2d< U > &r2)
Equality operator.
template<typename U >
bool operator!= (const Range2d< U > &r1, const Range2d< U > &r2)
Inequality operator.
template<typename U >
Range2d< U > Intersection (const Range2d< U > &r1, const Range2d< U > &r2)
Return a rectangle being the intersetion of the two rectangles.
template<typename U >
Range2d< U > Union (const Range2d< U > &r1, const Range2d< U > &r2)
Return a rectangle being the union of the two rectangles.

## Detailed Description

2d Range template class

The class stores 4 values of the type specified as template argument, representing the set of points enclosed by the given min and max values for the 2 dimensions, and provides methods for manipulating them. The parameter type must be a numeric type.

The two dimensions are called X and Y.

Note that the range is "open", which means that the points on its boundary are considered internal to the range.

## Constructor & Destructor Documentation

 gnash::geometry::Range2d::Range2d ( RangeKind kind = `nullRange` ) ` [inline]`

Construct a Range2d of the given kind.

The default is building a nullRange. If finiteRange is given the range will be set to enclose the origin.

See RangeKind

 gnash::geometry::Range2d::Range2d ( T xmin, T ymin, T xmax, T ymax ) ` [inline]`

Construct a finite Range2d with the given values.

Make sure that the min <= max, or an assertion would fail. We could as well swap the values in this case, but it is probably better to force caller to deal with this, as a similar case might as well expose a bug in the code.

template<typename U >
 gnash::geometry::Range2d::Range2d ( const Range2d< U > & from ) ` [inline]`

Templated copy constructor, for casting between range types.

## Member Function Documentation

template<typename U >
 bool gnash::geometry::Range2d::contains ( U x, U y ) const` [inline]`

Return true if this rectangle contains the point with given coordinates (boundaries are inclusive).

Note that WORLD rectangles contain every point and NULL rectangles contain no point.

 bool gnash::geometry::Range2d::contains ( const Range2d< T > & other ) const` [inline]`

Return true if this rectangle contains the given rectangle.

Note that:

• WORLD ranges contain every range except NULL ones and are only contained in WORLD ranges
• NULL ranges contain no ranges and are contained in no ranges.
 Range2d& gnash::geometry::Range2d::expandTo ( T x, T y ) ` [inline]`

Expand this Range2d to enclose the given point.

Returns:
a reference to this instance
 void gnash::geometry::Range2d::expandTo ( const Range2d< T > & r ) ` [inline]`

Expand this range to include the given Range2d.

WORLD ranges force result to be the WORLD range. A NULL range will have no effect on the result.

 Range2d& gnash::geometry::Range2d::expandToCircle ( T x, T y, T radius ) ` [inline]`

Expand this Range2d to enclose the given circle.

Returns:
a reference to this instance
 T gnash::geometry::Range2d::getArea ( ) const` [inline]`

Get area (width*height)

template<>
 int gnash::geometry::Range2d< int >::getArea ( ) const` [inline]`

References assert.

template<>
 unsigned int gnash::geometry::Range2d< unsigned int >::getArea ( ) const` [inline]`

References assert, and gnash::isFinite().

 T gnash::geometry::Range2d::getMaxX ( ) const` [inline]`
 T gnash::geometry::Range2d::getMaxY ( ) const` [inline]`
 T gnash::geometry::Range2d::getMinX ( ) const` [inline]`
 T gnash::geometry::Range2d::getMinY ( ) const` [inline]`
 Range2d& gnash::geometry::Range2d::growBy ( T amount ) ` [inline]`

Grow this range by the given amout in all directions.

WORLD or NULL ranges will be unchanged.

If a growing range hits the numerical limit for T it will be set to the WORLD range.

Parameters:
 amount The amount of T to grow this range in all directions. If negative the range will shrink. If negative the range will shrink. See shrinkBy().
Returns:
a reference to this instance
 T gnash::geometry::Range2d::height ( ) const` [inline]`

Return height this Range2dangle.

Don't call this function on a WORLD rectangle!

 bool gnash::geometry::Range2d::intersects ( const Range2d< T > & other ) const` [inline]`

Return true if this rectangle intersects the point with given coordinates (boundaries are inclusive).

Note that NULL rectangles don't intersect anything and WORLD rectangles intersects everything except a NULL rectangle.

 bool gnash::geometry::Range2d::isFinite ( ) const` [inline]`
 Range2d& gnash::geometry::Range2d::scale ( float xfactor, float yfactor ) ` [inline]`

Scale this Range2d.

WORLD or NULL ranges will be unchanged

For finite ranges: Any factor of 0 will make the range NULL. A factor of 1 will leave the corresponding size unchanged. A factor > 1 will make the corresponding size bigger. A factor < 1 factor will make the corresponding size smaller.

Computation is done in single floating point precision. Specializations for integer types ensure that when rounding back the resulting range is not smaller then the floating range computed during scaling (in all directions).

Control point is the origin (0,0).

If the range so scaled will hit the numerical limit of the range an assertion will fail (TODO: throw an exception instead!).

Parameters:
 xfactor The horizontal scale factor. It's a float to allow for fractional scale even for integer ranges. yfactor The vertical scale factor. It's a float to allow for fractional scale even for integer ranges.
Returns:
a reference to this instance
 Range2d& gnash::geometry::Range2d::scale ( float factor ) ` [inline]`

Scale this Range2d in both directions with the same factor.

 Range2d& gnash::geometry::Range2d::scaleX ( float factor ) ` [inline]`

Scale this Range2d horizontally.

 Range2d& gnash::geometry::Range2d::scaleY ( float factor ) ` [inline]`

Scale this Range2d vertically.

 Range2d& gnash::geometry::Range2d::setNull ( ) ` [inline]`

Set the Range2d to the NULL value.

Returns:
a reference to this instance
 Range2d& gnash::geometry::Range2d::setTo ( T x, T y ) ` [inline]`

Set ourself to bound the given point.

Returns:
a reference to this instance
 Range2d& gnash::geometry::Range2d::setTo ( T xmin, T ymin, T xmax, T ymax ) ` [inline]`

Set coordinates to given values.

Make sure that the min <= max, or an assertion would fail. We could as well swap the values in this case, but it is probably better to force caller to deal with this, as a similar case might as well expose a bug in the code.

Returns:
a reference to this instance
 Range2d& gnash::geometry::Range2d::setWorld ( ) ` [inline]`

Set the Range2d to the WORLD value.

This is implemented using the minimun and maximun values of the parameter type.

See RangeType::worldRange

Returns:
a reference to this instance
 Range2d& gnash::geometry::Range2d::shiftX ( T offset ) ` [inline]`

Shift this Range2dangle horizontally.

A positive offset will shift to the right, A negative offset will shift to the left.

WORLD or NULL ranges will be unchanged

Returns:
a reference to this instance
 Range2d& gnash::geometry::Range2d::shiftY ( T offset ) ` [inline]`

Shift this Range2dangle vertically.

A positive offset will increment y values. A negative offset will decrement y values.

WORLD or NULL ranges will be unchanged

Returns:
a reference to this instance
 Range2d& gnash::geometry::Range2d::shrinkBy ( T amount ) ` [inline]`

Shirnk this range by the given amout in all directions.

WORLD or NULL ranges will be unchanged.

If a shrinking range will collapse in either the horizontal or vertical dimension it will be set to the NULL range.

Parameters:
 amount The amount of T to shink this range in all directions. If negative the range will grow. See growBy().
Returns:
a reference to this instance

NOTE: This method assumes that the numerical type used as parameter does allow both positive and negative values. Using this method against an instance of an 'unsigned' Range2d will likely raise unexpected results.

TODO: change the interface to never make the Range null, as we might always use the Range *center* point instead of forgetting about it!

Referenced by gnash::geometry::Range2d< int >::growBy().

 T gnash::geometry::Range2d::width ( ) const` [inline]`

Return width this Range2d.

Don't call this function on a WORLD rectangle!

## Friends And Related Function Documentation

template<typename U >
 Range2d Intersection ( const Range2d< U > & r1, const Range2d< U > & r2 ) ` [friend]`

Return a rectangle being the intersetion of the two rectangles.

Any NULL operand will make the result also NULL.

template<typename U >
 bool operator!= ( const Range2d< U > & r1, const Range2d< U > & r2 ) ` [friend]`

Inequality operator.

This is needed to take NULL kind into account since we don't explicitly set all members when constructing NULL ranges

template<typename U >
 std::ostream& operator<< ( std::ostream & os, const Range2d< U > & rect ) ` [friend]`

Ouput operator.

template<typename U >
 bool operator== ( const Range2d< U > & r1, const Range2d< U > & r2 ) ` [friend]`

Equality operator.

This is needed to take NULL kind into account since we don't explicitly set all members when constructing NULL ranges

template<typename U >
 Range2d Union ( const Range2d< U > & r1, const Range2d< U > & r2 ) ` [friend]`

Return a rectangle being the union of the two rectangles.

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