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_Number & get_xmin () const
 Gets the minimum x-coordinate.
 
const Geom_Number & get_ymin () const
 Gets the minimum y-coordinate.
 
const Geom_Number & get_xmax () const
 Gets the maximum x-coordinate.
 
const Geom_Number & get_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 1788 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 1838 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 1851 of file point.H.

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

Member Function Documentation

◆ area()

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

◆ 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 1906 of file point.H.

References xmax_, xmin_, ymax_, and ymin_.

Referenced by Aleph::RTree< Payload, MaxEntries, MinEntries, Variant >::reinsert_farthest().

◆ 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 1969 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 1916 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 1938 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 1959 of file point.H.

References distance_squared_to(), and sqrt().

◆ get_xmax()

◆ get_xmin()

◆ get_ymax()

◆ get_ymin()

◆ height()

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

Calculates the height of the rectangle.

Definition at line 1883 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 1926 of file point.H.

References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), 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 1809 of file point.H.

References Aleph::blossom_maximum_cardinality_matching(), 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 1799 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 1897 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 1866 of file point.H.

References ah_range_error_if, Aleph::blossom_maximum_cardinality_matching(), 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 1978 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 1878 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: