40 template<
typename T>
struct Box2;
150 template<
typename T>
struct Box2
154 #if (MTOOLS_TGX_EXTENSIONS)
155 #include <mtools/extensions/tgx/tgx_ext_Box2.inl>
178 constexpr Box2(
const T minx,
const T maxx,
const T miny,
const T maxy) :
minX(minx),
maxX(maxx),
minY(miny),
maxY(maxy)
244 if (std::is_integral<T>::value)
265 if (std::is_integral<T>::value)
413 (*this) = ((*this) & B);
478 (*this) = (*this) | v;
605 template<
typename T
float = DefaultFPType<T> >
inline Tfloat
ratio()
const
607 if (
isEmpty())
return (Tfloat)(-1);
608 return ((Tfloat)(
lx())) / ((Tfloat)(
ly()));
619 const T u =
lx() / 10;
622 const T v =
ly() / 10;
635 const T u =
lx() / 8;
638 const T v =
ly() / 8;
651 const T u =
lx() / 10;
664 const T u =
lx() / 10;
677 const T v =
ly() / 10;
690 const T v =
ly() / 10;
721 if (ratio() < B.
ratio())
724 C.
maxX = maxX - minX;
725 T ll = (T)(lx() / B.
ratio());
726 C.
minY = (ly() - ll) / 2;
727 C.
maxY = C.
minY + ll - (std::is_integral<T>::value ? 1 : 0);
732 C.
maxY = maxY - minY;
733 T ll = (T)(ly() * B.
ratio());
734 C.
minX = (lx() - ll) / 2;
735 C.
maxX = C.
minX + ll - (std::is_integral<T>::value ? 1 : 0);
744 if (ratio() > B.
ratio())
747 C.
maxX = maxX - minX;
748 T ll = (T)(lx() / B.
ratio());
749 C.
minY = (ly() - ll) / 2;
750 C.
maxY = C.
minY + ll - (std::is_integral<T>::value ? 1 : 0);
755 C.
maxY = maxY - minY;
756 T ll = (T)(ly() * B.
ratio());
757 C.
minX = (lx() - ll) / 2;
758 C.
maxX = C.
minX + ll - (std::is_integral<T>::value ? 1 : 0);
Anchor & operator|=(Anchor &a1, Anchor a2)
Enable bitwise |= operator for enum Anchor.
Definition: Box2.h:97
constexpr Anchor operator|(Anchor a1, Anchor a2)
Enable bitwise | operator for enum Anchor.
Definition: Box2.h:94
constexpr Anchor operator&(Anchor a1, Anchor a2)
Enable bitwise & operator for enum Anchor.
Definition: Box2.h:100
BoxSplit
Splitting of a box in half and quarters.
Definition: Box2.h:109
@ SPLIT_RIGHT
right half
Definition: Box2.h:111
@ SPLIT_BOTTOMRIGHT
bottom right quarter
Definition: Box2.h:117
@ SPLIT_BOTTOM
bottom half
Definition: Box2.h:113
@ SPLIT_TOPRIGHT
top right quarter
Definition: Box2.h:115
@ SPLIT_BOTTOMLEFT
bottom left quarter
Definition: Box2.h:116
@ SPLIT_LEFT
left half
Definition: Box2.h:110
@ SPLIT_TOPLEFT
top left quarter
Definition: Box2.h:114
@ SPLIT_TOP
top half
Definition: Box2.h:112
Anchor & operator&=(Anchor &a1, Anchor a2)
Enable bitwise &= operator for enum Anchor.
Definition: Box2.h:103
Anchor
Define the placement of an anchor point inside a box.
Definition: Box2.h:74
@ BASELINE
Baseline height (vertical alignement). only makes sense with a font (when drawing text),...
Definition: Box2.h:80
@ BOTTOMRIGHT
Bottom-right corner.
Definition: Box2.h:84
@ CENTERRIGHT
center point on the right side
Definition: Box2.h:86
@ TOPLEFT
Top-left corner.
Definition: Box2.h:81
@ TOPRIGHT
Top-right corner.
Definition: Box2.h:82
@ CENTERLEFT
center point on the left side
Definition: Box2.h:85
@ BOTTOM
Bottom side (vertical alignement)
Definition: Box2.h:79
@ CENTER
Center (vertical/horizontal alignement). This is the default placement if not specitified.
Definition: Box2.h:75
@ RIGHT
Right side (horizontal alignement)
Definition: Box2.h:77
@ CENTERBOTTOM
center point on the bottom side
Definition: Box2.h:88
@ BOTTOMLEFT
bottom-left corner
Definition: Box2.h:83
@ CENTERTOP
center point on the top side
Definition: Box2.h:87
@ DEFAULT_TEXT_ANCHOR
Default location for text anchoring.
Definition: Box2.h:89
@ TOP
Top side (vertical alignement)
Definition: Box2.h:78
@ LEFT
Left side (horizontal alignement)
Definition: Box2.h:76
Utility/miscellaneous functions used throughout the library.
TGX_INLINE T min(const T &a, const T &b)
Don't know why but faster than fminf() for floats.
Definition: Misc.h:180
TGX_INLINE T max(const T &a, const T &b)
Don't know why but much faster than fmaxf() for floats.
Definition: Misc.h:184
Generic 2D Box [specializations iBox2 , fBox2, dBox2].
Definition: Box2.h:151
bool equals(const Box2< T > &B) const
Return true if the boxes are equal.
Definition: Box2.h:283
Box2(const Box2< T > &B)=default
default copy constructor.
Box2< T > operator&(const Box2< T > &B) const
Return the intersection of this box and B.
Definition: Box2.h:386
T maxY
max vertical (Y) value (inclusive)
Definition: Box2.h:164
constexpr Box2()
default constructor: the box content is undefined.
Definition: Box2.h:170
void split(BoxSplit part)
Split the box in half or quarter.
Definition: Box2.h:531
bool operator==(const Box2< T > &B) const
Return true if the boxes are equal.
Definition: Box2.h:297
constexpr Box2(const T minx, const T maxx, const T miny, const T maxy)
Constructor with explicit dimensions.
Definition: Box2.h:178
Box2< T > operator+(const Vec2< T > &V) const
Return this box translated by vector v.
Definition: Box2.h:497
void operator-=(const Vec2< T > &V)
Translate the box by a given vector (substracted)
Definition: Box2.h:506
void left()
Move the box to the left by 1/10th of its width.
Definition: Box2.h:649
Box2< T > getSplit(BoxSplit part) const
Return the box splitted in half or quater.
Definition: Box2.h:544
void down()
Move the box down by 1/10th of its height.
Definition: Box2.h:688
Vec2< T > getAnchor(Anchor anchor_pos) const
Return the position of an anchor point inside this box.
Definition: Box2.h:568
void up()
Move the box up by 1/10th of its height.
Definition: Box2.h:675
Box2< T > operator-(const Vec2< T > &V) const
Return this box translated by v (substracted).
Definition: Box2.h:518
bool operator>(const Box2< T > &B) const
Return true if B is strictly included in this box (i.e.
Definition: Box2.h:364
T ly() const
Return the box height.
Definition: Box2.h:263
Tfloat ratio() const
Return the aspect ratio of the box lx()/ly().
Definition: Box2.h:605
bool operator<(const Box2< T > &B) const
Return true if this box is strictly included inside B (i.e.
Definition: Box2.h:377
Box2< T > getEnclosedWithSameRatioAs(const Box2< T > &B) const
Return the largest box with the same ratio() as box B that is centered and enclosed inside this box.
Definition: Box2.h:718
bool operator>=(const Box2< T > &B) const
Return true if B is included in this box.
Definition: Box2.h:336
bool operator<=(const Box2< T > &B) const
Return true if this box is included in B.
Definition: Box2.h:351
void zoomOut()
Zoom outside the box (ie increase its size by 1/10th).
Definition: Box2.h:617
T maxX
max horizontal (X) value (inclusive)
Definition: Box2.h:162
void empty()
Make the box empty.
Definition: Box2.h:225
constexpr bool isEmpty() const
Return true if the box is empty.
Definition: Box2.h:219
T lx() const
Return the box width.
Definition: Box2.h:242
T minX
min horizontal (X) value (inclusive)
Definition: Box2.h:161
Vec2< T > center() const
Return the position of the box center as a 2 dimensional vector.
Definition: Box2.h:591
bool contains(const Vec2< T > &v) const
Return true if the box contains the point v.
Definition: Box2.h:306
Box2< T > operator|(const Vec2< T > &v) const
Return the smallest box containing this box and point v.
Definition: Box2.h:454
Box2< T > operator|(const Box2< T > &B) const
Return the smallest box containing both this box and B.
Definition: Box2.h:420
void operator|=(const Vec2< T > &v)
Enlarge this box in order to contain point v.
Definition: Box2.h:476
Box2< T > getEnclosingWithSameRatioAs(const Box2< T > &B) const
Return the smallest box with the same ratio() as box B that contains this box in its center.
Definition: Box2.h:741
bool contains(const Box2< T > &B) const
Return true if B is included in this box.
Definition: Box2.h:319
void right()
Move the box to the right by 1/10th of its width.
Definition: Box2.h:662
void operator+=(const Vec2< T > &V)
Translate this box by a given vector.
Definition: Box2.h:485
Box2< T > & operator=(const Box2< T > &B)=default
default assignement operator.
void zoomIn()
Zoom inside the box (ie decrease its size by 1/8th).
Definition: Box2.h:633
void operator|=(const Box2< T > &B)
Enlarge this box in order to contain B.
Definition: Box2.h:445
T minY
min vertical (Y) value (inclusive)
Definition: Box2.h:163
constexpr Box2(const Vec2< T > &P)
Construct a box representing a single point.
Definition: Box2.h:186
void operator&=(const Box2< T > &B)
Intersect this box with box B.
Definition: Box2.h:411
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64
T x
'x' coordinate (first dimension)
Definition: Vec2.h:72
T y
'y' coordinate (second dimension)
Definition: Vec2.h:73