24 #ifndef LSST_AFW_GEOM_BOX_H
25 #define LSST_AFW_GEOM_BOX_H
28 #include "boost/format.hpp"
63 Box2I() : _minimum(0), _dimensions(0) {}
103 Box2I(
Box2I const& other) : _minimum(other._minimum), _dimensions(other._dimensions) {}
106 _minimum.
swap(other._minimum);
107 _dimensions.
swap(other._dimensions);
112 _minimum = other._minimum;
113 _dimensions = other._dimensions;
124 int getMinX()
const {
return _minimum.getX(); }
125 int getMinY()
const {
return _minimum.getY(); }
128 int getMaxX()
const {
return _minimum.getX() + _dimensions.getX() - 1; }
129 int getMaxY()
const {
return _minimum.getY() + _dimensions.getY() - 1; }
143 int getEndX()
const {
return _minimum.getX() + _dimensions.getX(); }
144 int getEndY()
const {
return _minimum.getY() + _dimensions.getY(); }
154 int getWidth()
const {
return _dimensions.getX(); }
160 ndarray::View<boost::fusion::vector2<ndarray::index::Range, ndarray::index::Range> >
getSlices()
const;
163 bool isEmpty()
const {
return _dimensions.getX() == 0 && _dimensions.getY() == 0; }
239 return (boost::format(
"Box2I(%s,%s)") % _minimum.
toString() % _dimensions.
toString()).str();
317 Box2D(
Box2D const& other) : _minimum(other._minimum), _maximum(other._maximum) {}
320 _minimum.
swap(other._minimum);
321 _maximum.
swap(other._maximum);
326 _minimum = other._minimum;
327 _maximum = other._maximum;
338 double getMinX()
const {
return _minimum.getX(); }
339 double getMinY()
const {
return _minimum.getY(); }
342 double getMaxX()
const {
return _maximum.getX(); }
343 double getMaxY()
const {
return _maximum.getY(); }
357 return dim.getX() * dim.getY();
368 double getCenterX()
const {
return (_minimum.getX() + _maximum.getX()) * 0.5; }
369 double getCenterY()
const {
return (_minimum.getY() + _maximum.getY()) * 0.5; }
373 bool isEmpty()
const {
return _minimum.getX() != _minimum.getX(); }
412 void flipLR(
float xExtent);
415 void flipTB(
float yExtent);
455 return (boost::format(
"Box2D(%s,%s)") % _minimum.
toString() % _maximum.
toString()).str();
459 void _tweakMax(
int n) {
460 if (_maximum[n] < 0.0) {
461 _maximum[n] *= (1.0 -
EPSILON);
462 }
else if (_maximum[n] > 0.0) {
463 _maximum[n] *= (1.0 +
EPSILON);
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
ndarray::View< boost::fusion::vector2< ndarray::index::Range, ndarray::index::Range > > getSlices() const
Return slices to extract the box's region from an ndarray::Array.
afw::table::PointKey< int > dimensions
Extent2I const getDimensions() const
bool contains(Point2D const &point) const
Return true if the box contains the point.
Point2D const getCenter() const
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
Box2I(Box2I const &other)
Standard copy constructor.
Extent< double, 2 > Extent2D
bool contains(Point2I const &point) const
Return true if the box contains the point.
Point2D const getMin() const
Box2I()
Construct an empty box.
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
static double const INVALID
Value used to specify undefined coordinate values.
bool isEmpty() const
Return true if the box contains no points.
A coordinate class intended to represent offsets and dimensions.
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
bool overlaps(Box2I const &other) const
Return true if any points in other are also in this.
bool operator==(Box2I const &other) const
Compare two boxes for equality.
Point2D const getMax() const
bool operator!=(Box2I const &other) const
Compare two boxes for equality.
bool operator==(Box2D const &other) const
Compare two boxes for equality.
Box2D(Box2D const &other)
Standard copy constructor.
Extent< int, 2 > Extent2I
Point2I const getMax() const
A coordinate class intended to represent absolute positions.
Box2D & operator=(Box2D const &other)
Standard assignment operator.
An integer coordinate rectangle.
void clip(Box2D const &other)
Shrink this to ensure that other.contains(*this).
std::string toString() const
double getCenterX() const
Point< double, 2 > Point2D
double getCenterY() const
void flipTB(float yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
Box2I & operator=(Box2I const &other)
Standard assignment operator.
std::string toString() const
void include(Point2D const &point)
Expand this to ensure that this->contains(point).
static double const EPSILON
Value the maximum coordinate is multiplied by to increase it by the smallest possible amount...
std::vector< Point2D > getCorners() const
Get the corner points.
std::string toString() const
bool isEmpty() const
Return true if the box contains no points.
std::string toString() const
void flipLR(int xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
Box2D()
Construct an empty box.
void flipLR(float xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
void flipTB(int yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
Point2I const getEnd() const
bool overlaps(Box2D const &other) const
Return true if any points in other are also in this.
void shift(Extent2D const &offset)
Shift the position of the box by the given offset.
Point2I const getBegin() const
void clip(Box2I const &other)
Shrink this to ensure that other.contains(*this).
A floating-point coordinate rectangle geometry.
Point2I const getMin() const
bool operator!=(Box2D const &other) const
Compare two boxes for equality.
std::vector< Point2I > getCorners() const
Get the corner points.
Extent2D const getDimensions() const