lsst.geom  16.0-5-g0fa37f0+2
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
lsst::geom::Box2D Class Reference

A floating-point coordinate rectangle geometry. More...

#include <Box.h>

Public Types

typedef Point2D Point
 
typedef Extent2D Extent
 
typedef double Element
 

Public Member Functions

 Box2D () noexcept
 Construct an empty box. More...
 
 Box2D (Point2D const &minimum, Point2D const &maximum, bool invert=true) noexcept
 Construct a box from its minimum and maximum points. More...
 
 Box2D (Point2D const &corner, Extent2D const &dimensions, bool invert=true) noexcept
 Construct a box from one corner and dimensions. More...
 
 Box2D (Box2I const &other) noexcept
 Construct a floating-point box from an integer box. More...
 
 Box2D (Box2D const &) noexcept=default
 Standard copy constructor. More...
 
 Box2D (Box2D &&) noexcept=default
 
 ~Box2D () noexcept=default
 
void swap (Box2D &other) noexcept
 
Box2Doperator= (Box2D const &) noexcept=default
 Standard assignment operator. More...
 
Box2Doperator= (Box2D &&) noexcept=default
 
bool isEmpty () const noexcept
 Return true if the box contains no points. More...
 
bool contains (Point2D const &point) const noexcept
 Return true if the box contains the point. More...
 
bool contains (Box2D const &other) const noexcept
 Return true if all points contained by other are also contained by this. More...
 
bool overlaps (Box2D const &other) const noexcept
 Return true if any points in other are also in this. More...
 
void grow (double buffer)
 Increase the size of the box by the given buffer amount in all directions. More...
 
void grow (Extent2D const &buffer)
 Increase the size of the box by the given buffer amount in each direction. More...
 
void shift (Extent2D const &offset)
 Shift the position of the box by the given offset. More...
 
void flipLR (float xExtent)
 Flip a bounding box about the y-axis given a parent box of extent (xExtent). More...
 
void flipTB (float yExtent)
 Flip a bounding box about the x-axis given a parent box of extent (yExtent). More...
 
void include (Point2D const &point) noexcept
 Expand this to ensure that this->contains(point). More...
 
void include (Box2D const &other) noexcept
 Expand this to ensure that this->contains(other). More...
 
void clip (Box2D const &other) noexcept
 Shrink this to ensure that other.contains(*this). More...
 
bool operator== (Box2D const &other) const noexcept
 Compare two boxes for equality. More...
 
bool operator!= (Box2D const &other) const noexcept
 Compare two boxes for equality. More...
 
std::vector< Point2DgetCorners () const
 Get the corner points. More...
 
std::string toString () const
 
Min/Max Accessors

Return the minimum (inclusive) and maximum (exclusive) coordinates of the box.

Point2D const getMin () const noexcept
 
double getMinX () const noexcept
 
double getMinY () const noexcept
 
Point2D const getMax () const noexcept
 
double getMaxX () const noexcept
 
double getMaxY () const noexcept
 
Size Accessors

Return the size of the box.

Extent2D const getDimensions () const noexcept
 
double getWidth () const noexcept
 
double getHeight () const noexcept
 
double getArea () const noexcept
 
Center Accessors

Return the center coordinate of the box.

Point2D const getCenter () const noexcept
 
double getCenterX () const noexcept
 
double getCenterY () const noexcept
 

Static Public Member Functions

static Box2D makeCenteredBox (Point2D const &center, Extent const &size) noexcept
 Create a box centered on a particular point. More...
 

Static Public Attributes

static double const EPSILON = std::numeric_limits<double>::epsilon() * 2
 Value the maximum coordinate is multiplied by to increase it by the smallest possible amount. More...
 
static double const INVALID = std::numeric_limits<double>::quiet_NaN()
 Value used to specify undefined coordinate values. More...
 

Detailed Description

A floating-point coordinate rectangle geometry.

Box2D is a half-open (minimum is inclusive, maximum is exclusive) box. A box never has negative dimensions; the empty box is defined to zero-size dimensions and its minimum and maximum values set to NaN. Only the empty box may have zero-size dimensions.

Definition at line 291 of file Box.h.

Member Typedef Documentation

◆ Element

Definition at line 295 of file Box.h.

◆ Extent

Definition at line 294 of file Box.h.

◆ Point

Definition at line 293 of file Box.h.

Constructor & Destructor Documentation

◆ Box2D() [1/6]

lsst::geom::Box2D::Box2D ( )
noexcept

Construct an empty box.

Definition at line 234 of file Box.cc.

◆ Box2D() [2/6]

lsst::geom::Box2D::Box2D ( Point2D const &  minimum,
Point2D const &  maximum,
bool  invert = true 
)
noexcept

Construct a box from its minimum and maximum points.

If any(minimum == maximum), the box will always be empty (even if invert==true).

Parameters
[in]minimumMinimum (lower left) coordinate (inclusive).
[in]maximumMaximum (upper right) coordinate (exclusive).
[in]invertIf true (default), swap the minimum and maximum coordinates if minimum > maximum instead of creating an empty box.

Definition at line 236 of file Box.cc.

◆ Box2D() [3/6]

lsst::geom::Box2D::Box2D ( Point2D const &  corner,
Extent2D const &  dimensions,
bool  invert = true 
)
noexcept

Construct a box from one corner and dimensions.

Parameters
[in]cornerReference coordinate (inclusive). This is the lower left corner if both dimensions are positive, but a right corner or upper corner if the corresponding dimension is negative and invert is set.
[in]dimensionsBox dimensions. If either dimension coordinate is 0, the box will be empty.
[in]invertIf true (default), invert any negative dimensions instead of creating an empty box.

Definition at line 253 of file Box.cc.

◆ Box2D() [4/6]

lsst::geom::Box2D::Box2D ( Box2I const &  other)
explicitnoexcept

Construct a floating-point box from an integer box.

Integer to floating-point box conversion is based on the concept that a pixel is not an infinitesimal point but rather a square of unit size centered on integer-valued coordinates. While the output floating-point box thus has the same dimensions as the input integer box, its minimum/maximum coordinates are 0.5 smaller/greater.

Definition at line 270 of file Box.cc.

◆ Box2D() [5/6]

lsst::geom::Box2D::Box2D ( Box2D const &  )
defaultnoexcept

Standard copy constructor.

◆ Box2D() [6/6]

lsst::geom::Box2D::Box2D ( Box2D &&  )
defaultnoexcept

◆ ~Box2D()

lsst::geom::Box2D::~Box2D ( )
defaultnoexcept

Member Function Documentation

◆ clip()

void lsst::geom::Box2D::clip ( Box2D const &  other)
noexcept

Shrink this to ensure that other.contains(*this).

In particular, if other and this box do not overlap this box will become empty.

Parameters
otherthe box that must contain this one

Definition at line 369 of file Box.cc.

◆ contains() [1/2]

bool lsst::geom::Box2D::contains ( Point2D const &  point) const
noexcept

Return true if the box contains the point.

Definition at line 282 of file Box.cc.

◆ contains() [2/2]

bool lsst::geom::Box2D::contains ( Box2D const &  other) const
noexcept

Return true if all points contained by other are also contained by this.

An empty box is contained by every other box, including other empty boxes.

Definition at line 286 of file Box.cc.

◆ flipLR()

void lsst::geom::Box2D::flipLR ( float  xExtent)

Flip a bounding box about the y-axis given a parent box of extent (xExtent).

Definition at line 309 of file Box.cc.

◆ flipTB()

void lsst::geom::Box2D::flipTB ( float  yExtent)

Flip a bounding box about the x-axis given a parent box of extent (yExtent).

Definition at line 321 of file Box.cc.

◆ getArea()

double lsst::geom::Box2D::getArea ( ) const
inlinenoexcept

Definition at line 397 of file Box.h.

◆ getCenter()

Point2D const lsst::geom::Box2D::getCenter ( ) const
inlinenoexcept

Definition at line 409 of file Box.h.

◆ getCenterX()

double lsst::geom::Box2D::getCenterX ( ) const
inlinenoexcept

Definition at line 412 of file Box.h.

◆ getCenterY()

double lsst::geom::Box2D::getCenterY ( ) const
inlinenoexcept

Definition at line 413 of file Box.h.

◆ getCorners()

std::vector< Point2D > lsst::geom::Box2D::getCorners ( ) const

Get the corner points.

The order is counterclockise, starting from the lower left corner, i.e.: (minX, minY), (maxX, maxY), (maxX, maxX), (minX, maxY)

Definition at line 401 of file Box.cc.

◆ getDimensions()

Extent2D const lsst::geom::Box2D::getDimensions ( ) const
inlinenoexcept

Definition at line 394 of file Box.h.

◆ getHeight()

double lsst::geom::Box2D::getHeight ( ) const
inlinenoexcept

Definition at line 396 of file Box.h.

◆ getMax()

Point2D const lsst::geom::Box2D::getMax ( ) const
inlinenoexcept

Definition at line 383 of file Box.h.

◆ getMaxX()

double lsst::geom::Box2D::getMaxX ( ) const
inlinenoexcept

Definition at line 384 of file Box.h.

◆ getMaxY()

double lsst::geom::Box2D::getMaxY ( ) const
inlinenoexcept

Definition at line 385 of file Box.h.

◆ getMin()

Point2D const lsst::geom::Box2D::getMin ( ) const
inlinenoexcept

Definition at line 379 of file Box.h.

◆ getMinX()

double lsst::geom::Box2D::getMinX ( ) const
inlinenoexcept

Definition at line 380 of file Box.h.

◆ getMinY()

double lsst::geom::Box2D::getMinY ( ) const
inlinenoexcept

Definition at line 381 of file Box.h.

◆ getWidth()

double lsst::geom::Box2D::getWidth ( ) const
inlinenoexcept

Definition at line 395 of file Box.h.

◆ grow() [1/2]

void lsst::geom::Box2D::grow ( double  buffer)
inline

Increase the size of the box by the given buffer amount in all directions.

If a negative buffer is passed and the final size of the box is less than or equal to zero, the box will be made empty.

Definition at line 442 of file Box.h.

◆ grow() [2/2]

void lsst::geom::Box2D::grow ( Extent2D const &  buffer)

Increase the size of the box by the given buffer amount in each direction.

If a negative buffer is passed and the final size of the box is less than or equal to zero, the box will be made empty.

Definition at line 296 of file Box.cc.

◆ include() [1/2]

void lsst::geom::Box2D::include ( Point2D const &  point)
noexcept

Expand this to ensure that this->contains(point).

If the point sets a new maximum value for the box, the maximum coordinate will be adjusted to ensure the point is actually contained by the box instead of sitting on its exclusive upper edge.

Definition at line 333 of file Box.cc.

◆ include() [2/2]

void lsst::geom::Box2D::include ( Box2D const &  other)
noexcept

Expand this to ensure that this->contains(other).

Definition at line 351 of file Box.cc.

◆ isEmpty()

bool lsst::geom::Box2D::isEmpty ( ) const
inlinenoexcept

Return true if the box contains no points.

Definition at line 417 of file Box.h.

◆ makeCenteredBox()

Box2D lsst::geom::Box2D::makeCenteredBox ( Point2D const &  center,
Box2D::Extent const &  size 
)
staticnoexcept

Create a box centered on a particular point.

Parameters
centerThe desired center of the box.
sizeThe desired width and height (in that order) of the box.
Returns
if size is positive, a box with size size; otherwise, an empty box. If the returned box is not empty, it shall be centered on center. Behavior is undefined if either center or size is non-finite.

Definition at line 276 of file Box.cc.

◆ operator!=()

bool lsst::geom::Box2D::operator!= ( Box2D const &  other) const
noexcept

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 396 of file Box.cc.

◆ operator=() [1/2]

Box2D& lsst::geom::Box2D::operator= ( Box2D const &  )
defaultnoexcept

Standard assignment operator.

◆ operator=() [2/2]

Box2D& lsst::geom::Box2D::operator= ( Box2D &&  )
defaultnoexcept

◆ operator==()

bool lsst::geom::Box2D::operator== ( Box2D const &  other) const
noexcept

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 391 of file Box.cc.

◆ overlaps()

bool lsst::geom::Box2D::overlaps ( Box2D const &  other) const
noexcept

Return true if any points in other are also in this.

Any overlap operation involving an empty box returns false.

Definition at line 291 of file Box.cc.

◆ shift()

void lsst::geom::Box2D::shift ( Extent2D const &  offset)

Shift the position of the box by the given offset.

Definition at line 303 of file Box.cc.

◆ swap()

void lsst::geom::Box2D::swap ( Box2D other)
inlinenoexcept

Definition at line 364 of file Box.h.

◆ toString()

std::string lsst::geom::Box2D::toString ( ) const
inline

Definition at line 503 of file Box.h.

Member Data Documentation

◆ EPSILON

double const lsst::geom::Box2D::EPSILON = std::numeric_limits<double>::epsilon() * 2
static

Value the maximum coordinate is multiplied by to increase it by the smallest possible amount.

Definition at line 301 of file Box.h.

◆ INVALID

double const lsst::geom::Box2D::INVALID = std::numeric_limits<double>::quiet_NaN()
static

Value used to specify undefined coordinate values.

Definition at line 304 of file Box.h.


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