Loading...
Searching...
No Matches
meshkit::Box2 Class Reference

Axis-aligned rectangle in the XY plane, stored as an origin corner and a signed size. More...

#include <meshkit/geometry.hpp>

Collaboration diagram for meshkit::Box2:

Public Member Functions

constexpr Box2 ()=default
 Null box at the origin: width and height 0, so isNull() and isEmpty() hold.
 
constexpr Box2 (Point2 a, Point2 b)
 Box spanning from corner a to corner b.
 
constexpr double left () const
 X of the origin corner; the minimum x when width() >= 0.
 
constexpr double right () const
 left() + width(); the maximum x when width() >= 0.
 
constexpr double top () const
 Y of the origin corner; the minimum y when height() >= 0.
 
constexpr double bottom () const
 top() + height(); the maximum y when height() >= 0.
 
constexpr double width () const
 Signed extent along x in XY plane units; negative when not normalized.
 
constexpr double height () const
 Signed extent along y in XY plane units; negative when not normalized.
 
 Box2 (double x, double y, double w, double h)
 Box from an origin corner and a size, all stored as given.
 
Box2 normalized () const
 Copy with non-negative width and height covering the same two corners.
 
bool isValid () const
 True when width and height are both > 0.
 
bool isEmpty () const
 True when width <= 0 or height <= 0.
 
bool isNull () const
 True when width and height are both exactly 0 (one zero side is empty, not null).
 
Point2 bottomRight () const
 Corner (right(), bottom()).
 
Point2 topLeft () const
 Corner (left(), top()), the origin corner.
 
bool contains (double x, double y) const
 Inclusive point-in-box test on coordinates; same as contains(Point2(x, y)).
 
bool contains (Point2 p) const
 Inclusive point-in-box test.
 
bool intersects (Box2 b) const
 Strict overlap test.
 
Box2 intersected (Box2 b) const
 Overlap of this box and b.
 
Box2 adjusted (double l, double t, double r, double b) const
 Copy with each edge moved by an offset, in XY plane units.
 
constexpr Point2 center () const
 Midpoint (left() + width() / 2, top() + height() / 2).
 
Box2 united (Box2 b) const
 Bounding box of this box and b.
 

Detailed Description

Axis-aligned rectangle in the XY plane, stored as an origin corner and a signed size.

Stand-in for QRectF in detail::StandardStorage, with QRectF's naming: left() and top() are the origin corner, right() is left() + width() and bottom() is top() + height(). With a non-negative height, top() is the minimum-y edge, which is not the visually upper edge of a y-up map. Coordinates, width and height are in XY plane units; there are no finiteness checks. Width and height may be negative (see normalized()). contains(), intersects(), intersected() and united() assume normalized boxes (width and height >= 0) and do not normalize their inputs.

Constructor & Destructor Documentation

◆ Box2() [1/3]

meshkit::Box2::Box2 ( )
constexprdefault

Null box at the origin: width and height 0, so isNull() and isEmpty() hold.

Here is the caller graph for this function:

◆ Box2() [2/3]

meshkit::Box2::Box2 ( Point2 a,
Point2 b )
inlineconstexpr

Box spanning from corner a to corner b.

The size is stored as b - a and the corners are not reordered, so a b left of or below a gives a negative width or height.

Parameters
[in]aOrigin corner; becomes left(), top().
[in]bOpposite corner; becomes right(), bottom() (up to rounding of the size).

◆ Box2() [3/3]

meshkit::Box2::Box2 ( double x,
double y,
double w,
double h )
inline

Box from an origin corner and a size, all stored as given.

Parameters
[in]xLeft (origin) x in XY plane units.
[in]yTop (origin) y in XY plane units.
[in]wWidth; may be negative.
[in]hHeight; may be negative.

Member Function Documentation

◆ adjusted()

Box2 meshkit::Box2::adjusted ( double l,
double t,
double r,
double b ) const
inline

Copy with each edge moved by an offset, in XY plane units.

adjusted(-d, -d, d, d) grows a normalized box by d on every side.

Parameters
[in]lAdded to left().
[in]tAdded to top().
[in]rAdded to right().
[in]bAdded to bottom().
Returns
Box from (left() + l, top() + t) to (right() + r, bottom() + b).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bottom()

double meshkit::Box2::bottom ( ) const
inlineconstexpr

top() + height(); the maximum y when height() >= 0.

Here is the caller graph for this function:

◆ bottomRight()

Point2 meshkit::Box2::bottomRight ( ) const
inline

Corner (right(), bottom()).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ center()

Point2 meshkit::Box2::center ( ) const
inlineconstexpr

Midpoint (left() + width() / 2, top() + height() / 2).

◆ contains() [1/2]

bool meshkit::Box2::contains ( double x,
double y ) const
inline

Inclusive point-in-box test on coordinates; same as contains(Point2(x, y)).

Parameters
[in]xQuery x in XY plane units.
[in]yQuery y in XY plane units.
Returns
True when the point lies inside or on the boundary.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains() [2/2]

bool meshkit::Box2::contains ( Point2 p) const
inline

Inclusive point-in-box test.

Parameters
[in]pQuery point in XY plane units.
Returns
True when left() <= p.x <= right() and top() <= p.y <= bottom(), so points on an edge or corner are inside. Always false for a box with a negative width or height, or for a NaN coordinate.
Here is the call graph for this function:

◆ height()

double meshkit::Box2::height ( ) const
inlineconstexpr

Signed extent along y in XY plane units; negative when not normalized.

Here is the caller graph for this function:

◆ intersected()

Box2 meshkit::Box2::intersected ( Box2 b) const
inline

Overlap of this box and b.

Parameters
[in]bOther box, assumed normalized like this one.
Returns
Box from (max(left), max(top)) to (min(right), min(bottom)) of the two boxes. Boxes that touch along an edge give a zero-width or zero-height box there; disjoint boxes give the null box Box2() at the origin.
Here is the call graph for this function:

◆ intersects()

bool meshkit::Box2::intersects ( Box2 b) const
inline

Strict overlap test.

Parameters
[in]bOther box, assumed normalized.
Returns
True when left() < b.right(), right() > b.left(), top() < b.bottom() and bottom() > b.top(). Boxes that only share an edge or a corner do not intersect.
Here is the call graph for this function:

◆ isEmpty()

bool meshkit::Box2::isEmpty ( ) const
inline

True when width <= 0 or height <= 0.

A NaN width or height makes both isValid() and isEmpty() false.

◆ isNull()

bool meshkit::Box2::isNull ( ) const
inline

True when width and height are both exactly 0 (one zero side is empty, not null).

◆ isValid()

bool meshkit::Box2::isValid ( ) const
inline

True when width and height are both > 0.

Here is the caller graph for this function:

◆ left()

double meshkit::Box2::left ( ) const
inlineconstexpr

X of the origin corner; the minimum x when width() >= 0.

Here is the caller graph for this function:

◆ normalized()

Box2 meshkit::Box2::normalized ( ) const
inline

Copy with non-negative width and height covering the same two corners.

Returns
Box from (min(left, right), min(top, bottom)) to (max(left, right), max(top, bottom)).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ right()

double meshkit::Box2::right ( ) const
inlineconstexpr

left() + width(); the maximum x when width() >= 0.

Here is the caller graph for this function:

◆ top()

double meshkit::Box2::top ( ) const
inlineconstexpr

Y of the origin corner; the minimum y when height() >= 0.

Here is the caller graph for this function:

◆ topLeft()

Point2 meshkit::Box2::topLeft ( ) const
inline

Corner (left(), top()), the origin corner.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ united()

Box2 meshkit::Box2::united ( Box2 b) const
inline

Bounding box of this box and b.

Parameters
[in]bOther box.
Returns
Box from (min(left), min(top)) to (max(right), max(bottom)) of the two boxes. Each box's left() and top() are taken as its minimum corner, so both must be normalized. A null or empty box is not skipped: uniting with Box2() extends the result to include the origin.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ width()

double meshkit::Box2::width ( ) const
inlineconstexpr

Signed extent along x in XY plane units; negative when not normalized.

Here is the caller graph for this function:

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