LSSTApplications  12.1-5-gbdcc3ab+2,15.0+13,15.0+26,15.0-1-g19261fa+17,15.0-1-g60afb23+26,15.0-1-g615e0bb+18,15.0-1-g788a293+26,15.0-1-ga91101e+26,15.0-1-gae1598d+12,15.0-1-gd076f1f+24,15.0-1-gdf18595+5,15.0-1-gf4f1c34+12,15.0-11-g7db6e543+4,15.0-12-g3681e7a+4,15.0-15-gc15de322,15.0-16-g83b84f4,15.0-2-g100d730+19,15.0-2-g1f9c9cf+4,15.0-2-g8aea5f4+1,15.0-2-gf38729e+21,15.0-29-ga12a2b06e,15.0-3-g11fe1a0+14,15.0-3-g707930d+3,15.0-3-g9103c06+12,15.0-3-gd3cbb57+3,15.0-4-g2d82b59,15.0-4-g535e784+10,15.0-4-g92ca6c3+4,15.0-4-gf906033+2,15.0-5-g23e394c+14,15.0-5-g4be42a9,15.0-6-g69628aa,15.0-6-g86e3f3d+1,15.0-6-gfa9b38f+4,15.0-7-g949993c+3,15.0-8-g67a62d3+1,15.0-8-gcf05001+1,15.0-9-g1e7c341+1,w.2018.21
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Attributes | List of all members
lsst::afw::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 ()
 Construct an empty box. More...
 
 Box2D (Point2D const &minimum, Point2D const &maximum, bool invert=true)
 Construct a box from its minimum and maximum points. More...
 
 Box2D (Point2D const &minimum, Extent2D const &dimensions, bool invert=true)
 Construct a box from its minimum point and dimensions. More...
 
 Box2D (Box2I const &other)
 Construct a floating-point box from an integer box. More...
 
 Box2D (Box2D const &)=default
 Standard copy constructor. More...
 
 Box2D (Box2D &&)=default
 
 ~Box2D ()=default
 
void swap (Box2D &other)
 
Box2Doperator= (Box2D const &)=default
 Standard assignment operator. More...
 
Box2Doperator= (Box2D &&)=default
 
bool isEmpty () const
 Return true if the box contains no points. More...
 
bool contains (Point2D const &point) const
 Return true if the box contains the point. 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
 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)
 Expand this to ensure that this->contains(point). More...
 
void include (Box2D const &other)
 Expand this to ensure that this->contains(other). More...
 
void clip (Box2D const &other)
 Shrink this to ensure that other.contains(*this). More...
 
bool operator== (Box2D const &other) const
 Compare two boxes for equality. More...
 
bool operator!= (Box2D const &other) const
 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
 
double getMinX () const
 
double getMinY () const
 
Point2D const getMax () const
 
double getMaxX () const
 
double getMaxY () const
 
Size Accessors

Return the size of the box.

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

Return the center coordinate of the box.

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

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

Member Typedef Documentation

◆ Element

Definition at line 270 of file Box.h.

◆ Extent

Definition at line 269 of file Box.h.

◆ Point

Definition at line 268 of file Box.h.

Constructor & Destructor Documentation

◆ Box2D() [1/6]

lsst::afw::geom::Box2D::Box2D ( )

Construct an empty box.

Definition at line 224 of file Box.cc.

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

◆ Box2D() [2/6]

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

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

227  : _minimum(minimum), _maximum(maximum) {
228  for (int n = 0; n < 2; ++n) {
229  if (_minimum[n] == _maximum[n]) {
230  *this = Box2D();
231  return;
232  } else if (_minimum[n] > _maximum[n]) {
233  if (invert) {
234  std::swap(_minimum[n], _maximum[n]);
235  } else {
236  *this = Box2D();
237  return;
238  }
239  }
240  }
241 }
T swap(T... args)
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
Box2D()
Construct an empty box.
Definition: Box.cc:224

◆ Box2D() [3/6]

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

Construct a box from its minimum point and dimensions.

Parameters
[in]minimumMinimum (lower left) coordinate (inclusive).
[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 243 of file Box.cc.

244  : _minimum(minimum), _maximum(minimum + dimensions) {
245  for (int n = 0; n < 2; ++n) {
246  if (_minimum[n] == _maximum[n]) {
247  *this = Box2D();
248  return;
249  } else if (_minimum[n] > _maximum[n]) {
250  if (invert) {
251  std::swap(_minimum[n], _maximum[n]);
252  } else {
253  *this = Box2D();
254  return;
255  }
256  }
257  }
258 }
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:44
T swap(T... args)
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
Box2D()
Construct an empty box.
Definition: Box.cc:224

◆ Box2D() [4/6]

lsst::afw::geom::Box2D::Box2D ( Box2I const &  other)
explicit

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

261  : _minimum(Point2D(other.getMin()) - Extent2D(0.5)),
262  _maximum(Point2D(other.getMax()) + Extent2D(0.5)) {
263  if (other.isEmpty()) *this = Box2D();
264 }
Extent< double, 2 > Extent2D
Definition: Extent.h:383
Point< double, 2 > Point2D
Definition: Point.h:304
Box2D()
Construct an empty box.
Definition: Box.cc:224
ItemVariant const * other
Definition: Schema.cc:55

◆ Box2D() [5/6]

lsst::afw::geom::Box2D::Box2D ( Box2D const &  )
default

Standard copy constructor.

◆ Box2D() [6/6]

lsst::afw::geom::Box2D::Box2D ( Box2D &&  )
default

◆ ~Box2D()

lsst::afw::geom::Box2D::~Box2D ( )
default

Member Function Documentation

◆ clip()

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

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

Definition at line 353 of file Box.cc.

353  {
354  if (isEmpty()) return;
355  if (other.isEmpty()) {
356  *this = Box2D();
357  return;
358  }
359  Point2D const& otherMin = other.getMin();
360  Point2D const& otherMax = other.getMax();
361  for (int n = 0; n < 2; ++n) {
362  if (otherMin[n] > _minimum[n]) {
363  _minimum[n] = otherMin[n];
364  }
365  if (otherMax[n] < _maximum[n]) {
366  _maximum[n] = otherMax[n];
367  }
368  }
369  if (any(_maximum.le(_minimum))) {
370  *this = Box2D();
371  return;
372  }
373 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
Point< double, 2 > Point2D
Definition: Point.h:304
CoordinateExpr< N > le(Point< T, N > const &other) const
Definition: Point.cc:99
Box2D()
Construct an empty box.
Definition: Box.cc:224
ItemVariant const * other
Definition: Schema.cc:55

◆ contains() [1/2]

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

Return true if the box contains the point.

Definition at line 266 of file Box.cc.

266  {
267  return all(point.ge(this->getMin())) && all(point.lt(this->getMax()));
268 }
bool all(CoordinateExpr< N > const &expr)
Return true if all elements are true.

◆ contains() [2/2]

bool lsst::afw::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 270 of file Box.cc.

270  {
271  return other.isEmpty() ||
272  (all(other.getMin().ge(this->getMin())) && all(other.getMax().le(this->getMax())));
273 }
bool all(CoordinateExpr< N > const &expr)
Return true if all elements are true.
ItemVariant const * other
Definition: Schema.cc:55
Point2D const getMax() const
Definition: Box.h:342
Point2D const getMin() const
Definition: Box.h:338

◆ flipLR()

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

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

Definition at line 293 of file Box.cc.

293  {
294  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
295  // Swap min and max values for x dimension
296  _minimum[0] += _maximum[0];
297  _maximum[0] = _minimum[0] - _maximum[0];
298  _minimum[0] -= _maximum[0];
299  // Apply flip assuming coordinate system of parent.
300  _minimum[0] = xextent - _minimum[0];
301  _maximum[0] = xextent - _maximum[0];
302  // _dimensions should remain unchanged
303 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374

◆ flipTB()

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

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

Definition at line 305 of file Box.cc.

305  {
306  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
307  // Swap min and max values for y dimension
308  _minimum[1] += _maximum[1];
309  _maximum[1] = _minimum[1] - _maximum[1];
310  _minimum[1] -= _maximum[1];
311  // Apply flip assuming coordinate system of parent.
312  _minimum[1] = yextent - _minimum[1];
313  _maximum[1] = yextent - _maximum[1];
314  // _dimensions should remain unchanged
315 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374

◆ getArea()

double lsst::afw::geom::Box2D::getArea ( ) const
inline

Definition at line 356 of file Box.h.

356  {
357  Extent2D dim(getDimensions());
358  return dim.getX() * dim.getY();
359  }
Extent< double, 2 > Extent2D
Definition: Extent.h:383
Extent2D const getDimensions() const
Definition: Box.h:353

◆ getCenter()

Point2D const lsst::afw::geom::Box2D::getCenter ( ) const
inline

Definition at line 368 of file Box.h.

368 { return Point2D((_minimum.asEigen() + _maximum.asEigen()) * 0.5); }
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
Point< double, 2 > Point2D
Definition: Point.h:304

◆ getCenterX()

double lsst::afw::geom::Box2D::getCenterX ( ) const
inline

Definition at line 369 of file Box.h.

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

◆ getCenterY()

double lsst::afw::geom::Box2D::getCenterY ( ) const
inline

Definition at line 370 of file Box.h.

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

◆ getCorners()

std::vector< Point2D > lsst::afw::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 385 of file Box.cc.

385  {
386  std::vector<Point2D> retVec;
387  retVec.push_back(getMin());
388  retVec.push_back(Point2D(getMaxX(), getMinY()));
389  retVec.push_back(getMax());
390  retVec.push_back(Point2D(getMinX(), getMaxY()));
391  return retVec;
392 }
double getMaxX() const
Definition: Box.h:343
T push_back(T... args)
Point< double, 2 > Point2D
Definition: Point.h:304
double getMaxY() const
Definition: Box.h:344
double getMinX() const
Definition: Box.h:339
STL class.
double getMinY() const
Definition: Box.h:340
Point2D const getMax() const
Definition: Box.h:342
Point2D const getMin() const
Definition: Box.h:338

◆ getDimensions()

Extent2D const lsst::afw::geom::Box2D::getDimensions ( ) const
inline

Definition at line 353 of file Box.h.

353 { return isEmpty() ? Extent2D(0.0) : _maximum - _minimum; }
Extent< double, 2 > Extent2D
Definition: Extent.h:383
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374

◆ getHeight()

double lsst::afw::geom::Box2D::getHeight ( ) const
inline

Definition at line 355 of file Box.h.

355 { return isEmpty() ? 0 : _maximum.getY() - _minimum.getY(); }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374

◆ getMax()

Point2D const lsst::afw::geom::Box2D::getMax ( ) const
inline

Definition at line 342 of file Box.h.

342 { return _maximum; }

◆ getMaxX()

double lsst::afw::geom::Box2D::getMaxX ( ) const
inline

Definition at line 343 of file Box.h.

343 { return _maximum.getX(); }

◆ getMaxY()

double lsst::afw::geom::Box2D::getMaxY ( ) const
inline

Definition at line 344 of file Box.h.

344 { return _maximum.getY(); }

◆ getMin()

Point2D const lsst::afw::geom::Box2D::getMin ( ) const
inline

Definition at line 338 of file Box.h.

338 { return _minimum; }

◆ getMinX()

double lsst::afw::geom::Box2D::getMinX ( ) const
inline

Definition at line 339 of file Box.h.

339 { return _minimum.getX(); }

◆ getMinY()

double lsst::afw::geom::Box2D::getMinY ( ) const
inline

Definition at line 340 of file Box.h.

340 { return _minimum.getY(); }

◆ getWidth()

double lsst::afw::geom::Box2D::getWidth ( ) const
inline

Definition at line 354 of file Box.h.

354 { return isEmpty() ? 0 : _maximum.getX() - _minimum.getX(); }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374

◆ grow() [1/2]

void lsst::afw::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 399 of file Box.h.

399 { grow(Extent2D(buffer)); }
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
Definition: Box.h:399
Extent< double, 2 > Extent2D
Definition: Extent.h:383

◆ grow() [2/2]

void lsst::afw::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 280 of file Box.cc.

280  {
281  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
282  _minimum -= buffer;
283  _maximum += buffer;
284  if (any(_minimum.ge(_maximum))) *this = Box2D();
285 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374
CoordinateExpr< N > ge(Point< T, N > const &other) const
Definition: Point.cc:113
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
Box2D()
Construct an empty box.
Definition: Box.cc:224

◆ include() [1/2]

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

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

317  {
318  if (isEmpty()) {
319  _minimum = point;
320  _maximum = point;
321  _tweakMax(0);
322  _tweakMax(1);
323  return;
324  }
325  for (int n = 0; n < 2; ++n) {
326  if (point[n] < _minimum[n]) {
327  _minimum[n] = point[n];
328  } else if (point[n] >= _maximum[n]) {
329  _maximum[n] = point[n];
330  _tweakMax(n);
331  }
332  }
333 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374

◆ include() [2/2]

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

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

Definition at line 335 of file Box.cc.

335  {
336  if (other.isEmpty()) return;
337  if (this->isEmpty()) {
338  *this = other;
339  return;
340  }
341  Point2D const& otherMin = other.getMin();
342  Point2D const& otherMax = other.getMax();
343  for (int n = 0; n < 2; ++n) {
344  if (otherMin[n] < _minimum[n]) {
345  _minimum[n] = otherMin[n];
346  }
347  if (otherMax[n] > _maximum[n]) {
348  _maximum[n] = otherMax[n];
349  }
350  }
351 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374
Point< double, 2 > Point2D
Definition: Point.h:304
ItemVariant const * other
Definition: Schema.cc:55

◆ isEmpty()

bool lsst::afw::geom::Box2D::isEmpty ( ) const
inline

Return true if the box contains no points.

Definition at line 374 of file Box.h.

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

◆ operator!=()

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

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 380 of file Box.cc.

380  {
381  return !(other.isEmpty() && other.isEmpty()) &&
382  (other._minimum != this->_minimum || other._maximum != this->_maximum);
383 }
ItemVariant const * other
Definition: Schema.cc:55

◆ operator=() [1/2]

Box2D& lsst::afw::geom::Box2D::operator= ( Box2D const &  )
default

Standard assignment operator.

◆ operator=() [2/2]

Box2D& lsst::afw::geom::Box2D::operator= ( Box2D &&  )
default

◆ operator==()

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

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 375 of file Box.cc.

375  {
376  return (other.isEmpty() && this->isEmpty()) ||
377  (other._minimum == this->_minimum && other._maximum == this->_maximum);
378 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374
ItemVariant const * other
Definition: Schema.cc:55

◆ overlaps()

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

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

Any overlap operation involving an empty box returns false.

Definition at line 275 of file Box.cc.

275  {
276  return !(other.isEmpty() || this->isEmpty() || any(other.getMax().le(this->getMin())) ||
277  any(other.getMin().ge(this->getMax())));
278 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
ItemVariant const * other
Definition: Schema.cc:55
Point2D const getMax() const
Definition: Box.h:342
Point2D const getMin() const
Definition: Box.h:338

◆ shift()

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

Shift the position of the box by the given offset.

Definition at line 287 of file Box.cc.

287  {
288  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
289  _minimum += offset;
290  _maximum += offset;
291 }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:374

◆ swap()

void lsst::afw::geom::Box2D::swap ( Box2D other)
inline

Definition at line 323 of file Box.h.

323  {
324  _minimum.swap(other._minimum);
325  _maximum.swap(other._maximum);
326  }
void swap(Point &other)
Definition: Point.h:189
ItemVariant const * other
Definition: Schema.cc:55

◆ toString()

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

Definition at line 455 of file Box.h.

455  {
456  return (boost::format("Box2D(%s,%s)") % _minimum.toString() % _maximum.toString()).str();
457  }
std::string toString() const
Definition: Point.h:131
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:134

Member Data Documentation

◆ EPSILON

double const lsst::afw::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 276 of file Box.h.

◆ INVALID

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

Value used to specify undefined coordinate values.

Definition at line 279 of file Box.h.


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