bn::rect class
#include <bn_rect.h>

Defines a two-dimensional rectangle using integer precision and a center point as position.

Since it takes a center point as position instead of a top-left point, it has problems with odd dimensions.

If you need to handle odd dimensions, use bn::top_left_rect instead.

Constructors, destructors, conversion operators

rect() defaulted constexpr
Default constructor.
rect(const point& position, const size& dimensions) constexpr
Constructor.
rect(int x, int y, int width, int height) constexpr
Constructor.

Public functions

auto position() const -> const point& constexpr
Returns the position of the center point of the rectangle.
void set_position(const point& position) constexpr
Sets the position of the center point of the rectangle.
void set_position(int x, int y) constexpr
Sets the position of the center point of the rectangle.
auto dimensions() const -> const size& constexpr
Returns the size of the rectangle.
void set_dimensions(const size& dimensions) constexpr
Sets the size of the rectangle.
void set_dimensions(int width, int height) constexpr
Sets the size of the rectangle.
auto x() const -> int constexpr
Returns the horizontal position of the center point of the rectangle.
void set_x(int x) constexpr
Sets the horizontal position of the center point of the rectangle.
auto y() const -> int constexpr
Returns the vertical position of the center point of the rectangle.
void set_y(int y) constexpr
Sets the vertical position of the center point of the rectangle.
auto width() const -> int constexpr
Returns the width of the rectangle.
void set_width(int width) constexpr
Sets the width of the rectangle.
auto height() const -> int constexpr
Returns the height of the rectangle.
void set_height(int height) constexpr
Sets the height of the rectangle.
auto top() const -> int constexpr
Returns the position of the top boundary of the rectangle.
auto left() const -> int constexpr
Returns the position of the left boundary of the rectangle.
auto bottom() const -> int constexpr
Returns the position of the bottom boundary of the rectangle.
auto right() const -> int constexpr
Returns the position of the right boundary of the rectangle.
auto top_left() const -> point constexpr
Returns the position of the top-left corner of the rectangle.
auto top_right() const -> point constexpr
Returns the position of the top-right corner of the rectangle.
auto bottom_left() const -> point constexpr
Returns the position of the bottom-left corner of the rectangle.
auto bottom_right() const -> point constexpr
Returns the position of the bottom-right corner of the rectangle.
auto center_x() const -> int constexpr
Returns the horizontal position of the center point of the rectangle.
auto center_y() const -> int constexpr
Returns the vertical position of the center point of the rectangle.
auto center() const -> point constexpr
Returns the position of the center point of the rectangle.
auto contains(const point& point) const -> bool constexpr
Indicates if the given point is inside the rectangle or not.
auto edge_contains(const point& point) const -> bool constexpr
Indicates if the given point is inside the rectangle or not.
auto contains(const rect& other) const -> bool constexpr
Indicates if the given rectangle is inside this one or not.
auto edge_contains(const rect& other) const -> bool constexpr
Indicates if the given rectangle is inside this one or not.
auto intersects(const rect& other) const -> bool constexpr
Indicates if this rectangle intersects with the given one or not.
auto touches(const rect& other) const -> bool constexpr
Indicates if this rectangle touches the given one or not.
auto operator*=(int value) -> rect& constexpr
Multiplies both width and height of the rectangle by the given factor.
auto operator/=(int value) -> rect& constexpr
Divides both width and height of the rectangle by the given divisor.

Friends

auto operator*(const rect& a, int b) -> rect constexpr
Returns a multiplied by b.
auto operator/(const rect& a, int b) -> rect constexpr
Returns a divided by b.
auto operator==(const rect& a, const rect& b) -> bool defaulted constexpr
Default equal operator.

Function documentation

bn::rect::rect(const point& position, const size& dimensions) constexpr

Constructor.

Parameters
position Position of the center point of the rectangle.
dimensions Size of the rectangle.

bn::rect::rect(int x, int y, int width, int height) constexpr

Constructor.

Parameters
x Horizontal position of the center point of the rectangle.
y Vertical position of the center point of the rectangle.
width Valid width of the rectangle (>= 0).
height Valid height of the rectangle (>= 0).

void bn::rect::set_position(int x, int y) constexpr

Sets the position of the center point of the rectangle.

Parameters
x Horizontal position of the center point of the rectangle.
y Vertical position of the center point of the rectangle.

void bn::rect::set_dimensions(int width, int height) constexpr

Sets the size of the rectangle.

Parameters
width Valid width of the rectangle (>= 0).
height Valid height of the rectangle (>= 0).

void bn::rect::set_width(int width) constexpr

Sets the width of the rectangle.

Parameters
width Valid width (>= 0).

void bn::rect::set_height(int height) constexpr

Sets the height of the rectangle.

Parameters
height Valid height (>= 0).

bool bn::rect::contains(const point& point) const constexpr

Indicates if the given point is inside the rectangle or not.

If the point is on the edge of the rectangle, it returns false.

bool bn::rect::edge_contains(const point& point) const constexpr

Indicates if the given point is inside the rectangle or not.

If the point is on the edge of the rectangle, it returns true.

bool bn::rect::contains(const rect& other) const constexpr

Indicates if the given rectangle is inside this one or not.

If the given rectangle is on the edge of this one, it returns false.

bool bn::rect::edge_contains(const rect& other) const constexpr

Indicates if the given rectangle is inside this one or not.

If the given rectangle is on the edge of this one, it returns true.

bool bn::rect::intersects(const rect& other) const constexpr

Indicates if this rectangle intersects with the given one or not.

Two rectangles intersect if there is at least one point that is within both rectangles, excluding their edges.

bool bn::rect::touches(const rect& other) const constexpr

Indicates if this rectangle touches the given one or not.

Two rectangles touch each other if there is at least one point that is within both rectangles, including their edges.

rect& bn::rect::operator*=(int value) constexpr

Multiplies both width and height of the rectangle by the given factor.

Parameters
value Integer multiplication factor.
Returns Reference to this.

rect& bn::rect::operator/=(int value) constexpr

Divides both width and height of the rectangle by the given divisor.

Parameters
value Valid integer divisor (> 0).
Returns Reference to this.