29#include "common/Interval.h"
39 template<
typename Valtype>
42 typedef Valtype value_type;
56 Rect( Valtype width, Valtype height ) noexcept;
57 Rect( const
common::Interval<Valtype>& width, const
common::Interval<Valtype>& height ) noexcept;
58 explicit
Rect( const
Vector2D<Valtype>& diagonal ) noexcept;
60 Rect( Valtype left, Valtype top, Valtype right, Valtype bottom ) noexcept;
71 Rect& Init() noexcept;
73 Rect& Init( Valtype left, Valtype top, Valtype width, Valtype height ) noexcept;
78 bool Normal() const noexcept;
86 Valtype
Left() const noexcept;
90 Valtype
Top() const noexcept;
94 Valtype
Right() const noexcept;
98 Valtype
Bottom() const noexcept;
102 Rect&
Top( Valtype val ) noexcept;
114 Valtype
Width() const noexcept;
118 Valtype
Height() const noexcept;
122 auto
Area() const noexcept -> decltype(Valtype{}*Valtype{});
130 bool IsArea() const noexcept;
159 bool Includes( Valtype x, Valtype y ) const noexcept;
166 bool Includes( const Position2D<Valtype>& pt ) const noexcept;
173 Rect&
Expand( Valtype x, Valtype y ) noexcept;
180 Rect&
Expand( const Position2D<Valtype>& pt ) noexcept;
201 Rect& Move( Valtype dx, Valtype dy ) noexcept;
203 Rect& Move( const Vector2D<Valtype>& offset ) noexcept;
210 template<typename Valtype>
211 void operator+=(
Rect<Valtype>& r1, const
Rect<Valtype>& r2 ) noexcept;
212 template<typename Valtype>
213 Rect<Valtype> operator+( const
Rect<Valtype>& r1, const
Rect<Valtype>& r2 ) noexcept;
214 template<typename Valtype> constexpr
215 bool operator==( const
Rect<Valtype>& r1, const
Rect<Valtype>& r2 ) noexcept;
216 template<typename Valtype> constexpr
217 bool operator!=( const
Rect<Valtype>& r1, const
Rect<Valtype>& r2 ) noexcept;
223 template<typename Valtype>
228template<typename Valtype> inline
229Rect<Valtype>::
Rect( Valtype width, Valtype height ) noexcept
234template<
typename Valtype>
inline
240template<
typename Valtype>
inline
242 :
m_Width {-diagonal.dx/2,diagonal.dx/2},
243 m_Height{-diagonal.dy/2,diagonal.dy/2}
246template<
typename Valtype>
inline
248 :
m_Width {lefttop.x,rightbottom.x},
252template<
typename Valtype>
inline
258template<
typename Valtype>
inline
265template<
typename Valtype>
inline
272template<
typename Valtype>
inline
277template<
typename Valtype>
inline
284template<
typename Valtype>
inline
289template<
typename Valtype>
inline
294template<
typename Valtype>
inline
299template<
typename Valtype>
inline
304template<
typename Valtype>
inline
310template<
typename Valtype>
inline
316template<
typename Valtype>
inline
322template<
typename Valtype>
inline
328template<
typename Valtype>
inline
333template<
typename Valtype>
inline
338template<
typename Valtype>
inline
343template<
typename Valtype>
inline
348template<
typename Valtype>
inline
353template<
typename Valtype>
inline
358template<
typename Valtype>
inline
363template<
typename Valtype>
inline
368template<
typename Valtype>
inline
373template<
typename Valtype>
inline
378template<
typename Valtype>
inline
382 m_Width.Union( r1.m_Width, r2.m_Width );
383 m_Height.Union( r1.m_Height, r2.m_Height );
387template<
typename Valtype>
inline
395template<
typename Valtype>
inline
399 m_Width.Intersection( r1.m_Width, r2.m_Width );
400 m_Height.Intersection( r1.m_Height, r2.m_Height );
404template<
typename Valtype>
inline
407 m_Width.Intersection( rect.m_Width );
408 m_Height.Intersection( rect.m_Height );
412template<
typename Valtype>
inline
417template<
typename Valtype>
inline
422template<
typename Valtype>
inline
429template<
typename Valtype>
inline
431 return Expand( pt.x, pt.y );
434template<
typename Valtype>
inline
441template<
typename Valtype>
inline
446template<
typename Valtype>
inline
447Rect<Valtype>& Rect<Valtype>::Move( Valtype dx, Valtype dy )
noexcept{
453template<
typename Valtype>
inline
454Rect<Valtype>& Rect<Valtype>::Move(
const Vector2D<Valtype>& offset )
noexcept{
455 return Move( offset.dx, offset.dy );
458template<
typename Valtype>
inline
463template<
typename Valtype>
inline
466 retval.Union( r1, r2 );
470template<
typename Valtype>
inline
475template<
typename Valtype>
constexpr
477 return r1.m_Width == r2.m_Width && r1.m_Height == r2.m_Height;
480template<
typename Valtype>
constexpr
Namespace of common utility classes and methods.
Definition Helpers.h:43
constexpr bool operator!=(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:701
constexpr Interval< Valtype > operator+(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:591
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
Position< Valtype > & operator+=(Position< Valtype > &, const Position< Valtype > &)=delete
Position operator.
bool Intersect(const Rect< Valtype > &r1, const Rect< Valtype > &r2) noexcept
Definition Rect.h:471
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
Implements a 2D - position in cartesian coordinates.
Definition Position2D.h:45
Axis aligned rectangle.
Definition Rect.h:41
bool IsArea() const noexcept
Is non zero area?
Definition Rect.h:374
Position2D< Valtype > RightTop() const noexcept
Definition Rect.h:344
Rect & Inflate(Valtype dx, Valtype dy) noexcept
Moves the edges to the outside of the rect, thereyby inflating it.
Definition Rect.h:435
common::Interval< Valtype > m_Width
X dimension.
Definition Rect.h:44
Valtype Left() const noexcept
Definition Rect.h:285
Position2D< Valtype > RightBottom() const noexcept
Definition Rect.h:339
Rect & Union(const Rect &r1, const Rect &r2) noexcept
Calculates the union of the two rects.
Definition Rect.h:379
Valtype Top() const noexcept
Definition Rect.h:290
Position2D< Valtype > LeftTop() const noexcept
Definition Rect.h:329
bool Includes(Valtype x, Valtype y) const noexcept
Definition Rect.h:413
Valtype Bottom() const noexcept
Definition Rect.h:300
Valtype Height() const noexcept
Definition Rect.h:359
Valtype Right() const noexcept
Definition Rect.h:295
auto Area() const noexcept -> decltype(Valtype{} *Valtype{})
Definition Rect.h:364
Position2D< Valtype > Center() const noexcept
Definition Rect.h:349
Rect() noexcept=default
Does not initialize the members.
Rect & Deflate(Valtype dx, Valtype dy) noexcept
Moves the edges to the inward side of the rect, thereyby deflating it.
Definition Rect.h:442
common::Interval< Valtype > m_Height
Y dimension.
Definition Rect.h:45
Rect & Intersection(const Rect &r1, const Rect &r2) noexcept
Calculates the intersection rect of r1 and r2.
Definition Rect.h:396
Rect & Expand(Valtype x, Valtype y) noexcept
Expands the rect so that it touches (being included or laying on border) the point.
Definition Rect.h:423
Valtype Width() const noexcept
Definition Rect.h:354
Rect & Normalize() noexcept
make bottom <= top and left <= right
Definition Rect.h:278
Position2D< Valtype > LeftBottom() const noexcept
Definition Rect.h:334
bool Normal() const noexcept
is bottom <= top and left <= right
Definition Rect.h:273
Valtype Diagonal() const noexcept
Definition Rect.h:369
Implements a 2D - vector in cartesian coordinates.
Definition Vector2D.h:46