TGX 1.1.4
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
Loading...
Searching...
No Matches
tgx::Box2< T > Struct Template Reference

Generic 2D Box [specializations iBox2 , fBox2, dBox2]. More...

#include <Box2.h>

Public Member Functions

constexpr Box2 ()
 default constructor: the box content is undefined.
 
constexpr Box2 (const T minx, const T maxx, const T miny, const T maxy)
 Constructor with explicit dimensions.
 
constexpr Box2 (const Vec2< T > &P)
 Construct a box representing a single point.
 
 Box2 (const Box2< T > &B)=default
 default copy constructor.
 
Box2< T > & operator= (const Box2< T > &B)=default
 default assignment operator.
 
template<typename U >
 operator Box2< U > () const
 Explicit conversion to another box type.
 
 operator Box2< typename DefaultFPType< T >::fptype > () const
 Implicit conversion to floating-point type.
 
constexpr bool isEmpty () const
 Return true if the box is empty.
 
void empty ()
 Make the box empty.
 
T lx () const
 Return the box width. More...
 
T ly () const
 Return the box height. More...
 
bool equals (const Box2< T > &B) const
 Return true if the boxes are equal. More...
 
bool operator== (const Box2< T > &B) const
 Return true if the boxes are equal. More...
 
bool contains (const Vec2< T > &v) const
 Return true if the box contains the point v.
 
bool contains (const Box2< T > &B) const
 Return true if B is included in this box. More...
 
bool operator>= (const Box2< T > &B) const
 Return true if B is included in this box. More...
 
bool operator<= (const Box2< T > &B) const
 Return true if this box is included in B. More...
 
bool operator> (const Box2< T > &B) const
 Return true if B is strictly included in this box (i.e. More...
 
bool operator< (const Box2< T > &B) const
 Return true if this box is strictly included inside B (i.e. More...
 
Box2< T > operator& (const Box2< T > &B) const
 Return the intersection of this box and B. More...
 
void operator&= (const Box2< T > &B)
 Intersect this box with box B. More...
 
Box2< T > operator| (const Box2< T > &B) const
 Return the smallest box containing both this box and B.
 
void operator|= (const Box2< T > &B)
 Enlarge this box in order to contain B.
 
Box2< T > operator| (const Vec2< T > &v) const
 Return the smallest box containing this box and point v.
 
void operator|= (const Vec2< T > &v)
 Enlarge this box in order to contain point v.
 
void operator+= (const Vec2< T > &V)
 Translate this box by a given vector.
 
Box2< T > operator+ (const Vec2< T > &V) const
 Return this box translated by vector v.
 
void operator-= (const Vec2< T > &V)
 Translate the box by a given vector (substracted)
 
Box2< T > operator- (const Vec2< T > &V) const
 Return this box translated by v (substracted).
 
void split_fixed (BoxSplit part)
 Split the box in half or quarter. More...
 
Box2< T > getSplit_fixed (BoxSplit part) const
 Return the box splitted in half or quater. More...
 
Vec2< T > getAnchor (Anchor anchor_pos) const
 Return the position of an anchor point inside this box. More...
 
Vec2< T > center () const
 Return the position of the box center as a 2 dimensional vector.
 
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat ratio () const
 Return the aspect ratio of the box lx()/ly(). More...
 
void zoomOut ()
 Zoom outside the box (ie increase its size by 1/10th). More...
 
void zoomIn ()
 Zoom inside the box (ie decrease its size by 1/8th). More...
 
void left ()
 Move the box to the left by 1/10th of its width. More...
 
void right ()
 Move the box to the right by 1/10th of its width. More...
 
void up ()
 Move the box up by 1/10th of its height. More...
 
void down ()
 Move the box down by 1/10th of its height. More...
 
Box2< T > getEnclosedWithSameRatioAs_fixed (const Box2< T > &B) const
 Return the largest box with the same ratio() as box B that is centered and enclosed inside this box. More...
 
Box2< T > getEnclosingWithSameRatioAs_fixed (const Box2< T > &B) const
 Return the smallest box with the same ratio() as box B that contains this box in its center. More...
 

Public Attributes

T minX
 min horizontal (X) value (inclusive)
 
T maxX
 max horizontal (X) value (inclusive)
 
T minY
 min vertical (Y) value (inclusive)
 
T maxY
 max vertical (Y) value (inclusive)
 

Detailed Description

template<typename T>
struct tgx::Box2< T >

Generic 2D Box [specializations iBox2 , fBox2, dBox2].

The class encapsulates of 4 public variables: minX, maxX, minY, maxY which delimit the 2 dimensional closed box: [minX, maxX] x [minY, maxY]

The box is empty if maxX < minX or if maxY < minY.

Warning
Some methods compute things differently depending whether T is an integral or a floating point value type.
Template Parameters
`T`arithmetic type of the box (int, float...)
See also
iBox2,fBox2,dBox2

Member Function Documentation

◆ lx()

template<typename T >
T tgx::Box2< T >::lx ( ) const
inline

Return the box width.

Warning
The width is computed differently depending on whether T is of floating point or integral type.
  • If T is floating point, the method returns maxX - minX.
  • If T is integral, the method returns maxX - minX + 1 (number of horizontal points in the closed box).

◆ ly()

template<typename T >
T tgx::Box2< T >::ly ( ) const
inline

Return the box height.

Warning
The height is computed differently depending on whether T is of floating point or integral type.
  • If T is floating point, the method returns maxY - minY.
  • If T is integral, the method returns maxY - minY + 1 (number of vertical points in the closed box).

◆ equals()

template<typename T >
bool tgx::Box2< T >::equals ( const Box2< T > &  B) const
inline

Return true if the boxes are equal.

Note
Two empty boxes always compare equal.
See also
operator==()

◆ operator==()

template<typename T >
bool tgx::Box2< T >::operator== ( const Box2< T > &  B) const
inline

Return true if the boxes are equal.

Note
Two empty boxes always compare equal.
See also
equals()

◆ contains()

template<typename T >
bool tgx::Box2< T >::contains ( const Box2< T > &  B) const
inline

Return true if B is included in this box.

Note
  1. An empty box contains nothing.
  2. A non-empty box contains any empty box.

◆ operator>=()

template<typename T >
bool tgx::Box2< T >::operator>= ( const Box2< T > &  B) const
inline

Return true if B is included in this box.

Note
  1. An empty box contains nothing.
  2. A non-empty box contains any empty box.
See also
contains()

◆ operator<=()

template<typename T >
bool tgx::Box2< T >::operator<= ( const Box2< T > &  B) const
inline

Return true if this box is included in B.

Note
  1. An empty box contains nothing.
  2. A non-empty box contains any empty box.
See also
contains()

◆ operator>()

template<typename T >
bool tgx::Box2< T >::operator> ( const Box2< T > &  B) const
inline

Return true if B is strictly included in this box (i.e.

contained but not equal).

Note
  1. An empty box contains nothing.
  2. A non-empty box contains any empty box.

◆ operator<()

template<typename T >
bool tgx::Box2< T >::operator< ( const Box2< T > &  B) const
inline

Return true if this box is strictly included inside B (i.e.

contained but not equal).

Note
  1. An empty box contains nothing.
  2. A non-empty box contains any empty box.

◆ operator&()

template<typename T >
Box2< T > tgx::Box2< T >::operator& ( const Box2< T > &  B) const
inline

Return the intersection of this box and B.

This may return an empty box.

◆ operator&=()

template<typename T >
void tgx::Box2< T >::operator&= ( const Box2< T > &  B)
inline

Intersect this box with box B.

May create an empty box.

◆ split_fixed()

template<typename T >
void tgx::Box2< T >::split_fixed ( BoxSplit  part)
inline

Split the box in half or quarter.

Remarks
This method replaces the former split(): TOP/BOTTOM now follow the anchor convention and integral splits no longer overlap on the middle row/column.
Parameters
partThe part or the box to keep. See tgx::BoxSplit.
See also
getSplit_fixed()

◆ getSplit_fixed()

template<typename T >
Box2< T > tgx::Box2< T >::getSplit_fixed ( BoxSplit  part) const
inline

Return the box splitted in half or quater.

Remarks
This method replaces the former getSplit(): TOP/BOTTOM now follow the anchor convention and integral splits no longer overlap on the middle row/column.
Parameters
partThe part or the box to keep. See tgx::BoxSplit.
See also
split_fixed()

◆ getAnchor()

template<typename T >
Vec2< T > tgx::Box2< T >::getAnchor ( Anchor  anchor_pos) const
inline

Return the position of an anchor point inside this box.

Parameters
anchor_posTh anchor location, see

◆ ratio()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat tgx::Box2< T >::ratio ( ) const
inline

Return the aspect ratio of the box lx()/ly().

  • Return -1 for an empty box.
  • Beware that lx() and ly() are computed differently depending on wether T is an integral or a floating point type !
See also
lx(),ly()

◆ zoomOut()

template<typename T >
void tgx::Box2< T >::zoomOut ( )
inline

Zoom outside the box (ie increase its size by 1/10th).

See also
zoomIn()

◆ zoomIn()

template<typename T >
void tgx::Box2< T >::zoomIn ( )
inline

Zoom inside the box (ie decrease its size by 1/8th).

See also
zoomOut()

◆ left()

template<typename T >
void tgx::Box2< T >::left ( )
inline

Move the box to the left by 1/10th of its width.

See also
up(),down(),right()

◆ right()

template<typename T >
void tgx::Box2< T >::right ( )
inline

Move the box to the right by 1/10th of its width.

See also
up(),down(),left()

◆ up()

template<typename T >
void tgx::Box2< T >::up ( )
inline

Move the box up by 1/10th of its height.

See also
down(),left(),right()

◆ down()

template<typename T >
void tgx::Box2< T >::down ( )
inline

Move the box down by 1/10th of its height.

See also
up(),left(),right()

◆ getEnclosedWithSameRatioAs_fixed()

template<typename T >
Box2< T > tgx::Box2< T >::getEnclosedWithSameRatioAs_fixed ( const Box2< T > &  B) const

Return the largest box with the same ratio() as box B that is centered and enclosed inside this box.

Remarks
This method replaces the former getEnclosedWithSameRatioAs(): the returned box now preserves the position/center of this box instead of being relative to the origin.
See also
ratio(),getEnclosingWithSameRatioAs_fixed()

◆ getEnclosingWithSameRatioAs_fixed()

template<typename T >
Box2< T > tgx::Box2< T >::getEnclosingWithSameRatioAs_fixed ( const Box2< T > &  B) const

Return the smallest box with the same ratio() as box B that contains this box in its center.

Remarks
This method replaces the former getEnclosingWithSameRatioAs(): the returned box now preserves the position/center of this box instead of being relative to the origin.
See also
ratio(),getEnclosedWithSameRatioAs_fixed()

The documentation for this struct was generated from the following file: