Go to the documentation of this file.
23 #ifndef GNASH_RANGE2D_H
24 #define GNASH_RANGE2D_H
58 template <>
struct Promote<int> {
typedef std::int64_t
type; };
59 template <>
struct Promote<unsigned int> {
typedef std::uint64_t
type; };
100 template <
typename U>
159 assert(_xmin <= _xmax);
160 assert(_ymin <= _ymax);
165 template <
typename U>
170 }
else if ( from.
isNull() ) {
173 _xmin = roundMin(from.
getMinX());
174 _ymin = roundMin(from.
getMinY());
175 _xmax = roundMax(from.
getMaxX());
176 _ymax = roundMax(from.
getMaxY());
183 return _xmax < _xmin;
192 _xmin = std::numeric_limits<T>::max();
193 _xmax = std::numeric_limits<T>::min();
202 return _xmax == std::numeric_limits<T>::max()
203 && _xmin == std::numeric_limits<T>::min();
226 _xmin = std::numeric_limits<T>::min();
227 _xmax = std::numeric_limits<T>::max();
240 template <
typename U>
243 if (
isNull() )
return false;
245 if (x < _xmin || x > _xmax || y < _ymin || y > _ymax)
266 if ( other.
isWorld() )
return false;
268 return _xmin <= other._xmin &&
269 _xmax >= other._xmax &&
270 _ymin <= other._ymin &&
271 _ymax >= other._ymax;
286 if ( _xmin > other._xmax )
return false;
287 if ( _xmax < other._xmin )
return false;
288 if ( _ymin > other._ymax )
return false;
289 if ( _ymax < other._ymin )
return false;
308 _xmin = std::min(_xmin,
x);
309 _ymin = std::min(_ymin,
y);
310 _xmax = std::max(_xmax,
x);
311 _ymax = std::max(_ymax,
y);
364 assert(_xmin <= _xmax);
365 assert(_ymin <= _ymax);
429 return scale(factor, 1);
435 return scale(1, factor);
473 assert(xfactor >= 0 && yfactor >= 0);
477 if ( xfactor == 0 || yfactor == 0 )
484 _xmin = scaleMin(_xmin, xfactor);
485 _xmax = scaleMax(_xmax, xfactor);
486 assert(_xmin <= _xmax);
491 _ymin = scaleMin(_ymin, yfactor);
492 _ymax = scaleMax(_ymax, yfactor);
493 assert(_ymin <= _ymax);
502 return scale(factor, factor);
527 if ( amount < 0 )
return shrinkBy(-amount);
529 T newxmin = _xmin - amount;
530 if (newxmin > _xmin )
return setWorld();
531 else _xmin = newxmin;
533 T newxmax = _xmax + amount;
534 if (newxmax < _xmax )
return setWorld();
535 else _xmax = newxmax;
537 T newymin = _ymin - amount;
538 if (newymin > _ymin )
return setWorld();
539 else _ymin = newymin;
541 T newymax = _ymax + amount;
542 if (newymax < _ymax )
return setWorld();
543 else _ymax = newymax;
580 if ( amount < 0 )
return growBy(-amount);
587 if ( _xmax - _xmin <= amount )
return setNull();
588 if ( _ymax - _ymin <= amount )
return setNull();
679 _xmin = std::min(_xmin,
r._xmin);
680 _xmax = std::max(_xmax,
r._xmax);
681 _ymin = std::min(_ymin,
r._ymin);
682 _ymax = std::max(_ymax,
r._ymax);
688 T _xmin, _xmax, _ymin, _ymax;
690 T scaleMin(
T min,
float scale)
const {
691 return roundMin(
static_cast<float>(min) *
scale);
694 T scaleMax(
T max,
float scale)
const {
695 return roundMax(
static_cast<float>(max) *
scale);
698 T roundMin(
float v)
const {
699 return static_cast<T>(
v);
702 T roundMax(
float v)
const {
703 return static_cast<T>(
v);
709 template <
typename T>
inline std::ostream&
712 if ( rect.
isNull() )
return os <<
"Null range";
713 if ( rect.
isWorld() )
return os <<
"World range";
715 return os <<
"Finite range (" << rect._xmin <<
"," << rect._ymin
716 <<
" " << rect._xmax <<
"," << rect._ymax <<
")";
719 template <
typename T>
inline bool
731 return r1._xmin == r2._xmin && r1._ymin == r2._ymin &&
732 r1._xmax == r2._xmax && r1._ymax == r2._ymax;
735 template <
typename T>
inline bool
738 return ! ( r1 == r2 );
742 template <
typename T>
inline bool
749 template <
typename T>
inline Range2d<T>
761 template <
typename T>
inline Range2d<T>
785 std::max(r1._xmin, r2._xmin),
786 std::max(r1._ymin, r2._ymin),
787 std::min(r1._xmax, r2._xmax),
788 std::min(r1._ymax, r2._ymax)
797 template<>
inline int
798 Range2d<int>::roundMin(
float min)
const
800 return static_cast<int>(std::floor(min));
807 template<>
inline unsigned int
808 Range2d<unsigned int>::roundMin(
float min)
const
810 return static_cast<unsigned int>(std::floor(min));
817 template<>
inline int
818 Range2d<int>::roundMax(
float max)
const
820 return static_cast<int>(std::ceil(max));
827 template<>
inline unsigned int
828 Range2d<unsigned int>::roundMax(
float max)
const
830 return static_cast<unsigned int>(std::ceil(max));
841 assert ( !isWorld() );
842 if ( isNull() )
return 0;
864 #endif // GNASH_RANGE2D_H
Range2d< T > & growBy(T amount)
Grow this range by the given amout in all directions.
Definition: Range2d.h:520
2d Range template class
Definition: Range2d.h:78
friend bool operator==(const Range2d< U > &r1, const Range2d< U > &r2)
Equality operator.
bool contains(const Range2d< T > &other) const
Return true if this rectangle contains the given rectangle.
Definition: Range2d.h:262
Range2d< T > Union(const Range2d< T > &r1, const Range2d< T > &r2)
Return a rectangle being the union of the two rectangles.
Definition: Range2d.h:750
friend std::ostream & operator<<(std::ostream &os, const Range2d< U > &rect)
Ouput operator.
friend Range2d< U > Intersection(const Range2d< U > &r1, const Range2d< U > &r2)
Return a rectangle being the intersetion of the two rectangles.
@ U
Definition: GnashKey.h:133
Range2d< T > & scale(float xfactor, float yfactor)
Scale this Range2d.
Definition: Range2d.h:471
@ T
Definition: GnashKey.h:132
T getMaxY() const
Get max Y ordinate.
Definition: Range2d.h:633
Range2d< T > & setTo(T xmin, T ymin, T xmax, T ymax)
Set coordinates to given values.
Definition: Range2d.h:356
std::int32_t y
Definition: BitmapData_as.cpp:435
Range2d(T xmin, T ymin, T xmax, T ymax)
Construct a finite Range2d with the given values.
Definition: Range2d.h:151
Range2d< T > & scale(float factor)
Scale this Range2d in both directions with the same factor.
Definition: Range2d.h:500
friend Range2d< U > Union(const Range2d< U > &r1, const Range2d< U > &r2)
Return a rectangle being the union of the two rectangles.
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
T getMaxX() const
Get max X ordinate.
Definition: Range2d.h:613
Range2d< T > & scaleY(float factor)
Scale this Range2d vertically.
Definition: Range2d.h:433
bool operator!=(const Range2d< T > &r1, const Range2d< T > &r2)
Definition: Range2d.h:736
Range2d< T > & expandTo(T x, T y)
Expand this Range2d to enclose the given point.
Definition: Range2d.h:297
@ worldRange
A WORLD range2d is a range including all points on the plane.
Definition: Range2d.h:52
T getMinX() const
Get min X ordinate.
Definition: Range2d.h:603
Range2d< T > & shiftX(T offset)
Shift this Range2dangle horizontally.
Definition: Range2d.h:401
bool isNull() const
Returns true if this is the NULL Range2d.
Definition: Range2d.h:181
Range2d< T > & shiftY(T offset)
Shift this Range2dangle vertically.
Definition: Range2d.h:418
bool isFinite(double d)
Definition: GnashNumeric.h:47
@ finiteRange
Valid range, using finite values.
Definition: Range2d.h:40
Range2d< T > Intersection(const Range2d< T > &r1, const Range2d< T > &r2)
Return a rectangle being the intersetion of the two rectangles.
Definition: Range2d.h:762
bool isFinite() const
Returns true if this is a finite Range2d.
Definition: Range2d.h:210
Range2d< T > & setWorld()
Set the Range2d to the WORLD value.
Definition: Range2d.h:224
@ r
Definition: GnashKey.h:164
bool isWorld() const
Returns true if this is the WORLD Range2d.
Definition: Range2d.h:200
Range2d< T > & scaleX(float factor)
Scale this Range2d horizontally.
Definition: Range2d.h:427
Range2d(RangeKind kind=nullRange)
Construct a Range2d of the given kind.
Definition: Range2d.h:122
Range2d< T > & shrinkBy(T amount)
Shirnk this range by the given amout in all directions.
Definition: Range2d.h:573
type
Definition: GnashKey.h:330
bool operator==(const Range2d< T > &r1, const Range2d< T > &r2)
Definition: Range2d.h:720
T getMinY() const
Get min Y ordinate.
Definition: Range2d.h:623
T width() const
Return width this Range2d.
Definition: Range2d.h:374
@ nullRange
A NULL range is a range enclosing NO points.
Definition: Range2d.h:43
bool intersects(const Range2d< T > &other) const
Return true if this rectangle intersects the point with given coordinates (boundaries are inclusive).
Definition: Range2d.h:281
friend bool operator!=(const Range2d< U > &r1, const Range2d< U > &r2)
Inequality operator.
RangeKind
Kinds of a range.
Definition: Range2d.h:38
bool contains(U x, U y) const
Return true if this rectangle contains the point with given coordinates (boundaries are inclusive).
Definition: Range2d.h:241
void expandTo(const Range2d< T > &r)
Expand this range to include the given Range2d.
Definition: Range2d.h:657
T height() const
Return height this Range2dangle.
Definition: Range2d.h:385
Range2d< T > & setTo(T x, T y)
Set ourself to bound the given point.
Definition: Range2d.h:339
Range2d< T > & expandToCircle(T x, T y, T radius)
Expand this Range2d to enclose the given circle.
Definition: Range2d.h:321
detail::Promote< T >::type getArea() const
Get area (width*height)
Definition: Range2d.h:643
Range2d< T > & setNull()
Set the Range2d to the NULL value.
Definition: Range2d.h:190
std::int32_t x
Definition: BitmapData_as.cpp:434
std::ostream & operator<<(std::ostream &os, const Point2d &p)
Output operator.
Definition: Point2d.h:136
Range2d(const Range2d< U > &from)
Templated copy constructor, for casting between range types.
Definition: Range2d.h:166
bool Intersect(const Range2d< T > &r1, const Range2d< T > &r2)
Return true of the two ranges intersect (boundaries included)
Definition: Range2d.h:743