Gnash
0.8.11dev
|
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... | |
T | width () const |
Return width this Range2d. More... | |
T | 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... | |
T | getMinX () const |
Get min X ordinate. More... | |
T | getMaxX () const |
Get max X ordinate. More... | |
T | getMinY () const |
Get min Y ordinate. More... | |
T | 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... | |
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.
|
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
|
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.
|
inline |
Templated copy constructor, for casting between range types.
|
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()().
|
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.
|
inline |
Expand this Range2d to enclose the given point.
Referenced by gnash::geometry::SnappingRanges2d< std::int32_t >::getFullArea(), gnash::geometry::SnappingRanges2d< T >::ExpandToIfSnap::operator()(), gnash::geometry::operator<<(), gnash::SWFMatrix::transform(), and gnash::geometry::Union().
|
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.
|
inline |
Expand this Range2d to enclose the given circle.
|
inline |
Get area (width*height)
Referenced by gnash::geometry::operator<<().
|
inline |
Specialization of area value for int type.
Add one.
|
inline |
Specialization of area value for unsigned int type.
Add one.
|
inline |
Get max X ordinate.
Don't call this against a NULL or WORLD Range2d
Referenced by gnash::Renderer_cairo::begin_display(), gnash::Gui::notify_key_event(), gnash::Renderer::pixel_to_world(), gnash::geometry::Range2d< int >::Range2d(), gnash::SdlAggGlue::render(), gnash::AOS4AggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::HaikuAggGlue::render(), gnash::Gui::setInvalidatedRegions(), gnash::SWFMatrix::transform(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), and gnash::Renderer::world_to_pixel().
|
inline |
Get max Y ordinate.
Don't call this against a NULL or WORLD Range2d
Referenced by gnash::Renderer_cairo::begin_display(), gnash::Gui::notify_key_event(), gnash::Renderer::pixel_to_world(), gnash::geometry::Range2d< int >::Range2d(), gnash::SdlAggGlue::render(), gnash::AOS4AggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::HaikuAggGlue::render(), gnash::Gui::setInvalidatedRegions(), gnash::SWFMatrix::transform(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), and gnash::Renderer::world_to_pixel().
|
inline |
Get min X ordinate.
Don't call this against a NULL or WORLD Range2
Referenced by gnash::Renderer_cairo::begin_display(), gnash::FltkAggGlue::draw(), gnash::Renderer_cairo::drawVideoFrame(), gnash::Gui::notify_key_event(), gnash::Renderer::pixel_to_world(), gnash::geometry::Range2d< int >::Range2d(), gnash::SdlAggGlue::render(), gnash::AOS4AggGlue::render(), gnash::KdeAggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::HaikuAggGlue::render(), gnash::GtkGui::setInvalidatedRegions(), gnash::Gui::setInvalidatedRegions(), gnash::SWFMatrix::transform(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), and gnash::Renderer::world_to_pixel().
|
inline |
Get min Y ordinate.
Don't call this against a NULL or WORLD Range2d
Referenced by gnash::Renderer_cairo::begin_display(), gnash::FltkAggGlue::draw(), gnash::Renderer_cairo::drawVideoFrame(), gnash::Gui::notify_key_event(), gnash::Renderer::pixel_to_world(), gnash::geometry::Range2d< int >::Range2d(), gnash::SdlAggGlue::render(), gnash::AOS4AggGlue::render(), gnash::KdeAggGlue::render(), gnash::AOS4CairoGlue::render(), gnash::HaikuAggGlue::render(), gnash::GtkGui::setInvalidatedRegions(), gnash::Gui::setInvalidatedRegions(), gnash::SWFMatrix::transform(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), and gnash::Renderer::world_to_pixel().
|
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::SnappingRanges2d< T >::GrowBy::operator()().
|
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().
|
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<<().
|
inline |
Returns true if this is a finite Range2d.
See RangeKind::finiteRange
Referenced by gnash::KdeAggGlue::render(), gnash::FltkGui::renderBuffer(), gnash::KdeAggGlue::setInvalidatedRegions(), gnash::FltkGui::setInvalidatedRegions(), gnash::Qt4Gui::setInvalidatedRegions(), gnash::GtkGui::setInvalidatedRegions(), and gnash::Gui::setInvalidatedRegions().
|
inline |
Returns true if this is the NULL Range2d.
Referenced by gnash::geometry::SnappingRanges2d< std::int32_t >::add(), gnash::Renderer_cairo::begin_display(), gnash::geometry::Range2d< int >::contains(), gnash::geometry::Range2d< int >::expandTo(), gnash::geometry::SnappingRanges2d< std::int32_t >::intersect(), gnash::geometry::Intersection(), gnash::geometry::Range2d< int >::intersects(), gnash::geometry::operator==(), gnash::geometry::Range2d< int >::Range2d(), gnash::SdlAggGlue::setInvalidatedRegions(), gnash::AOS4AggGlue::setInvalidatedRegions(), gnash::KdeAggGlue::setInvalidatedRegions(), gnash::AOS4CairoGlue::setInvalidatedRegions(), gnash::HaikuAggGlue::setInvalidatedRegions(), gnash::FltkGui::setInvalidatedRegions(), gnash::gui::FBOvgGlue::setInvalidatedRegions(), gnash::gui::FBAggGlue::setInvalidatedRegions(), gnash::Qt4Gui::setInvalidatedRegions(), gnash::GtkGui::setInvalidatedRegions(), test_geometry(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), and gnash::Renderer::world_to_pixel().
|
inline |
Returns true if this is the WORLD Range2d.
Referenced by gnash::geometry::SnappingRanges2d< std::int32_t >::add(), gnash::Renderer_cairo::begin_display(), gnash::geometry::Range2d< int >::contains(), gnash::geometry::Range2d< int >::expandTo(), gnash::geometry::SnappingRanges2d< std::int32_t >::intersect(), gnash::geometry::Intersection(), gnash::geometry::Range2d< int >::intersects(), gnash::geometry::operator==(), gnash::geometry::Range2d< int >::Range2d(), gnash::Gui::setInvalidatedRegions(), gnash::renderer::DirectFB::Renderer_DirectFB::world_to_pixel(), gnash::renderer::openvg::Renderer_ovg::world_to_pixel(), gnash::renderer::gles1::Renderer_gles1::world_to_pixel(), and gnash::Renderer::world_to_pixel().
|
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::SnappingRanges2d< T >::Scale::operator()().
|
inline |
Scale this Range2d in both directions with the same factor.
|
inline |
Scale this Range2d horizontally.
|
inline |
Scale this Range2d vertically.
|
inline |
Set the Range2d to the NULL value.
Referenced by gnash::geometry::SnappingRanges2d< std::int32_t >::getFullArea().
|
inline |
Set ourself to bound the given point.
Referenced by gnash::gui::FBAggGlue::createRenderHandler(), gnash::GtkGui::createWindow(), gnash::DumpGui::createWindow(), gnash::Qt4Gui::createWindow(), gnash::gui::FBGui::init(), gnash::KdeAggGlue::initBuffer(), gnash::FltkAggGlue::initBuffer(), gnash::SdlAggGlue::prepDrawingArea(), gnash::HaikuAggGlue::prepDrawingArea(), gnash::Gui::resize_view(), and gnash::SWFMatrix::transform().
|
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.
|
inline |
Set the Range2d to the WORLD value.
This is implemented using the minimum and maximum values of the parameter type.
See RangeType::worldRange
|
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
|
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
|
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!
|
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().
|
friend |
Return a rectangle being the intersetion of the two rectangles.
Any NULL operand will make the result also NULL.
|
friend |
Inequality operator.
This is needed to take NULL kind into account since we don't explicitly set all members when constructing NULL ranges
|
friend |
Ouput operator.
|
friend |
Equality operator.
This is needed to take NULL kind into account since we don't explicitly set all members when constructing NULL ranges
|
friend |
Return a rectangle being the union of the two rectangles.