Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Rectangle Class Reference

An axis-aligned rectangle. More...

#include <point.H>

Collaboration diagram for Aleph::Rectangle:
[legend]

Public Member Functions

bool operator== (const Rectangle &r) const noexcept
 Checks for exact equality between two rectangles.
 
bool operator!= (const Rectangle &r) const noexcept
 Checks for inequality between two rectangles.
 
const Geom_Numberget_xmin () const
 Gets the minimum x-coordinate.
 
const Geom_Numberget_ymin () const
 Gets the minimum y-coordinate.
 
const Geom_Numberget_xmax () const
 Gets the maximum x-coordinate.
 
const Geom_Numberget_ymax () const
 Gets the maximum y-coordinate.
 
 Rectangle ()
 Default constructor.
 
 Rectangle (const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax)
 Constructs a rectangle from four coordinates.
 
void set_rect (const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax)
 Sets the coordinates of the rectangle.
 
Geom_Number width () const noexcept
 Calculates the width of the rectangle.
 
Geom_Number height () const noexcept
 Calculates the height of the rectangle.
 
Geom_Number area () const noexcept
 Calculates the area of the rectangle.
 
Geom_Number perimeter () const noexcept
 Calculates the perimeter of the rectangle.
 
Point center () const noexcept
 Calculates the center point of the rectangle.
 
std::array< Point, 4 > corners () const noexcept
 Gets the four corners of the rectangle.
 
bool intersects (const Rectangle &that) const noexcept
 Checks if this axis-aligned rectangle intersects another one.
 
Geom_Number distance_squared_to (const Point &p) const noexcept
 Calculates the squared Euclidean distance from the rectangle to a point.
 
Geom_Number distance_to (const Point &p) const
 Calculates the Euclidean distance from the rectangle to a point.
 
bool contains (const Point &p) const noexcept
 Checks if this axis-aligned rectangle contains a point.
 
std::string to_string () const
 Returns a string representation of the rectangle.
 

Private Attributes

Geom_Number xmin_
 
Geom_Number ymin_
 
Geom_Number xmax_
 
Geom_Number ymax_
 

Detailed Description

An axis-aligned rectangle.

Stored as (xmin, ymin, xmax, ymax) with the invariant that xmin <= xmax and ymin <= ymax must hold.

Definition at line 1736 of file point.H.

Constructor & Destructor Documentation

◆ Rectangle() [1/2]

Aleph::Rectangle::Rectangle ( )
inline

Default constructor.

Initializes a zero-sized rectangle at the origin.

Definition at line 1775 of file point.H.

◆ Rectangle() [2/2]

Aleph::Rectangle::Rectangle ( const Geom_Number xmin,
const Geom_Number ymin,
const Geom_Number xmax,
const Geom_Number ymax 
)
inline

Constructs a rectangle from four coordinates.

Parameters
xminThe minimum x-coordinate.
yminThe minimum y-coordinate.
xmaxThe maximum x-coordinate.
ymaxThe maximum y-coordinate.
Exceptions
std::out_of_rangeif xmin > xmax or ymin > ymax.

Definition at line 1788 of file point.H.

References ah_range_error_if, Aleph::divide_and_conquer_partition_dp(), xmax_, xmin_, ymax_, and ymin_.

Member Function Documentation

◆ area()

Geom_Number Aleph::Rectangle::area ( ) const
inlinenoexcept

Calculates the area of the rectangle.

Definition at line 1819 of file point.H.

References height(), and width().

◆ center()

Point Aleph::Rectangle::center ( ) const
inlinenoexcept

Calculates the center point of the rectangle.

Returns
A Point at the center of the rectangle.

Definition at line 1834 of file point.H.

References xmax_, xmin_, ymax_, and ymin_.

◆ contains()

bool Aleph::Rectangle::contains ( const Point p) const
inlinenoexcept

Checks if this axis-aligned rectangle contains a point.

Parameters
pThe point to check.
Returns
true if the point is inside or on the boundary of the rectangle.

Definition at line 1902 of file point.H.

References Aleph::and, xmax_, xmin_, ymax_, and ymin_.

◆ corners()

std::array< Point, 4 > Aleph::Rectangle::corners ( ) const
inlinenoexcept

Gets the four corners of the rectangle.

Returns
A std::array of 4 Points in counter-clockwise order, starting at the bottom-left.

Definition at line 1844 of file point.H.

References xmax_, xmin_, ymax_, and ymin_.

◆ distance_squared_to()

Geom_Number Aleph::Rectangle::distance_squared_to ( const Point p) const
inlinenoexcept

Calculates the squared Euclidean distance from the rectangle to a point.

Parameters
pThe point.
Returns
The squared distance from p to the closest point on this rectangle. Returns 0 if the point is inside.

Definition at line 1871 of file point.H.

References xmax_, xmin_, ymax_, and ymin_.

Referenced by distance_to().

◆ distance_to()

Geom_Number Aleph::Rectangle::distance_to ( const Point p) const
inline

Calculates the Euclidean distance from the rectangle to a point.

Parameters
pThe point.
Returns
The distance from p to the closest point on this rectangle.

Definition at line 1892 of file point.H.

References distance_squared_to(), and sqrt().

◆ get_xmax()

const Geom_Number & Aleph::Rectangle::get_xmax ( ) const
inline

Gets the maximum x-coordinate.

Definition at line 1768 of file point.H.

References xmax_.

Referenced by Aleph::AABBTree::boxes_overlap(), TEST_F(), Aleph::AABBTree::union_bbox(), Aleph::visualize_range_tree_query(), and K2Tree< T >::Node::xmax().

◆ get_xmin()

const Geom_Number & Aleph::Rectangle::get_xmin ( ) const
inline

Gets the minimum x-coordinate.

Definition at line 1764 of file point.H.

References xmin_.

Referenced by Aleph::AABBTree::boxes_overlap(), TEST_F(), Aleph::AABBTree::union_bbox(), Aleph::visualize_range_tree_query(), and K2Tree< T >::Node::xmin().

◆ get_ymax()

const Geom_Number & Aleph::Rectangle::get_ymax ( ) const
inline

Gets the maximum y-coordinate.

Definition at line 1770 of file point.H.

References ymax_.

Referenced by Aleph::AABBTree::boxes_overlap(), TEST_F(), Aleph::AABBTree::union_bbox(), Aleph::visualize_range_tree_query(), and K2Tree< T >::Node::ymax().

◆ get_ymin()

const Geom_Number & Aleph::Rectangle::get_ymin ( ) const
inline

Gets the minimum y-coordinate.

Definition at line 1766 of file point.H.

References ymin_.

Referenced by Aleph::AABBTree::boxes_overlap(), TEST_F(), Aleph::AABBTree::union_bbox(), Aleph::visualize_range_tree_query(), and K2Tree< T >::Node::ymin().

◆ height()

Geom_Number Aleph::Rectangle::height ( ) const
inlinenoexcept

Calculates the height of the rectangle.

Definition at line 1817 of file point.H.

References ymax_, and ymin_.

Referenced by area(), and perimeter().

◆ intersects()

bool Aleph::Rectangle::intersects ( const Rectangle that) const
inlinenoexcept

Checks if this axis-aligned rectangle intersects another one.

Parameters
thatThe other rectangle.
Returns
true if they overlap, false otherwise.

Definition at line 1859 of file point.H.

References Aleph::and, Aleph::divide_and_conquer_partition_dp(), and ymin_.

◆ operator!=()

bool Aleph::Rectangle::operator!= ( const Rectangle r) const
inlinenoexcept

Checks for inequality between two rectangles.

Parameters
rThe other rectangle to compare.
Returns
true if any coordinate is different.

Definition at line 1758 of file point.H.

References Aleph::divide_and_conquer_partition_dp(), and r.

◆ operator==()

bool Aleph::Rectangle::operator== ( const Rectangle r) const
inlinenoexcept

Checks for exact equality between two rectangles.

Parameters
rThe other rectangle to compare.
Returns
true if all four coordinates are identical.

Definition at line 1747 of file point.H.

References Aleph::and, r, xmax_, xmin_, ymax_, and ymin_.

◆ perimeter()

Geom_Number Aleph::Rectangle::perimeter ( ) const
inlinenoexcept

Calculates the perimeter of the rectangle.

Returns
The perimeter length.

Definition at line 1825 of file point.H.

References height(), and width().

◆ set_rect()

void Aleph::Rectangle::set_rect ( const Geom_Number xmin,
const Geom_Number ymin,
const Geom_Number xmax,
const Geom_Number ymax 
)
inline

Sets the coordinates of the rectangle.

Parameters
xminThe minimum x-coordinate.
yminThe minimum y-coordinate.
xmaxThe maximum x-coordinate.
ymaxThe maximum y-coordinate.
Exceptions
std::out_of_rangeif xmin > xmax or ymin > ymax.

Definition at line 1803 of file point.H.

References ah_range_error_if, Aleph::divide_and_conquer_partition_dp(), xmax_, xmin_, ymax_, and ymin_.

Referenced by K2Tree< T >::Node::set_rect(), K2Tree< T >::Node::set_rect(), and TEST_F().

◆ to_string()

std::string Aleph::Rectangle::to_string ( ) const
inline

Returns a string representation of the rectangle.

Returns
A std::string in the format "(xmin,ymin)-(xmax,ymax)".

Definition at line 1912 of file point.H.

References Aleph::geom_number_to_double(), xmax_, xmin_, ymax_, and ymin_.

◆ width()

Geom_Number Aleph::Rectangle::width ( ) const
inlinenoexcept

Calculates the width of the rectangle.

Definition at line 1815 of file point.H.

References xmax_, and xmin_.

Referenced by area(), and perimeter().

Member Data Documentation

◆ xmax_

Geom_Number Aleph::Rectangle::xmax_
private

◆ xmin_

Geom_Number Aleph::Rectangle::xmin_
private

◆ ymax_

Geom_Number Aleph::Rectangle::ymax_
private

◆ ymin_

Geom_Number Aleph::Rectangle::ymin_
private

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