Gnash
0.8.10
|
2d Range template class More...
#include <Range2d.h>
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. | |
T | width () const |
Return width this Range2d. | |
T | 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. | |
T | getMinX () const |
Get min X ordinate. | |
T | getMaxX () const |
Get max X ordinate. | |
T | getMinY () const |
Get min Y ordinate. | |
T | getMaxY () const |
Get max Y ordinate. | |
T | 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. |
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.
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.
gnash::geometry::Range2d::Range2d | ( | const Range2d< U > & | from | ) | [inline] |
Templated copy constructor, for casting between range types.
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.
Referenced by gnash::geometry::SnappingRanges2d::ContainsPoint::operator()(), and gnash::geometry::SnappingRanges2d::ContainsRange::operator()().
bool gnash::geometry::Range2d::contains | ( | const Range2d< T > & | other | ) | const [inline] |
Return true if this rectangle contains the given rectangle.
Note that:
Range2d<T>& gnash::geometry::Range2d::expandTo | ( | T | x, |
T | y | ||
) | [inline] |
Expand this Range2d to enclose the given point.
Referenced by gnash::geometry::Range2d< int >::expandToCircle(), gnash::geometry::SnappingRanges2d::ExpandToIfSnap::operator()(), gnash::geometry::SnappingRanges2d< T >::getFullArea(), and gnash::SWFMatrix::transform().
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<T>& gnash::geometry::Range2d::expandToCircle | ( | T | x, |
T | y, | ||
T | radius | ||
) | [inline] |
Expand this Range2d to enclose the given circle.
T gnash::geometry::Range2d::getArea | ( | ) | const [inline] |
Get area (width*height)
int gnash::geometry::Range2d< int >::getArea | ( | ) | const [inline] |
Add one.
References assert.
unsigned int gnash::geometry::Range2d< unsigned int >::getArea | ( | ) | const [inline] |
Add one.
References assert, and gnash::isFinite().
T gnash::geometry::Range2d::getMaxX | ( | ) | const [inline] |
Get max X ordinate.
Don't call this against a NULL or WORLD Range2d
Referenced by gnash::AOS4AggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::Gui::setInvalidatedRegions(), gnash::HaikuAggGlue::render(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::Renderer::world_to_pixel(), gnash::Renderer::pixel_to_world(), gnash::Renderer_cairo::begin_display(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), gnash::SdlAggGlue::render(), and gnash::SWFMatrix::transform().
T gnash::geometry::Range2d::getMaxY | ( | ) | const [inline] |
Get max Y ordinate.
Don't call this against a NULL or WORLD Range2d
Referenced by gnash::AOS4AggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::Gui::setInvalidatedRegions(), gnash::HaikuAggGlue::render(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::Renderer::world_to_pixel(), gnash::Renderer::pixel_to_world(), gnash::Renderer_cairo::begin_display(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), gnash::SdlAggGlue::render(), and gnash::SWFMatrix::transform().
T gnash::geometry::Range2d::getMinX | ( | ) | const [inline] |
Get min X ordinate.
Don't call this against a NULL or WORLD Range2
Referenced by gnash::AOS4AggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::FltkAggGlue::draw(), gnash::GtkGui::setInvalidatedRegions(), gnash::Gui::setInvalidatedRegions(), gnash::HaikuAggGlue::render(), gnash::KdeAggGlue::render(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::Renderer::world_to_pixel(), gnash::Renderer::pixel_to_world(), gnash::Renderer_cairo::drawVideoFrame(), gnash::Renderer_cairo::begin_display(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), gnash::SdlAggGlue::render(), and gnash::SWFMatrix::transform().
T gnash::geometry::Range2d::getMinY | ( | ) | const [inline] |
Get min Y ordinate.
Don't call this against a NULL or WORLD Range2d
Referenced by gnash::AOS4AggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::FltkAggGlue::draw(), gnash::GtkGui::setInvalidatedRegions(), gnash::Gui::setInvalidatedRegions(), gnash::HaikuAggGlue::render(), gnash::KdeAggGlue::render(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::Renderer::world_to_pixel(), gnash::Renderer::pixel_to_world(), gnash::Renderer_cairo::drawVideoFrame(), gnash::Renderer_cairo::begin_display(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), gnash::SdlAggGlue::render(), and gnash::SWFMatrix::transform().
Range2d<T>& 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.
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(). |
Referenced by gnash::geometry::Range2d< int >::shrinkBy(), and gnash::geometry::SnappingRanges2d::GrowBy::operator()().
T gnash::geometry::Range2d::height | ( | ) | const [inline] |
Return height this Range2dangle.
Don't call this function on a WORLD rectangle!
Referenced by gnash::gui::FBGui::run(), gnash::FltkAggGlue::draw(), gnash::GtkGui::setInvalidatedRegions(), gnash::KdeAggGlue::render(), and gnash::Renderer_cairo::drawVideoFrame().
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.
Referenced by gnash::geometry::SnappingRanges2d::IntersectsRange::operator()().
bool gnash::geometry::Range2d::isFinite | ( | ) | const [inline] |
Returns true if this is a finite Range2d.
See RangeKind::finiteRange
Referenced by gnash::FltkGui::renderBuffer(), gnash::FltkGui::setInvalidatedRegions(), gnash::GtkGui::setInvalidatedRegions(), gnash::Gui::setInvalidatedRegions(), gnash::KdeAggGlue::render(), gnash::KdeAggGlue::setInvalidatedRegions(), gnash::Qt4Gui::setInvalidatedRegions(), gnash::geometry::Range2d< int >::scale(), gnash::geometry::Range2d< int >::getMinX(), gnash::geometry::Range2d< int >::getMaxX(), gnash::geometry::Range2d< int >::getMinY(), and gnash::geometry::Range2d< int >::getMaxY().
bool gnash::geometry::Range2d::isNull | ( | ) | const [inline] |
Returns true if this is the NULL Range2d.
Referenced by gnash::AOS4AggGlue::setInvalidatedRegions(), gnash::AOS4CairoGlue::setInvalidatedRegions(), gnash::gui::FBAggGlue::setInvalidatedRegions(), gnash::gui::FBOvgGlue::setInvalidatedRegions(), gnash::FltkGui::setInvalidatedRegions(), gnash::GtkGui::setInvalidatedRegions(), gnash::HaikuAggGlue::setInvalidatedRegions(), gnash::KdeAggGlue::setInvalidatedRegions(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::Qt4Gui::setInvalidatedRegions(), gnash::geometry::Range2d< int >::isFinite(), gnash::geometry::Range2d< int >::contains(), gnash::geometry::Range2d< int >::intersects(), gnash::geometry::Range2d< int >::expandTo(), gnash::geometry::Range2d< int >::width(), gnash::geometry::Range2d< int >::height(), gnash::geometry::Range2d< int >::shiftX(), gnash::geometry::Range2d< int >::shiftY(), gnash::geometry::Range2d< int >::growBy(), gnash::geometry::Range2d< int >::shrinkBy(), gnash::geometry::Range2d< int >::getArea(), gnash::Renderer::world_to_pixel(), gnash::Renderer_cairo::begin_display(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), gnash::SdlAggGlue::setInvalidatedRegions(), gnash::geometry::SnappingRanges2d< T >::add(), gnash::geometry::SnappingRanges2d< T >::intersect(), and test_geometry().
bool gnash::geometry::Range2d::isWorld | ( | ) | const [inline] |
Returns true if this is the WORLD Range2d.
Referenced by gnash::Gui::setInvalidatedRegions(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::geometry::Range2d< int >::isFinite(), gnash::geometry::Range2d< int >::contains(), gnash::geometry::Range2d< int >::intersects(), gnash::geometry::Range2d< int >::expandTo(), gnash::geometry::Range2d< int >::expandToCircle(), gnash::geometry::Range2d< int >::width(), gnash::geometry::Range2d< int >::height(), gnash::geometry::Range2d< int >::shiftX(), gnash::geometry::Range2d< int >::shiftY(), gnash::geometry::Range2d< int >::growBy(), gnash::geometry::Range2d< int >::shrinkBy(), gnash::geometry::Range2d< int >::getArea(), gnash::Renderer::world_to_pixel(), gnash::Renderer_cairo::begin_display(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), gnash::geometry::SnappingRanges2d< T >::add(), and gnash::geometry::SnappingRanges2d< T >::intersect().
Range2d<T>& 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!).
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. |
Referenced by gnash::geometry::Range2d< int >::scaleX(), gnash::geometry::Range2d< int >::scaleY(), gnash::geometry::Range2d< int >::scale(), and gnash::geometry::SnappingRanges2d::Scale::operator()().
Range2d<T>& gnash::geometry::Range2d::scale | ( | float | factor | ) | [inline] |
Scale this Range2d in both directions with the same factor.
Range2d<T>& gnash::geometry::Range2d::scaleX | ( | float | factor | ) | [inline] |
Scale this Range2d horizontally.
Range2d<T>& gnash::geometry::Range2d::scaleY | ( | float | factor | ) | [inline] |
Scale this Range2d vertically.
Range2d<T>& gnash::geometry::Range2d::setNull | ( | ) | [inline] |
Set the Range2d to the NULL value.
Referenced by gnash::geometry::Range2d< int >::Range2d(), gnash::geometry::Range2d< int >::scale(), gnash::geometry::Range2d< int >::shrinkBy(), and gnash::geometry::SnappingRanges2d< T >::getFullArea().
Range2d<T>& gnash::geometry::Range2d::setTo | ( | T | x, |
T | y | ||
) | [inline] |
Set ourself to bound the given point.
Referenced by gnash::AOS4AggGlue::prepDrawingArea(), gnash::AOS4CairoGlue::prepDrawingArea(), gnash::DumpGui::createWindow(), gnash::gui::FBGui::init(), gnash::gui::FBAggGlue::createRenderHandler(), gnash::FltkAggGlue::initBuffer(), gnash::GtkGui::createWindow(), gnash::Gui::resize_view(), gnash::HaikuAggGlue::prepDrawingArea(), gnash::KdeAggGlue::initBuffer(), gnash::Qt4Gui::createWindow(), gnash::geometry::Range2d< int >::expandTo(), gnash::SdlAggGlue::prepDrawingArea(), and gnash::SWFMatrix::transform().
Range2d<T>& 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.
Range2d<T>& 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
Referenced by gnash::geometry::Range2d< int >::Range2d(), gnash::geometry::Range2d< int >::growBy(), and gnash::geometry::Range2d< int >::expandTo().
Range2d<T>& 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
Range2d<T>& 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
Range2d<T>& 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.
amount | The amount of T to shink this range in all directions. If negative the range will grow. See growBy(). |
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!
Referenced by gnash::gui::FBGui::run(), gnash::FltkAggGlue::draw(), gnash::GtkGui::setInvalidatedRegions(), gnash::KdeAggGlue::render(), and gnash::Renderer_cairo::drawVideoFrame().
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.
Inequality operator.
This is needed to take NULL kind into account since we don't explicitly set all members when constructing NULL ranges
std::ostream& operator<< | ( | std::ostream & | os, |
const Range2d< U > & | rect | ||
) | [friend] |
Ouput operator.
Equality operator.
This is needed to take NULL kind into account since we don't explicitly set all members when constructing NULL ranges
Range2d<U> Union | ( | const Range2d< U > & | r1, |
const Range2d< U > & | r2 | ||
) | [friend] |
Return a rectangle being the union of the two rectangles.