LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private 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
 

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 &other)
 Standard copy constructor. More...
 
void swap (Box2D &other)
 
Box2Doperator= (Box2D const &other)
 Standard assignment operator. More...
 
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
 
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
 
static double const INVALID
 Value used to specify undefined coordinate values. More...
 

Private Member Functions

void _tweakMax (int n)
 

Private Attributes

Point2D _minimum
 
Point2D _maximum
 

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

Member Typedef Documentation

Definition at line 275 of file Box.h.

Definition at line 274 of file Box.h.

Constructor & Destructor Documentation

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

Construct an empty box.

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

lsst::afw::geom::Box2D::Box2D ( Box2D const &  other)
inline

Standard copy constructor.

Definition at line 323 of file Box.h.

323 : _minimum(other._minimum), _maximum(other._maximum) {}
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474

Member Function Documentation

void lsst::afw::geom::Box2D::_tweakMax ( int  n)
inlineprivate

Definition at line 465 of file Box.h.

465  {
466  if (_maximum[n] < 0.0) {
467  _maximum[n] *= (1.0 - EPSILON);
468  } else if (_maximum[n] > 0.0) {
469  _maximum[n] *= (1.0 + EPSILON);
470  } else {
471  _maximum[n] = EPSILON;
472  }
473  }
Point2D _maximum
Definition: Box.h:475
static double const EPSILON
Definition: Box.h:281
void lsst::afw::geom::Box2D::clip ( Box2D const &  other)

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

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

Return true if the box contains the point.

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.

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

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

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

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

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

Definition at line 361 of file Box.h.

361  {
362  Extent2D dim(getDimensions());
363  return dim.getX() * dim.getY();
364  }
Extent< double, 2 > Extent2D
Definition: Extent.h:358
Extent2D const getDimensions() const
Definition: Box.h:358
Point2D const lsst::afw::geom::Box2D::getCenter ( ) const
inline

Definition at line 373 of file Box.h.

373 { return Point2D((_minimum.asEigen() + _maximum.asEigen())*0.5); }
Point< double, 2 > Point2D
Definition: Point.h:286
Point2D _maximum
Definition: Box.h:475
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
Point2D _minimum
Definition: Box.h:474
double lsst::afw::geom::Box2D::getCenterX ( ) const
inline

Definition at line 374 of file Box.h.

374 { return (_minimum.getX() + _maximum.getX())*0.5; }
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474
double lsst::afw::geom::Box2D::getCenterY ( ) const
inline

Definition at line 375 of file Box.h.

375 { return (_minimum.getY() + _maximum.getY())*0.5; }
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474
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)

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

Definition at line 358 of file Box.h.

358 { return isEmpty() ? Extent2D(0.0) : _maximum - _minimum; }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:379
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474
Extent< double, 2 > Extent2D
Definition: Extent.h:358
double lsst::afw::geom::Box2D::getHeight ( ) const
inline

Definition at line 360 of file Box.h.

360 { return isEmpty() ? 0 : _maximum.getY() - _minimum.getY(); }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:379
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474
Point2D const lsst::afw::geom::Box2D::getMax ( ) const
inline

Definition at line 347 of file Box.h.

347 { return _maximum; }
Point2D _maximum
Definition: Box.h:475
double lsst::afw::geom::Box2D::getMaxX ( ) const
inline

Definition at line 348 of file Box.h.

348 { return _maximum.getX(); }
Point2D _maximum
Definition: Box.h:475
double lsst::afw::geom::Box2D::getMaxY ( ) const
inline

Definition at line 349 of file Box.h.

349 { return _maximum.getY(); }
Point2D _maximum
Definition: Box.h:475
Point2D const lsst::afw::geom::Box2D::getMin ( ) const
inline

Definition at line 343 of file Box.h.

343 { return _minimum; }
Point2D _minimum
Definition: Box.h:474
double lsst::afw::geom::Box2D::getMinX ( ) const
inline

Definition at line 344 of file Box.h.

344 { return _minimum.getX(); }
Point2D _minimum
Definition: Box.h:474
double lsst::afw::geom::Box2D::getMinY ( ) const
inline

Definition at line 345 of file Box.h.

345 { return _minimum.getY(); }
Point2D _minimum
Definition: Box.h:474
double lsst::afw::geom::Box2D::getWidth ( ) const
inline

Definition at line 359 of file Box.h.

359 { return isEmpty() ? 0 : _maximum.getX() - _minimum.getX(); }
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:379
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474
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 404 of file Box.h.

404 { grow(Extent2D(buffer)); }
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
Definition: Box.h:404
Extent< double, 2 > Extent2D
Definition: Extent.h:358
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.

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.

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

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

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

Return true if the box contains no points.

Definition at line 379 of file Box.h.

379 { return _minimum.getX() != _minimum.getX(); }
Point2D _minimum
Definition: Box.h:474
bool lsst::afw::geom::Box2D::operator!= ( Box2D const &  other) const

Compare two boxes for equality.

All empty boxes are equal.

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

Standard assignment operator.

Definition at line 331 of file Box.h.

331  {
332  _minimum = other._minimum;
333  _maximum = other._maximum;
334  return *this;
335  }
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474
bool lsst::afw::geom::Box2D::operator== ( Box2D const &  other) const

Compare two boxes for equality.

All empty boxes are equal.

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.

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

Shift the position of the box by the given offset.

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

Definition at line 325 of file Box.h.

325  {
326  _minimum.swap(other._minimum);
327  _maximum.swap(other._maximum);
328  }
void swap(Point &other)
Definition: Point.h:174
Point2D _maximum
Definition: Box.h:475
Point2D _minimum
Definition: Box.h:474
std::string lsst::afw::geom::Box2D::toString ( ) const
inline

Definition at line 460 of file Box.h.

460  {
461  return (boost::format("Box2D(%s,%s)") % _minimum.toString() % _maximum.toString()).str();
462  }
Point2D _maximum
Definition: Box.h:475
std::string toString() const
Definition: Point.h:123
Point2D _minimum
Definition: Box.h:474

Member Data Documentation

Point2D lsst::afw::geom::Box2D::_maximum
private

Definition at line 475 of file Box.h.

Point2D lsst::afw::geom::Box2D::_minimum
private

Definition at line 474 of file Box.h.

double const lsst::afw::geom::Box2D::EPSILON
static

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

Definition at line 281 of file Box.h.

double const lsst::afw::geom::Box2D::INVALID
static

Value used to specify undefined coordinate values.

Definition at line 284 of file Box.h.


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