LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
lsst::geom::Box2D Class Referencefinal

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

#include <Box.h>

Public Types

typedef Point2D Point
 
typedef Extent2D Extent
 
typedef double Element
 
using Interval = IntervalD
 

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 (Interval const &x, Interval const &y)
 Construct a box from a pair of intervals. 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
 
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
 1-d interval accessors More...
 
double getWidth () const noexcept
 1-d interval accessors More...
 
double getHeight () const noexcept
 1-d interval accessors More...
 
double getArea () const noexcept
 1-d interval accessors More...
 
Interval getX () const
 1-d interval accessors More...
 
Interval getY () const
 1-d interval accessors More...
 

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...
 

Center Accessors

Return the center coordinate of the box.

Point2D const getCenter () const noexcept
 Return true if the box contains no points. More...
 
double getCenterX () const noexcept
 Return true if the box contains no points. More...
 
double getCenterY () const noexcept
 Return true if the box contains no points. More...
 
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 (Element x, Element y) const noexcept
 Return true if the box contains no points. More...
 
bool contains (Box2D const &other) const
 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...
 
bool intersects (Box2D const &other) const noexcept
 Return true if the box contains no points. More...
 
bool isDisjointFrom (Box2D const &other) const noexcept
 Return true if there are no points in both this and other. 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...
 
Box2D dilatedBy (Extent const &buffer) const
 Increase the size of the box by the given amount(s) on all sides (returning a new object). More...
 
Box2D dilatedBy (Element buffer) const
 Return true if the box contains no points. More...
 
Box2D erodedBy (Extent const &buffer) const
 Decrease the size of the box by the given amount(s) on all sides (returning a new object). More...
 
Box2D erodedBy (Element buffer) const
 Return true if the box contains no points. More...
 
Box2D shiftedBy (Extent const &offset) const
 Shift the position of the box by the given offset (returning a new object). More...
 
Box2D reflectedAboutX (Element x) const
 Reflect the box about a vertical line (returning a new object). More...
 
Box2D reflectedAboutY (Element y) const
 Reflect the box about a horizontal line (returning a new object). More...
 
Box2D expandedTo (Point const &other) const
 Expand a box to ensure that contains(other) is true (returning a new object). More...
 
Box2D expandedTo (Box2D const &other) const
 Expand a box to ensure that contains(other) is true (returning a new object). More...
 
Box2D clippedTo (Box2D const &other) const
 Shrink a box to ensure that it is contained by other (returning a new object). 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::size_t hash_value () const noexcept
 Return a hash of this object. More...
 
std::vector< Point2DgetCorners () const
 Get the corner points. More...
 
std::string toString () const
 Return true if the box contains no points. 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 413 of file Box.h.

Member Typedef Documentation

◆ Element

Definition at line 417 of file Box.h.

◆ Extent

Definition at line 416 of file Box.h.

◆ Interval

Definition at line 419 of file Box.h.

◆ Point

Definition at line 415 of file Box.h.

Constructor & Destructor Documentation

◆ Box2D() [1/7]

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

Construct an empty box.

Definition at line 274 of file Box.cc.

274 : _minimum(INVALID), _maximum(INVALID) {}
static double const INVALID
Value used to specify undefined coordinate values.
Definition: Box.h:428

◆ Box2D() [2/7]

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 276 of file Box.cc.

277  : _minimum(minimum), _maximum(maximum) {
278  for (int n = 0; n < 2; ++n) {
279  if (_minimum[n] == _maximum[n]) {
280  *this = Box2D();
281  return;
282  } else if (_minimum[n] > _maximum[n]) {
283  if (invert) {
284  std::swap(_minimum[n], _maximum[n]);
285  } else {
286  *this = Box2D();
287  return;
288  }
289  }
290  }
291 }
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
T swap(T... args)

◆ Box2D() [3/7]

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 293 of file Box.cc.

294  : _minimum(corner), _maximum(corner + dimensions) {
295  for (int n = 0; n < 2; ++n) {
296  if (_minimum[n] == _maximum[n]) {
297  *this = Box2D();
298  return;
299  } else if (_minimum[n] > _maximum[n]) {
300  if (invert) {
301  std::swap(_minimum[n], _maximum[n]);
302  } else {
303  *this = Box2D();
304  return;
305  }
306  }
307  }
308 }
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:48

◆ Box2D() [4/7]

lsst::geom::Box2D::Box2D ( Interval const &  x,
Interval const &  y 
)
inline

Construct a box from a pair of intervals.

Parameters
[in]xExtent in x direction.
[in]yExtent in y direction.

Definition at line 463 of file Box.h.

463  :
464  Box2D(Point(x.getMin(), y.getMin()), Point(x.getMax(), y.getMax()), false)
465  {}
double x
int y
Definition: SpanSet.cc:48
Point2D Point
Definition: Box.h:415

◆ Box2D() [5/7]

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 310 of file Box.cc.

311  : _minimum(Point2D(other.getMin()) - Extent2D(0.5)),
312  _maximum(Point2D(other.getMax()) + Extent2D(0.5)) {
313  if (other.isEmpty()) *this = Box2D();
314 }
Extent< double, 2 > Extent2D
Definition: Extent.h:400
Point< double, 2 > Point2D
Definition: Point.h:324

◆ Box2D() [6/7]

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

Standard copy constructor.

◆ Box2D() [7/7]

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 416 of file Box.cc.

416  {
417  if (isEmpty()) return;
418  if (other.isEmpty()) {
419  *this = Box2D();
420  return;
421  }
422  Point2D const& otherMin = other.getMin();
423  Point2D const& otherMax = other.getMax();
424  for (int n = 0; n < 2; ++n) {
425  if (otherMin[n] > _minimum[n]) {
426  _minimum[n] = otherMin[n];
427  }
428  if (otherMax[n] < _maximum[n]) {
429  _maximum[n] = otherMax[n];
430  }
431  }
432  if (any(_maximum.le(_minimum))) {
433  *this = Box2D();
434  return;
435  }
436 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557
CoordinateExpr< N > le(Point< T, N > const &other) const noexcept
Definition: Point.cc:97
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.

◆ clippedTo()

Box2D lsst::geom::Box2D::clippedTo ( Box2D const &  other) const

Shrink a box to ensure that it is contained by other (returning a new object).

In particular, if other and this do not overlap, the new box will be empty.

Definition at line 471 of file Box.cc.

471  {
472  return Box2D(getX().clippedTo(other.getX()),
473  getY().clippedTo(other.getY()));
474 }
Interval getY() const
1-d interval accessors
Definition: Box.h:540
Interval getX() const
1-d interval accessors
Definition: Box.h:539
Box2D clippedTo(Box2D const &other) const
Shrink a box to ensure that it is contained by other (returning a new object).
Definition: Box.cc:471

◆ contains() [1/3]

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

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 328 of file Box.cc.

328  {
329  return getX().contains(other.getX()) && getY().contains(other.getY());
330 }
bool contains(Element point) const
Return true if the interval contains the point.
Definition: Interval.cc:263

◆ contains() [2/3]

bool lsst::geom::Box2D::contains ( Element  x,
Element  y 
) const
inlinenoexcept

Return true if the box contains no points.

Definition at line 562 of file Box.h.

562 { return contains(Point2D(x, y)); }
bool contains(Point2D const &point) const noexcept
Return true if the box contains the point.
Definition: Box.cc:322

◆ contains() [3/3]

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

Return true if the box contains the point.

Definition at line 322 of file Box.cc.

322  {
323  // Can't delegate to IntervalD here because IntervalID is closed while
324  // Box2D is half-open.
325  return all(point.ge(this->getMin())) && all(point.lt(this->getMax()));
326 }
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.

◆ dilatedBy() [1/2]

Box2D lsst::geom::Box2D::dilatedBy ( Element  buffer) const
inline

Return true if the box contains no points.

Definition at line 650 of file Box.h.

650  {
651  return dilatedBy(Extent(buffer, buffer));
652  }
Box2D dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object).
Definition: Box.cc:438
Extent2D Extent
Definition: Box.h:416

◆ dilatedBy() [2/2]

Box2D lsst::geom::Box2D::dilatedBy ( Extent const &  buffer) const

Increase the size of the box by the given amount(s) on all sides (returning a new object).

If buffer is negative, this is equivalent to eroding by -buffer.

If the final size of the box is less than zero in either dimension the new box will empty.

Empty boxes remain empty after dilation. Infinite bounds are unaffected by dilation.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if buffer is not finite.

Definition at line 438 of file Box.cc.

438  {
439  return Box2D(getX().dilatedBy(buffer.getX()),
440  getY().dilatedBy(buffer.getY()));
441 }

◆ erodedBy() [1/2]

Box2D lsst::geom::Box2D::erodedBy ( Element  buffer) const
inline

Return true if the box contains no points.

Definition at line 672 of file Box.h.

672 { return dilatedBy(-buffer); }

◆ erodedBy() [2/2]

Box2D lsst::geom::Box2D::erodedBy ( Extent const &  buffer) const
inline

Decrease the size of the box by the given amount(s) on all sides (returning a new object).

If buffer is negative, this is equivalent to dilating by -buffer.

If the final size of the box is less than zero in either dimension the new box will empty.

Empty boxes remain empty after erosion. Infinite bounds are unaffected by erosion.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if buffer is not finite.

Definition at line 671 of file Box.h.

671 { return dilatedBy(-buffer); }

◆ expandedTo() [1/2]

Box2D lsst::geom::Box2D::expandedTo ( Box2D const &  other) const

Expand a box to ensure that contains(other) is true (returning a new object).

Expanding an empty box with a second box is equivalent to assignment.

Definition at line 466 of file Box.cc.

466  {
467  return Box2D(getX().expandedTo(other.getX()),
468  getY().expandedTo(other.getY()));
469 }
Box2D expandedTo(Point const &other) const
Expand a box to ensure that contains(other) is true (returning a new object).
Definition: Box.cc:458

◆ expandedTo() [2/2]

Box2D lsst::geom::Box2D::expandedTo ( Point const &  other) const

Expand a box to ensure that contains(other) is true (returning a new object).

Expanding an empty box with a single point yields a box with dimensions == (0, 0) at that point.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if other is not finite.

Definition at line 458 of file Box.cc.

458  {
459  // Can't delegate to IntervalD here because IntervalID is closed while
460  // Box2D is still half-open.
461  Box2D copy(*this);
462  copy.include(other);
463  return copy;
464 }
T copy(T... args)

◆ 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 356 of file Box.cc.

356  {
357  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
358  // Swap min and max values for x dimension
359  _minimum[0] += _maximum[0];
360  _maximum[0] = _minimum[0] - _maximum[0];
361  _minimum[0] -= _maximum[0];
362  // Apply flip assuming coordinate system of parent.
363  _minimum[0] = xextent - _minimum[0];
364  _maximum[0] = xextent - _maximum[0];
365  // _dimensions should remain unchanged
366 }

◆ 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 368 of file Box.cc.

368  {
369  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
370  // Swap min and max values for y dimension
371  _minimum[1] += _maximum[1];
372  _maximum[1] = _minimum[1] - _maximum[1];
373  _minimum[1] -= _maximum[1];
374  // Apply flip assuming coordinate system of parent.
375  _minimum[1] = yextent - _minimum[1];
376  _maximum[1] = yextent - _maximum[1];
377  // _dimensions should remain unchanged
378 }

◆ getArea()

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

1-d interval accessors

Definition at line 531 of file Box.h.

531  {
532  Extent2D dim(getDimensions());
533  return dim.getX() * dim.getY();
534  }
Extent2D const getDimensions() const noexcept
1-d interval accessors
Definition: Box.h:528

◆ getCenter()

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

Return true if the box contains no points.

Definition at line 549 of file Box.h.

549  {
550  return Point2D((_minimum.asEigen() + _maximum.asEigen()) * 0.5);
551  }
EigenVector const & asEigen() const noexcept(IS_ELEMENT_NOTHROW_COPYABLE)
Return a fixed-size Eigen representation of the coordinate object.

◆ getCenterX()

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

Return true if the box contains no points.

Definition at line 552 of file Box.h.

552 { return (_minimum.getX() + _maximum.getX()) * 0.5; }

◆ getCenterY()

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

Return true if the box contains no points.

Definition at line 553 of file Box.h.

553 { return (_minimum.getY() + _maximum.getY()) * 0.5; }

◆ 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 496 of file Box.cc.

496  {
497  std::vector<Point2D> retVec;
498  retVec.push_back(getMin());
499  retVec.push_back(Point2D(getMaxX(), getMinY()));
500  retVec.push_back(getMax());
501  retVec.push_back(Point2D(getMinX(), getMaxY()));
502  return retVec;
503 }
double getMaxY() const noexcept
Definition: Box.h:519
Point2D const getMax() const noexcept
Definition: Box.h:517
double getMaxX() const noexcept
Definition: Box.h:518
double getMinY() const noexcept
Definition: Box.h:515
Point2D const getMin() const noexcept
Definition: Box.h:513
double getMinX() const noexcept
Definition: Box.h:514
T push_back(T... args)

◆ getDimensions()

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

1-d interval accessors

Definition at line 528 of file Box.h.

528 { return isEmpty() ? Extent2D(0.0) : _maximum - _minimum; }

◆ getHeight()

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

1-d interval accessors

Definition at line 530 of file Box.h.

530 { return isEmpty() ? 0 : _maximum.getY() - _minimum.getY(); }

◆ getMax()

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

Definition at line 517 of file Box.h.

517 { return _maximum; }

◆ getMaxX()

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

Definition at line 518 of file Box.h.

518 { return _maximum.getX(); }

◆ getMaxY()

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

Definition at line 519 of file Box.h.

519 { return _maximum.getY(); }

◆ getMin()

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

Definition at line 513 of file Box.h.

513 { return _minimum; }

◆ getMinX()

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

Definition at line 514 of file Box.h.

514 { return _minimum.getX(); }

◆ getMinY()

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

Definition at line 515 of file Box.h.

515 { return _minimum.getY(); }

◆ getWidth()

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

1-d interval accessors

Definition at line 529 of file Box.h.

529 { return isEmpty() ? 0 : _maximum.getX() - _minimum.getX(); }

◆ getX()

Interval lsst::geom::Box2D::getX ( ) const
inline

1-d interval accessors

Definition at line 539 of file Box.h.

539 { return Interval::fromMinMax(getMinX(), getMaxX()); }
static IntervalD fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
Definition: Interval.cc:226

◆ getY()

Interval lsst::geom::Box2D::getY ( ) const
inline

1-d interval accessors

Definition at line 540 of file Box.h.

540 { return Interval::fromMinMax(getMinY(), getMaxY()); }

◆ 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 594 of file Box.h.

594 { grow(Extent2D(buffer)); }
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
Definition: Box.h:594

◆ 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 343 of file Box.cc.

343  {
344  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
345  _minimum -= buffer;
346  _maximum += buffer;
347  if (any(_minimum.ge(_maximum))) *this = Box2D();
348 }
CoordinateExpr< N > ge(Point< T, N > const &other) const noexcept
Definition: Point.cc:111

◆ hash_value()

std::size_t lsst::geom::Box2D::hash_value ( ) const
noexcept

Return a hash of this object.

Definition at line 486 of file Box.cc.

486  {
487  if (isEmpty()) {
488  // All empty boxes are equal and must have equal hashes
489  return 179;
490  } else {
491  // Completely arbitrary seed
492  return utils::hashCombine(17, _minimum, _maximum);
493  }
494 }
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35

◆ include() [1/2]

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

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

Definition at line 398 of file Box.cc.

398  {
399  if (other.isEmpty()) return;
400  if (this->isEmpty()) {
401  *this = other;
402  return;
403  }
404  Point2D const& otherMin = other.getMin();
405  Point2D const& otherMax = other.getMax();
406  for (int n = 0; n < 2; ++n) {
407  if (otherMin[n] < _minimum[n]) {
408  _minimum[n] = otherMin[n];
409  }
410  if (otherMax[n] > _maximum[n]) {
411  _maximum[n] = otherMax[n];
412  }
413  }
414 }

◆ include() [2/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 380 of file Box.cc.

380  {
381  if (isEmpty()) {
382  _minimum = point;
383  _maximum = point;
384  _tweakMax(0);
385  _tweakMax(1);
386  return;
387  }
388  for (int n = 0; n < 2; ++n) {
389  if (point[n] < _minimum[n]) {
390  _minimum[n] = point[n];
391  } else if (point[n] >= _maximum[n]) {
392  _maximum[n] = point[n];
393  _tweakMax(n);
394  }
395  }
396 }

◆ intersects()

bool lsst::geom::Box2D::intersects ( Box2D const &  other) const
inlinenoexcept

Return true if the box contains no points.

Definition at line 579 of file Box.h.

579 { return overlaps(other); }
bool overlaps(Box2D const &other) const noexcept
Return true if any points in other are also in this.
Definition: Box.cc:332

◆ isDisjointFrom()

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

Return true if there are no points in both this and other.

Definition at line 339 of file Box.cc.

339  {
340  return !overlaps(other);
341 }

◆ isEmpty()

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

Return true if the box contains no points.

Definition at line 557 of file Box.h.

557 { return _minimum.getX() != _minimum.getX(); }

◆ 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 316 of file Box.cc.

316  {
317  lsst::geom::Point2D corner(center);
318  corner.shift(-0.5 * size);
319  return lsst::geom::Box2D(corner, size, false);
320 }
A floating-point coordinate rectangle geometry.
Definition: Box.h:413

◆ operator!=()

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

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 481 of file Box.cc.

481  {
482  return !(other.isEmpty() && other.isEmpty()) &&
483  (other._minimum != this->_minimum || other._maximum != this->_maximum);
484 }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Standard assignment operator.

◆ operator==()

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

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 476 of file Box.cc.

476  {
477  return (other.isEmpty() && this->isEmpty()) ||
478  (other._minimum == this->_minimum && other._maximum == this->_maximum);
479 }

◆ 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 332 of file Box.cc.

332  {
333  // Can't delegate to IntervalD here because IntervalID is closed while
334  // Box2D is half-open.
335  return !(other.isEmpty() || this->isEmpty() || any(other.getMax().le(this->getMin())) ||
336  any(other.getMin().ge(this->getMax())));
337 }

◆ reflectedAboutX()

Box2D lsst::geom::Box2D::reflectedAboutX ( Element  x) const

Reflect the box about a vertical line (returning a new object).

Empty boxes remain empty when reflected.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if x is not finite.

Definition at line 448 of file Box.cc.

448  {
449  return Box2D(getX().reflectedAbout(x),
450  getY());
451 }

◆ reflectedAboutY()

Box2D lsst::geom::Box2D::reflectedAboutY ( Element  y) const

Reflect the box about a horizontal line (returning a new object).

Empty boxes remain empty when reflected.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if y is not finite.

Definition at line 453 of file Box.cc.

453  {
454  return Box2D(getX(),
455  getY().reflectedAbout(y));
456 }

◆ shift()

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

Shift the position of the box by the given offset.

Definition at line 350 of file Box.cc.

350  {
351  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
352  _minimum += offset;
353  _maximum += offset;
354 }

◆ shiftedBy()

Box2D lsst::geom::Box2D::shiftedBy ( Extent const &  offset) const

Shift the position of the box by the given offset (returning a new object).

Empty boxes remain empty when shifted. Infinite bounds are unaffected by shifting.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if offset is not finite.

Definition at line 443 of file Box.cc.

443  {
444  return Box2D(getX().shiftedBy(offset.getX()),
445  getY().shiftedBy(offset.getY()));
446 }
Box2D shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Definition: Box.cc:443

◆ swap()

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

Definition at line 498 of file Box.h.

498  {
499  _minimum.swap(other._minimum);
500  _maximum.swap(other._maximum);
501  }
void swap(Point &other) noexcept
Definition: Point.h:202

◆ toString()

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

Return true if the box contains no points.

Definition at line 761 of file Box.h.

761  {
762  return (boost::format("Box2D(%s,%s)") % _minimum.toString() % _maximum.toString()).str();
763  }
std::string toString() const
Cast this object to an Extent of the same numeric type and dimensionality.
Definition: Point.h:143
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

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 425 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 428 of file Box.h.


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