LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
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
 
bool isEmpty () 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 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 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
 
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
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...
 
Center Accessors

Return the center coordinate of the box.

Point2D const getCenter () const noexcept
 
double getCenterX () const noexcept
 
double getCenterY () const noexcept
 
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 the point. 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 any points in other are also in 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
 Increase the size of the box by the given amount(s) on all sides (returning a new object). 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
 Decrease the size of the box by the given amount(s) on all sides (returning a new object). 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...
 

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 }
T swap(T... args)
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274

◆ 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 }
T swap(T... args)
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274

◆ 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  {}
Point2D Point
Definition: Box.h:415
int y
Definition: SpanSet.cc:49
double x
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274

◆ 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 }
ItemVariant const * other
Definition: Schema.cc:56
Point< double, 2 > Point2D
Definition: Point.h:324
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Extent< double, 2 > Extent2D
Definition: Extent.h:400

◆ 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 }
ItemVariant const * other
Definition: Schema.cc:56
Point< double, 2 > Point2D
Definition: Point.h:324
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
CoordinateExpr< N > le(Point< T, N > const &other) const noexcept
Definition: Point.cc:97

◆ 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 }
ItemVariant const * other
Definition: Schema.cc:56
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
IntervalD clippedTo(IntervalD const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
Definition: Interval.cc:335
Interval getX() const
1-d interval accessors
Definition: Box.h:539
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Interval getY() const
1-d interval accessors
Definition: Box.h:540

◆ contains() [1/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.

◆ contains() [2/3]

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

Return true if the box contains the point.

Definition at line 562 of file Box.h.

562 { return contains(Point2D(x, y)); }
int y
Definition: SpanSet.cc:49
Point< double, 2 > Point2D
Definition: Point.h:324
bool contains(Point2D const &point) const noexcept
Return true if the box contains the point.
Definition: Box.cc:322
double x

◆ contains() [3/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 }
ItemVariant const * other
Definition: Schema.cc:56
Interval getX() const
1-d interval accessors
Definition: Box.h:539
bool contains(Element point) const
Return true if the interval contains the point.
Definition: Interval.cc:263
Interval getY() const
1-d interval accessors
Definition: Box.h:540

◆ dilatedBy() [1/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 }
IntervalD dilatedBy(Element buffer) const
Increase the size of the interval by the given amount in both directions (returning a new object)...
Definition: Interval.cc:284
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
Interval getX() const
1-d interval accessors
Definition: Box.h:539
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Interval getY() const
1-d interval accessors
Definition: Box.h:540

◆ dilatedBy() [2/2]

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

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

◆ erodedBy() [1/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); }
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

◆ erodedBy() [2/2]

Box2D lsst::geom::Box2D::erodedBy ( Element  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 672 of file Box.h.

672 { return dilatedBy(-buffer); }
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

◆ expandedTo() [1/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)
ItemVariant const * other
Definition: Schema.cc:56
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274

◆ expandedTo() [2/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 }
ItemVariant const * other
Definition: Schema.cc:56
IntervalD expandedTo(Element other) const
Expand an interval to ensure that contains(other) is true.
Definition: Interval.cc:314
Interval getX() const
1-d interval accessors
Definition: Box.h:539
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Box2D expandedTo(Point const &other) const
Expand a box to ensure that contains(other) is true (returning a new object).
Definition: Box.cc:458
Interval getY() const
1-d interval accessors
Definition: Box.h:540

◆ 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 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ 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 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ 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
Extent< double, 2 > Extent2D
Definition: Extent.h:400

◆ getCenter()

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

Definition at line 549 of file Box.h.

549  {
550  return Point2D((_minimum.asEigen() + _maximum.asEigen()) * 0.5);
551  }
Point< double, 2 > Point2D
Definition: Point.h:324
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

Definition at line 552 of file Box.h.

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

◆ getCenterY()

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

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 getMinY() const noexcept
Definition: Box.h:515
double getMinX() const noexcept
Definition: Box.h:514
double getMaxX() const noexcept
Definition: Box.h:518
Point2D const getMin() const noexcept
Definition: Box.h:513
Point< double, 2 > Point2D
Definition: Point.h:324
T push_back(T... args)
double getMaxY() const noexcept
Definition: Box.h:519
Point2D const getMax() const noexcept
Definition: Box.h:517

◆ 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; }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557
Extent< double, 2 > Extent2D
Definition: Extent.h:400

◆ 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(); }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ 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(); }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ 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()); }
double getMinX() const noexcept
Definition: Box.h:514
double getMaxX() const noexcept
Definition: Box.h:518
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()); }
double getMinY() const noexcept
Definition: Box.h:515
double getMaxY() const noexcept
Definition: Box.h:519
static IntervalD fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
Definition: Interval.cc:226

◆ 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
Extent< double, 2 > Extent2D
Definition: Extent.h:400

◆ 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 }
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557
CoordinateExpr< N > ge(Point< T, N > const &other) const noexcept
Definition: Point.cc:111
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274

◆ 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 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35

◆ 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 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 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ include() [2/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 }
ItemVariant const * other
Definition: Schema.cc:56
Point< double, 2 > Point2D
Definition: Point.h:324
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ intersects()

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

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

Any overlap operation involving an empty box returns false.

Definition at line 579 of file Box.h.

579 { return overlaps(other); }
ItemVariant const * other
Definition: Schema.cc:56
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 }
ItemVariant const * other
Definition: Schema.cc:56
bool overlaps(Box2D const &other) const noexcept
Return true if any points in other are also in this.
Definition: Box.cc:332

◆ 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 }

◆ 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 }
ItemVariant const * other
Definition: Schema.cc:56

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

476  {
477  return (other.isEmpty() && this->isEmpty()) ||
478  (other._minimum == this->_minimum && other._maximum == this->_maximum);
479 }
ItemVariant const * other
Definition: Schema.cc:56
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ 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 }
ItemVariant const * other
Definition: Schema.cc:56
Point2D const getMin() const noexcept
Definition: Box.h:513
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557
Point2D const getMax() const noexcept
Definition: Box.h:517

◆ 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 }
double x
Interval getX() const
1-d interval accessors
Definition: Box.h:539
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Interval getY() const
1-d interval accessors
Definition: Box.h:540

◆ 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 }
int y
Definition: SpanSet.cc:49
Interval getX() const
1-d interval accessors
Definition: Box.h:539
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Interval getY() const
1-d interval accessors
Definition: Box.h:540

◆ 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 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:557

◆ 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 }
IntervalD shiftedBy(Element offset) const
Shift the position of the interval by the given offset (returning a new object).
Definition: Interval.cc:292
Box2D shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Definition: Box.cc:443
Interval getX() const
1-d interval accessors
Definition: Box.h:539
Box2D() noexcept
Construct an empty box.
Definition: Box.cc:274
Interval getY() const
1-d interval accessors
Definition: Box.h:540

◆ 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  }
ItemVariant const * other
Definition: Schema.cc:56
void swap(Point &other) noexcept
Definition: Point.h:202

◆ toString()

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

Definition at line 761 of file Box.h.

761  {
762  return (boost::format("Box2D(%s,%s)") % _minimum.toString() % _maximum.toString()).str();
763  }
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
std::string toString() const
Definition: Point.h:143

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: