Gnash  0.8.11dev
Public Member Functions | Friends | List of all members
gnash::geometry::Range2d< T > Class Template Reference

2d Range template class More...

#include <Range2d.h>

Public Member Functions

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

Friends

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

Detailed Description

template<typename T>
class gnash::geometry::Range2d< T >

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

§ Range2d() [1/3]

template<typename T>
gnash::geometry::Range2d< T >::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

§ Range2d() [2/3]

template<typename T>
gnash::geometry::Range2d< T >::Range2d ( xmin,
ymin,
xmax,
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.

§ Range2d() [3/3]

template<typename T>
template<typename U >
gnash::geometry::Range2d< T >::Range2d ( const Range2d< U > &  from)
inline

Templated copy constructor, for casting between range types.

Member Function Documentation

§ contains() [1/2]

template<typename T>
template<typename U >
bool gnash::geometry::Range2d< T >::contains ( x,
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.

Referenced by gnash::geometry::SnappingRanges2d< T >::ContainsPoint::operator()(), and gnash::geometry::SnappingRanges2d< T >::ContainsRange::operator()().

§ contains() [2/2]

template<typename T>
bool gnash::geometry::Range2d< T >::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.

§ expandTo() [1/2]

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::expandTo ( x,
y 
)
inline

§ expandTo() [2/2]

template<typename T>
void gnash::geometry::Range2d< T >::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.

§ expandToCircle()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::expandToCircle ( x,
y,
radius 
)
inline

Expand this Range2d to enclose the given circle.

Returns
a reference to this instance

§ getArea() [1/3]

template<typename T>
detail::Promote<T>::type gnash::geometry::Range2d< T >::getArea ( ) const
inline

Get area (width*height)

Referenced by gnash::geometry::operator<<().

§ getArea() [2/3]

template<>
detail::Promote< int >::type gnash::geometry::Range2d< int >::getArea ( ) const
inline

Specialization of area value for int type.

Add one.

§ getArea() [3/3]

template<>
detail::Promote< unsigned int >::type gnash::geometry::Range2d< unsigned int >::getArea ( ) const
inline

Specialization of area value for unsigned int type.

Add one.

§ getMaxX()

template<typename T>
T gnash::geometry::Range2d< T >::getMaxX ( ) const
inline

§ getMaxY()

template<typename T>
T gnash::geometry::Range2d< T >::getMaxY ( ) const
inline

§ getMinX()

template<typename T>
T gnash::geometry::Range2d< T >::getMinX ( ) const
inline

§ getMinY()

template<typename T>
T gnash::geometry::Range2d< T >::getMinY ( ) const
inline

§ growBy()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::growBy ( 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
amountThe 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

Referenced by gnash::geometry::SnappingRanges2d< T >::GrowBy::operator()().

§ height()

template<typename T>
T gnash::geometry::Range2d< T >::height ( ) const
inline

Return height this Range2dangle.

Don't call this function on a WORLD rectangle!

Referenced by gnash::FltkAggGlue::draw(), gnash::Renderer_cairo::drawVideoFrame(), gnash::KdeAggGlue::render(), and gnash::GtkGui::setInvalidatedRegions().

§ intersects()

template<typename T>
bool gnash::geometry::Range2d< T >::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.

Referenced by gnash::geometry::Intersect(), gnash::geometry::Intersection(), gnash::geometry::SnappingRanges2d< T >::IntersectsRange::operator()(), and gnash::geometry::operator<<().

§ isFinite()

template<typename T>
bool gnash::geometry::Range2d< T >::isFinite ( ) const
inline

§ isNull()

template<typename T>
bool gnash::geometry::Range2d< T >::isNull ( ) const
inline

§ isWorld()

template<typename T>
bool gnash::geometry::Range2d< T >::isWorld ( ) const
inline

§ scale() [1/2]

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::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
xfactorThe horizontal scale factor. It's a float to allow for fractional scale even for integer ranges.
yfactorThe vertical scale factor. It's a float to allow for fractional scale even for integer ranges.
Returns
a reference to this instance

Referenced by gnash::geometry::SnappingRanges2d< T >::Scale::operator()().

§ scale() [2/2]

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::scale ( float  factor)
inline

Scale this Range2d in both directions with the same factor.

§ scaleX()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::scaleX ( float  factor)
inline

Scale this Range2d horizontally.

§ scaleY()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::scaleY ( float  factor)
inline

Scale this Range2d vertically.

§ setNull()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::setNull ( )
inline

Set the Range2d to the NULL value.

Returns
a reference to this instance

Referenced by gnash::geometry::SnappingRanges2d< std::int32_t >::getFullArea().

§ setTo() [1/2]

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::setTo ( x,
y 
)
inline

§ setTo() [2/2]

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::setTo ( xmin,
ymin,
xmax,
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

§ setWorld()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::setWorld ( )
inline

Set the Range2d to the WORLD value.

This is implemented using the minimum and maximum values of the parameter type.

See RangeType::worldRange

Returns
a reference to this instance

§ shiftX()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::shiftX ( 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

§ shiftY()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::shiftY ( 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

§ shrinkBy()

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::shrinkBy ( 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
amountThe 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!

§ width()

template<typename T>
T gnash::geometry::Range2d< T >::width ( ) const
inline

Return width this Range2d.

Don't call this function on a WORLD rectangle!

Referenced by gnash::FltkAggGlue::draw(), gnash::Renderer_cairo::drawVideoFrame(), gnash::KdeAggGlue::render(), and gnash::GtkGui::setInvalidatedRegions().

Friends And Related Function Documentation

§ Intersection

template<typename T>
template<typename U >
Range2d<U> 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.

§ operator!=

template<typename T>
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

§ operator<<

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

Ouput operator.

§ operator==

template<typename T>
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

§ Union

template<typename T>
template<typename U >
Range2d<U> 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: