Public Member Functions | Friends

gnash::geometry::Range2d< T > Class Template Reference

2d Range template class More...

#include <Range2d.h>

Inheritance diagram for gnash::geometry::Range2d< T >:
Inheritance graph
[legend]

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

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

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

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.

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

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< boost::int32_t >::add(), and main().

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.
template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::expandTo ( x,
y 
) [inline]
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.

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

Referenced by main().

template<typename T>
T gnash::geometry::Range2d< T >::getArea (  )  const [inline]

Get area (width*height)

template<>
int gnash::geometry::Range2d< int >::getArea (  )  const [inline]
template<>
unsigned int gnash::geometry::Range2d< unsigned int >::getArea (  )  const [inline]
template<typename T>
T gnash::geometry::Range2d< T >::getMaxX (  )  const [inline]
template<typename T>
T gnash::geometry::Range2d< T >::getMaxY (  )  const [inline]
template<typename T>
T gnash::geometry::Range2d< T >::getMinX (  )  const [inline]
template<typename T>
T gnash::geometry::Range2d< T >::getMinY (  )  const [inline]
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:
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

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

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(), and gnash::FBGui::run().

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(), and gnash::geometry::Intersection().

template<typename T>
bool gnash::geometry::Range2d< T >::isFinite (  )  const [inline]
template<typename T>
bool gnash::geometry::Range2d< T >::isNull (  )  const [inline]
template<typename T>
bool gnash::geometry::Range2d< T >::isWorld (  )  const [inline]
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:
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

Referenced by gnash::geometry::Range2d< int >::scale(), gnash::geometry::Range2d< int >::scaleX(), and gnash::geometry::Range2d< int >::scaleY().

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

Scale this Range2d in both directions with the same factor.

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

Scale this Range2d horizontally.

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

Scale this Range2d vertically.

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::Range2d< int >::Range2d(), gnash::geometry::Range2d< int >::scale(), and gnash::geometry::Range2d< int >::shrinkBy().

template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::setTo ( x,
y 
) [inline]
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
template<typename T>
Range2d<T>& gnash::geometry::Range2d< T >::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

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

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
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
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:
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().

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::FBGui::renderBuffer(), and gnash::FBGui::run().


Friends And Related Function Documentation

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.

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

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

Ouput 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

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: