X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGRect.hxx;h=86dd482c9c8875c54bdd848abff6fe2df6656e32;hb=8c38f799adf4f4ece8c79dd1e6ff5a75d85a17dc;hp=ad5771e9c803c37c6bdabc24f24c72c51b9c0b96;hpb=8896a59dff3a5efc5d5be3e999e662bf0f174b60;p=simgear.git diff --git a/simgear/math/SGRect.hxx b/simgear/math/SGRect.hxx index ad5771e9..86dd482c 100644 --- a/simgear/math/SGRect.hxx +++ b/simgear/math/SGRect.hxx @@ -34,7 +34,7 @@ class SGRect } - SGRect(const SGVec2& pt): + explicit SGRect(const SGVec2& pt): _min(pt), _max(pt) { @@ -88,11 +88,15 @@ class SGRect T y() const { return _min.y(); } T width() const { return _max.x() - _min.x(); } T height() const { return _max.y() - _min.y(); } + SGVec2 const& pos() const { return _min; } + SGVec2 size() const { return SGVec2(width(), height()); } void setX(T x) { T w = width(); _min.x() = x; _max.x() = x + w; } void setY(T y) { T h = height(); _min.y() = y; _max.y() = y + h; } void setWidth(T w) { _max.x() = _min.x() + w; } void setHeight(T h) { _max.y() = _min.y() + h; } + void setPos(const SGVec2& p) { setX(p.x()); setY(p.y()); } + void setSize(const SGVec2& s) { setWidth(s.x()); setHeight(s.y()); } T l() const { return _min.x(); } T r() const { return _max.x(); } @@ -109,6 +113,18 @@ class SGRect void setTop(T t) { _min.y() = t; } void setBottom(T b) { _max.y() = b; } + /** + * Expand rectangle to include the given position + */ + void expandBy(T x, T y) + { + if( x < _min.x() ) _min.x() = x; + if( x > _max.x() ) _max.x() = x; + + if( y < _min.y() ) _min.y() = y; + if( y > _max.y() ) _max.y() = y; + } + /** * Move rect by vector */ @@ -129,6 +145,17 @@ class SGRect return *this; } + bool operator==(const SGRect& rhs) const + { + return _min == rhs._min + && _max == rhs._max; + } + + bool operator!=(const SGRect& rhs) const + { + return !(*this == rhs); + } + bool contains(T x, T y) const { return _min.x() <= x && x <= _max.x() @@ -176,4 +203,8 @@ std::basic_ostream& operator<<(std::basic_ostream& s, const SGRect& rect) { return s << "min = " << rect.getMin() << ", max = " << rect.getMax(); } +typedef SGRect SGRecti; +typedef SGRect SGRectf; +typedef SGRect SGRectd; + #endif /* SG_RECT_HXX_ */