22#ifndef LSST_GEOM_BOX_H 
   23#define LSST_GEOM_BOX_H 
   27#include "boost/format.hpp" 
   66    Box2I() noexcept : _minimum(0), _dimensions(0) {}
 
  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; }
 
  386        return (boost::format(
"Box2I(%s,%s)") % _minimum.toString() % _dimensions.toString()).str();
 
 
 
  499        _minimum.swap(other._minimum);
 
  500        _maximum.swap(other._maximum);
 
 
  514    double getMinX() const noexcept { 
return _minimum.getX(); }
 
  515    double getMinY() const noexcept { 
return _minimum.getY(); }
 
  518    double getMaxX() const noexcept { 
return _maximum.getX(); }
 
  519    double getMaxY() const noexcept { 
return _maximum.getY(); }
 
  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);
 
 
A floating-point coordinate rectangle geometry.
double getMaxY() const noexcept
Box2D(Box2D const &) noexcept=default
Standard copy constructor.
void swap(Box2D &other) noexcept
Point2D const getMax() const noexcept
double getMaxX() const noexcept
Box2D dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object).
bool operator==(Box2D const &other) const noexcept
Compare two boxes for equality.
Extent2D const getDimensions() const noexcept
1-d interval accessors
Box2D dilatedBy(Element buffer) const
Return true if the box contains no points.
bool operator!=(Box2D const &other) const noexcept
Compare two boxes for equality.
void shift(Extent2D const &offset)
Shift the position of the box by the given offset.
double getMinY() const noexcept
void clip(Box2D const &other) noexcept
Shrink this to ensure that other.contains(*this).
std::size_t hash_value() const noexcept
Return a hash of this object.
double getWidth() const noexcept
1-d interval accessors
static Box2D makeCenteredBox(Point2D const ¢er, Extent const &size) noexcept
Create a box centered on a particular point.
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() noexcept
Construct an empty box.
Point2D const getCenter() const noexcept
Return true if the box contains no points.
Box2D & operator=(Box2D &&) noexcept=default
bool isEmpty() const noexcept
Return true if the box contains no points.
Box2D & operator=(Box2D const &) noexcept=default
Standard assignment operator.
Point2D const getMin() const noexcept
double getMinX() const noexcept
bool isDisjointFrom(Box2D const &other) const noexcept
Return true if there are no points in both this and other.
Interval getY() const
1-d interval accessors
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
Box2D reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
void flipLR(float xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
void flipTB(float yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
Interval getX() const
1-d interval accessors
Box2D reflectedAboutX(Element x) const
Reflect the box about a vertical line (returning a new object).
double getCenterX() const noexcept
Return true if the box contains no points.
void include(Point2D const &point) noexcept
Expand this to ensure that this->contains(point).
bool contains(Point2D const &point) const noexcept
Return true if the box contains the point.
Box2D erodedBy(Element buffer) const
Return true if the box contains no points.
bool overlaps(Box2D const &other) const noexcept
Return true if any points in other are also in this.
bool contains(Element x, Element y) const noexcept
Return true if the box contains no points.
bool intersects(Box2D const &other) const noexcept
Return true if the box contains no points.
double getArea() const noexcept
1-d interval accessors
Box2D clippedTo(Box2D const &other) const
Shrink a box to ensure that it is contained by other (returning a new object).
static double const EPSILON
Value the maximum coordinate is multiplied by to increase it by the smallest possible amount.
Box2D expandedTo(Point const &other) const
Expand a box to ensure that contains(other) is true (returning a new object).
std::vector< Point2D > getCorners() const
Get the corner points.
Box2D shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
double getHeight() const noexcept
1-d interval accessors
std::string toString() const
Return true if the box contains no points.
static double const INVALID
Value used to specify undefined coordinate values.
double getCenterY() const noexcept
Return true if the box contains no points.
Box2D(Box2D &&) noexcept=default
An integer coordinate rectangle.
int getBeginX() const noexcept
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
int getMinY() const noexcept
bool isDisjointFrom(Box2I const &other) const noexcept
Return true if there are no points in both this and other.
bool overlaps(Box2I 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).
int getHeight() const noexcept
Box2I(Interval const &x, Interval const &y)
Construct a box from a pair of intervals.
Box2I expandedTo(Point const &other) const
Expand the box to ensure that contains(other) is true (returning a new object).
Point2I const getMin() const noexcept
bool isEmpty() const noexcept
Return true if the box contains no points.
Point2I const getMax() const noexcept
Box2I erodedBy(Element buffer) const
1-d interval accessors
int getEndY() const noexcept
Box2I clippedTo(Box2I const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
Box2I erodedBy(Extent const &buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object).
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).
std::size_t hash_value() const noexcept
Return a hash of this object.
int getMinX() const noexcept
static Box2I makeCenteredBox(Point2D const ¢er, Extent const &size)
Create a box centered as closely as possible on a particular point.
int getWidth() const noexcept
int getBeginY() const noexcept
int getMaxX() const noexcept
Interval getX() const
1-d interval accessors
std::vector< Point2I > getCorners() const
Get the corner points.
Box2I reflectedAboutX(Element x) const
Reflect the box about a vertical line (returning a new object).
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
Box2I & operator=(Box2I &&) noexcept=default
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
bool contains(Element x, Element y) const noexcept
1-d interval accessors
std::string toString() const
1-d interval accessors
void flipTB(int yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
Box2I & operator=(Box2I const &) noexcept=default
Standard assignment operator.
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.
void swap(Box2I &other) noexcept
int getMaxY() const noexcept
double getCenterY() const noexcept
1-d interval accessors
Box2I(Box2I const &) noexcept=default
Standard copy constructor.
Box2I reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
Box2I(Box2I &&) noexcept=default
bool operator!=(Box2I const &other) const noexcept
Compare two boxes for equality.
Point2I const getEnd() const noexcept
bool operator==(Box2I const &other) const noexcept
Compare two boxes for equality.
Interval getY() const
1-d interval accessors
Extent2I const getDimensions() const noexcept
Box2I() noexcept
Construct an empty box.
double getCenterX() const noexcept
1-d interval accessors
Box2I dilatedBy(Element buffer) const
1-d interval accessors
bool intersects(Box2I const &other) const noexcept
1-d interval accessors
Box2I shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Point2D const getCenter() const noexcept
1-d interval accessors
void flipLR(int xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
int getEndX() const noexcept
A coordinate class intended to represent offsets and dimensions.
A floating-point coordinate rectangle geometry.
static IntervalD fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
A 1-d integer coordinate range.
static IntervalI fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
A coordinate class intended to represent absolute positions.
Extent< double, 2 > Extent2D
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Point< double, 2 > Point2D
Extent< int, 2 > Extent2I
lsst::geom::Box2D argument_type
size_t operator()(argument_type const &x) const noexcept
lsst::geom::Box2I argument_type
size_t operator()(argument_type const &x) const noexcept