ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::Quad< T > Class Template Reference

A 2D rectangle in space. More...

#include <geometry.h>

Public Member Functions

 Quad ()
 Default constructor for the Quad class.
 
 Quad (const Vec2< T > &position, const Vec2< T > &size)
 Constructor for the Quad class.
 
 Quad (T x, T y, T width, T height)
 Constructor for the Quad class.
 
void set_position (T x, T y)
 Set the position of the rectangle.
 
void set_size (T width, T height)
 Set the size of the rectangle.
 
Vec2< T > get_center () const
 Get center of the rectangle.
 
bool contains (const Vec2< T > &point) const
 Check if a point is inside the rectangle. The left and top edges are inside, the right and bottom edges are not, as for collides, so rectangles that share an edge never both contain a point.
 
bool contains (T x, T y) const
 Check if coordinates are inside the rectangle. The left and top edges are inside, the right and bottom edges are not, as for collides.
 
bool collides (const Quad &other) const
 Check if a rectangle is inside the rectangle.
 
Vec2< T > closest_point (const Vec2< T > &point) const
 Get the point in or on the rectangle closest to another point.
 
Vec2< T >::Real distance_to (const Vec2< T > &point) const
 Get the distance from a point to the edge of the rectangle.
 
Vec2< T > get_push_out (const Quad &other) const
 Get the smallest move that pushes this rectangle out of another. Useful to stop a moving box from entering solid scenery.
 
bool collides_bottom (const Quad &other) const
 
bool collides_top (const Quad &other) const
 
bool collides_left (const Quad &other) const
 
bool collides_right (const Quad &other) const
 
Quad operator+ (const Quad< T > &quad) const
 Add another rectangle's position and size to this one.
 
Quad operator- (const Quad< T > &quad) const
 Subtract another rectangle's position and size from this one.
 
Quad operator* (const T scalar) const
 Multiply the rectangle by a scalar.
 
Quad operator/ (const T scalar) const
 Divide the rectangle by a scalar.
 

Public Attributes

Vec2< T > position
 The position of the rectangle.
 
Vec2< T > size
 The size of the rectangle.
 

Detailed Description

template<typename T>
class asw::Quad< T >

A 2D rectangle in space.

This class represents a 2D rectangle in space. It is used to represent areas, sizes, and positions.

Definition at line 504 of file geometry.h.

Constructor & Destructor Documentation

◆ Quad() [1/3]

template<typename T >
asw::Quad< T >::Quad ( )
inline

Default constructor for the Quad class.

Definition at line 508 of file geometry.h.

◆ Quad() [2/3]

template<typename T >
asw::Quad< T >::Quad ( const Vec2< T > & position,
const Vec2< T > & size )
inline

Constructor for the Quad class.

Parameters
positionThe position of the rectangle.
sizeThe size of the rectangle.

Definition at line 519 of file geometry.h.

◆ Quad() [3/3]

template<typename T >
asw::Quad< T >::Quad ( T x,
T y,
T width,
T height )
inline

Constructor for the Quad class.

Parameters
xThe x position of the rectangle.
yThe y position of the rectangle.
widthThe width of the rectangle.
heightThe height of the rectangle.

Definition at line 532 of file geometry.h.

Member Function Documentation

◆ closest_point()

template<typename T >
Vec2< T > asw::Quad< T >::closest_point ( const Vec2< T > & point) const
inline

Get the point in or on the rectangle closest to another point.

Parameters
pointThe point to check.
Returns
Vec2 The closest point. This is the point itself when it is inside the rectangle.

Definition at line 613 of file geometry.h.

◆ collides()

template<typename T >
bool asw::Quad< T >::collides ( const Quad< T > & other) const
inline

Check if a rectangle is inside the rectangle.

Parameters
otherThe rectangle to check.
Returns
bool True if the rectangle is inside the rectangle.

Definition at line 597 of file geometry.h.

◆ collides_bottom()

template<typename T >
bool asw::Quad< T >::collides_bottom ( const Quad< T > & other) const
inline

Definition at line 662 of file geometry.h.

◆ collides_left()

template<typename T >
bool asw::Quad< T >::collides_left ( const Quad< T > & other) const
inline

Definition at line 673 of file geometry.h.

◆ collides_right()

template<typename T >
bool asw::Quad< T >::collides_right ( const Quad< T > & other) const
inline

Definition at line 678 of file geometry.h.

◆ collides_top()

template<typename T >
bool asw::Quad< T >::collides_top ( const Quad< T > & other) const
inline

Definition at line 668 of file geometry.h.

◆ contains() [1/2]

template<typename T >
bool asw::Quad< T >::contains ( const Vec2< T > & point) const
inline

Check if a point is inside the rectangle. The left and top edges are inside, the right and bottom edges are not, as for collides, so rectangles that share an edge never both contain a point.

Parameters
pointThe point to check.
Returns
bool True if the point is inside the rectangle.

Definition at line 574 of file geometry.h.

◆ contains() [2/2]

template<typename T >
bool asw::Quad< T >::contains ( T x,
T y ) const
inline

Check if coordinates are inside the rectangle. The left and top edges are inside, the right and bottom edges are not, as for collides.

Parameters
xThe x coordinate to check.
yThe y coordinate to check.
Returns
bool True if the point is inside the rectangle.

Definition at line 586 of file geometry.h.

◆ distance_to()

template<typename T >
Vec2< T >::Real asw::Quad< T >::distance_to ( const Vec2< T > & point) const
inline

Get the distance from a point to the edge of the rectangle.

Parameters
pointThe point to check.
Returns
The distance, 0 when the point is inside the rectangle.

Definition at line 627 of file geometry.h.

◆ get_center()

template<typename T >
Vec2< T > asw::Quad< T >::get_center ( ) const
inline

Get center of the rectangle.

Returns
Vec2 The center of the rectangle.

Definition at line 562 of file geometry.h.

◆ get_push_out()

template<typename T >
Vec2< T > asw::Quad< T >::get_push_out ( const Quad< T > & other) const
inline

Get the smallest move that pushes this rectangle out of another. Useful to stop a moving box from entering solid scenery.

Parameters
otherThe rectangle to push out of.
Returns
Vec2 The move to add to this rectangle's position, along whichever axis has the smallest overlap. A zero vector when the rectangles do not overlap.

Definition at line 640 of file geometry.h.

◆ operator*()

template<typename T >
Quad asw::Quad< T >::operator* ( const T scalar) const
inline

Multiply the rectangle by a scalar.

Parameters
scalarThe scalar to multiply by.
Returns
Quad The rectangle multiplied by the scalar.

Definition at line 709 of file geometry.h.

◆ operator+()

template<typename T >
Quad asw::Quad< T >::operator+ ( const Quad< T > & quad) const
inline

Add another rectangle's position and size to this one.

Parameters
quadThe rectangle to add.
Returns
Quad The rectangle with both position and size added.

Definition at line 689 of file geometry.h.

◆ operator-()

template<typename T >
Quad asw::Quad< T >::operator- ( const Quad< T > & quad) const
inline

Subtract another rectangle's position and size from this one.

Parameters
quadThe rectangle to subtract.
Returns
Quad The rectangle with both position and size subtracted.

Definition at line 699 of file geometry.h.

◆ operator/()

template<typename T >
Quad asw::Quad< T >::operator/ ( const T scalar) const
inline

Divide the rectangle by a scalar.

Parameters
scalarThe scalar to divide by.
Returns
Quad The rectangle divided by the scalar.

Definition at line 719 of file geometry.h.

◆ set_position()

template<typename T >
void asw::Quad< T >::set_position ( T x,
T y )
inline

Set the position of the rectangle.

Parameters
xThe x position of the rectangle.
yThe y position of the rectangle.

Definition at line 543 of file geometry.h.

◆ set_size()

template<typename T >
void asw::Quad< T >::set_size ( T width,
T height )
inline

Set the size of the rectangle.

Parameters
widthThe width of the rectangle.
heightThe height of the rectangle.

Definition at line 553 of file geometry.h.

Member Data Documentation

◆ position

template<typename T >
Vec2<T> asw::Quad< T >::position

The position of the rectangle.

Definition at line 725 of file geometry.h.

◆ size

template<typename T >
Vec2<T> asw::Quad< T >::size

The size of the rectangle.

Definition at line 728 of file geometry.h.


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