32 : _minimum(minimum), _dimensions(maximum - minimum) {
33 for (
int n = 0; n < 2; ++n) {
34 if (_dimensions[n] < 0) {
36 _minimum[n] += _dimensions[n];
37 _dimensions[n] = -_dimensions[n];
49 for (
int n = 0; n < 2; ++n) {
50 if (_dimensions[n] == 0) {
53 }
else if (_dimensions[n] < 0) {
55 _minimum[n] += (_dimensions[n] + 1);
56 _dimensions[n] = -_dimensions[n];
65 "Box dimensions too large; integer overflow detected.");
89 Box2I(
IntervalI(other.getX(), translateEdgeHandling(edgeHandling)),
90 IntervalI(other.getY(), translateEdgeHandling(edgeHandling)))
109 ndarray::View<boost::fusion::vector2<ndarray::index::Range, ndarray::index::Range> >
Box2I::getSlices()
115 return getX().contains(point.getX()) && getY().contains(point.getY());
119 return getX().contains(other.getX()) && getY().contains(other.getY());
123 return !isDisjointFrom(other);
127 return getX().isDisjointFrom(other.getX()) || getY().isDisjointFrom(other.getY());
141 _minimum[0] = xextent - (_minimum[0] + _dimensions[0]);
148 _minimum[1] = yextent - (_minimum[1] + _dimensions[1]);
159 for (
int n = 0; n < 2; ++n) {
160 if (point[n] < _minimum[n]) {
161 _minimum[n] = point[n];
162 }
else if (point[n] > maximum[n]) {
163 maximum[n] = point[n];
166 _dimensions =
Extent2I(1) + maximum - _minimum;
178 for (
int n = 0; n < 2; ++n) {
179 if (otherMin[n] < _minimum[n]) {
180 _minimum[n] = otherMin[n];
182 if (otherMax[n] > maximum[n]) {
183 maximum[n] = otherMax[n];
186 _dimensions =
Extent2I(1) + maximum - _minimum;
190 if (isEmpty())
return;
191 if (other.isEmpty()) {
196 Point2I const& otherMin = other.getMin();
197 Point2I const otherMax = other.getMax();
198 for (
int n = 0; n < 2; ++n) {
199 if (otherMin[n] > _minimum[n]) {
200 _minimum[n] = otherMin[n];
202 if (otherMax[n] < maximum[n]) {
203 maximum[n] = otherMax[n];
206 if (
any(maximum.
lt(_minimum))) {
210 _dimensions =
Extent2I(1) + maximum - _minimum;
230 getY().reflectedAbout(
y));
244 return Box2I(getX().clippedTo(other.getX()),
245 getY().clippedTo(other.getY()));
249 return other._minimum == this->_minimum && other._dimensions == this->_dimensions;
253 return other._minimum != this->_minimum || other._dimensions != this->_dimensions;
277 : _minimum(minimum), _maximum(maximum) {
278 for (
int n = 0; n < 2; ++n) {
279 if (_minimum[n] == _maximum[n]) {
282 }
else if (_minimum[n] > _maximum[n]) {
294 : _minimum(corner), _maximum(corner +
dimensions) {
295 for (
int n = 0; n < 2; ++n) {
296 if (_minimum[n] == _maximum[n]) {
299 }
else if (_minimum[n] > _maximum[n]) {
313 if (other.isEmpty()) *
this =
Box2D();
318 corner.
shift(-0.5 * size);
325 return all(point.ge(this->getMin())) &&
all(point.lt(this->getMax()));
335 return !(other.isEmpty() || this->isEmpty() ||
any(other.getMax().le(this->getMin())) ||
336 any(other.getMin().ge(this->getMax())));
340 return !overlaps(other);
347 if (
any(_minimum.
ge(_maximum))) *
this =
Box2D();
359 _minimum[0] += _maximum[0];
360 _maximum[0] = _minimum[0] - _maximum[0];
361 _minimum[0] -= _maximum[0];
363 _minimum[0] = xextent - _minimum[0];
364 _maximum[0] = xextent - _maximum[0];
371 _minimum[1] += _maximum[1];
372 _maximum[1] = _minimum[1] - _maximum[1];
373 _minimum[1] -= _maximum[1];
375 _minimum[1] = yextent - _minimum[1];
376 _maximum[1] = yextent - _maximum[1];
388 for (
int n = 0; n < 2; ++n) {
389 if (point[n] < _minimum[n]) {
390 _minimum[n] = point[n];
391 }
else if (point[n] >= _maximum[n]) {
392 _maximum[n] = point[n];
399 if (other.isEmpty())
return;
400 if (this->isEmpty()) {
404 Point2D const& otherMin = other.getMin();
405 Point2D const& otherMax = other.getMax();
406 for (
int n = 0; n < 2; ++n) {
407 if (otherMin[n] < _minimum[n]) {
408 _minimum[n] = otherMin[n];
410 if (otherMax[n] > _maximum[n]) {
411 _maximum[n] = otherMax[n];
417 if (isEmpty())
return;
418 if (other.isEmpty()) {
422 Point2D const& otherMin = other.getMin();
423 Point2D const& otherMax = other.getMax();
424 for (
int n = 0; n < 2; ++n) {
425 if (otherMin[n] > _minimum[n]) {
426 _minimum[n] = otherMin[n];
428 if (otherMax[n] < _maximum[n]) {
429 _maximum[n] = otherMax[n];
432 if (
any(_maximum.le(_minimum))) {
455 getY().reflectedAbout(
y));
477 return (other.isEmpty() && this->isEmpty()) ||
478 (other._minimum == this->_minimum && other._maximum == this->_maximum);
482 return !(other.isEmpty() && other.isEmpty()) &&
483 (other._minimum != this->_minimum || other._maximum != this->_maximum);
506 if (box.
isEmpty())
return os <<
"Box2I()";
511 if (box.
isEmpty())
return os <<
"Box2D()";
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
afw::table::PointKey< int > dimensions
A floating-point coordinate rectangle geometry.
double getMaxY() const 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
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.
static Box2D makeCenteredBox(Point2D const ¢er, Extent const &size) noexcept
Create a box centered on a particular point.
Box2D() noexcept
Construct an empty box.
Point2D const getCenter() const noexcept
Return true if the box contains no points.
bool isEmpty() const noexcept
Return true if the box contains no points.
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).
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.
bool overlaps(Box2D const &other) const noexcept
Return true if any points in other are also in this.
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).
static double const INVALID
Value used to specify undefined coordinate values.
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).
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
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 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 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.
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
void flipTB(int yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
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.
int getMaxY() const noexcept
Box2I reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
bool operator!=(Box2I const &other) const noexcept
Compare two boxes for equality.
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.
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
bool contains(Element point) const
Return true if the interval contains the point.
A 1-d integer coordinate range.
EdgeHandlingEnum
Enum used to indicate how to handle conversions from floating-point to integer intervals.
@ SHRINK
Include only pixels that are wholly contained by the floating-point interval.
@ EXPAND
Include all pixels that overlap the floating-point interval at all.
CoordinateExpr< N > lt(Point< T, N > const &other) const noexcept
CoordinateExpr< N > ge(Point< T, N > const &other) const noexcept
void shift(Extent< T, N > const &offset) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Shift the point by the given offset.
Reports invalid arguments.
Reports errors in the logical structure of the program.
Reports when the result of an arithmetic operation is too large for the destination type.
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Point< double, 2 > Point2D
Extent< int, 2 > Extent2I
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
A base class for image defects.