22 #ifndef LSST_GEOM_BOX_H 23 #define LSST_GEOM_BOX_H 27 #include "boost/format.hpp" 66 Box2I() noexcept : _minimum(0), _dimensions(0) {}
124 ~Box2I() noexcept =
default;
142 _minimum.
swap(other._minimum);
143 _dimensions.
swap(other._dimensions);
157 int getMinX() const noexcept {
return _minimum.getX(); }
158 int getMinY() const noexcept {
return _minimum.getY(); }
161 int getMaxX() const noexcept {
return _minimum.getX() + _dimensions.getX() - 1; }
162 int getMaxY() const noexcept {
return _minimum.getY() + _dimensions.getY() - 1; }
172 int getBeginX() const noexcept {
return _minimum.getX(); }
173 int getBeginY() const noexcept {
return _minimum.getY(); }
176 int getEndX() const noexcept {
return _minimum.getX() + _dimensions.getX(); }
177 int getEndY() const noexcept {
return _minimum.getY() + _dimensions.getY(); }
187 int getWidth() const noexcept {
return _dimensions.getX(); }
188 int getHeight() const noexcept {
return _dimensions.getY(); }
210 ndarray::View<boost::fusion::vector2<ndarray::index::Range, ndarray::index::Range> >
getSlices()
const;
213 bool isEmpty() const noexcept {
return _dimensions.getX() == 0 && _dimensions.getY() == 0; }
482 ~
Box2D() noexcept =
default;
499 _minimum.
swap(other._minimum);
500 _maximum.swap(other._maximum);
529 double getWidth() const noexcept {
return isEmpty() ? 0 : _maximum.getX() - _minimum.getX(); }
530 double getHeight() const noexcept {
return isEmpty() ? 0 : _maximum.getY() - _minimum.getY(); }
533 return dim.getX() * dim.getY();
550 return Point2D((_minimum.asEigen() + _maximum.asEigen()) * 0.5);
552 double getCenterX() const noexcept {
return (_minimum.getX() + _maximum.getX()) * 0.5; }
553 double getCenterY() const noexcept {
return (_minimum.getY() + _maximum.getY()) * 0.5; }
557 bool isEmpty() const noexcept {
return _minimum.
getX() != _minimum.getX(); }
608 void flipLR(
float xExtent);
611 void flipTB(
float yExtent);
762 return (
boost::format(
"Box2D(%s,%s)") % _minimum.toString() % _maximum.toString()).str();
766 void _tweakMax(
int n) noexcept {
767 if (_maximum[n] < 0.0) {
768 _maximum[n] *= (1.0 -
EPSILON);
769 }
else if (_maximum[n] > 0.0) {
770 _maximum[n] *= (1.0 +
EPSILON);
bool operator==(Box2I const &other) const noexcept
Compare two boxes for equality.
double getMinY() const noexcept
Extent2I const getDimensions() const noexcept
bool isDisjointFrom(Box2I const &other) const noexcept
Return true if there are no points in both this and other.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
double getHeight() const noexcept
1-d interval accessors
Point2I const getMax() const noexcept
Box2I reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
std::string toString() const
Box2I expandedTo(Point const &other) const
Expand the box to ensure that contains(other) is true (returning a new object).
void flipLR(int xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
double getWidth() const noexcept
1-d interval accessors
int getHeight() const noexcept
A floating-point coordinate rectangle geometry.
Point2D const getCenter() const noexcept
Box2D erodedBy(Extent const &buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object)...
Box2D erodedBy(Element buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object)...
double getMinX() const noexcept
A coordinate class intended to represent absolute positions.
bool isEmpty() const noexcept
Return true if the box contains no points.
Box2I reflectedAboutX(Element x) const
Reflect the box about a vertical line (returning a new object).
double getMaxX() const noexcept
Extent2D const getDimensions() const noexcept
1-d interval accessors
std::string toString() const
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
ItemVariant const * other
Point2D const getMin() const noexcept
std::vector< Point2I > getCorners() const
Get the corner points.
int getEndY() const noexcept
bool contains(Element x, Element y) const noexcept
Return true if the box contains the point.
std::string toString() const
Box2I shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Interval getY() const
1-d interval accessors
Point< double, 2 > Point2D
static double const EPSILON
Value the maximum coordinate is multiplied by to increase it by the smallest possible amount...
A floating-point coordinate rectangle geometry.
int getBeginY() const noexcept
Point2I const getMin() const noexcept
bool isEmpty() const noexcept
Return true if the box contains no points.
static IntervalI fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
afw::table::PointKey< int > dimensions
double getMaxY() const noexcept
Box2I dilatedBy(Element buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object)...
double getCenterX() const noexcept
double getCenterX() const noexcept
A base class for image defects.
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
int getMaxY() const noexcept
static double const INVALID
Value used to specify undefined coordinate values.
size_t operator()(argument_type const &x) const noexcept
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
int getBeginX() const noexcept
bool contains(Element x, Element y) const noexcept
Return true if the box contains the point.
int getWidth() const noexcept
Box2I clippedTo(Box2I const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
A coordinate class intended to represent offsets and dimensions.
int getMaxX() const noexcept
Point2I const getEnd() const noexcept
static IntervalI fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
void swap(Point &other) noexcept
double getArea() const noexcept
1-d interval accessors
std::size_t hash_value() const noexcept
Return a hash of this object.
Point2D const getMax() const noexcept
double getCenterY() const noexcept
void swap(Extent &other) noexcept
bool operator!=(Box2I const &other) const noexcept
Compare two boxes for equality.
double getCenterY() const noexcept
int getMinX() const noexcept
void swap(Box2D &other) noexcept
Extent< int, 2 > Extent2I
int getEndX() const noexcept
std::string toString() const
bool intersects(Box2D const &other) const noexcept
Return true if any points in other are also in this.
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
A 1-d integer coordinate range.
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
bool overlaps(Box2I const &other) const noexcept
Return true if any points in other are also in this.
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
~Box2I() noexcept=default
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
Point2D const getCenter() const noexcept
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.
Interval getX() const
1-d interval accessors
static Box2I makeCenteredBox(Point2D const ¢er, Extent const &size)
Create a box centered as closely as possible on a particular point.
Box2I() noexcept
Construct an empty box.
size_t operator()(argument_type const &x) const noexcept
Interval getX() const
1-d interval accessors
Extent< double, 2 > Extent2D
Point2I const getBegin() const noexcept
Box2I dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object)...
An integer coordinate rectangle.
bool intersects(Box2I const &other) const noexcept
Return true if any points in other are also in this.
Box2I erodedBy(Element buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object)...
Box2I(Interval const &x, Interval const &y)
Construct a box from a pair of intervals.
Box2D dilatedBy(Element buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object)...
Interval getY() const
1-d interval accessors
int getMinY() const noexcept
Box2I & operator=(Box2I const &) noexcept=default
Standard assignment operator.
void flipTB(int yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
void swap(Box2I &other) noexcept
Box2I erodedBy(Extent const &buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object)...