LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lsst::geom::Box2I Class Referencefinal

An integer coordinate rectangle. More...

#include <Box.h>

Public Types

enum  EdgeHandlingEnum { EXPAND, SHRINK }
 
typedef Point2I Point
 
typedef Extent2I Extent
 
typedef int Element
 

Public Member Functions

 Box2I () noexcept
 Construct an empty box. More...
 
 Box2I (Point2I const &minimum, Point2I const &maximum, bool invert=true)
 Construct a box from its minimum and maximum points. More...
 
 Box2I (Point2I const &corner, Extent2I const &dimensions, bool invert=true)
 Construct a box from one corner and dimensions. More...
 
 Box2I (Box2D const &other, EdgeHandlingEnum edgeHandling=EXPAND)
 Construct an integer box from a floating-point box. More...
 
 Box2I (Box2I const &) noexcept=default
 Standard copy constructor. More...
 
 Box2I (Box2I &&) noexcept=default
 
 ~Box2I () noexcept=default
 
void swap (Box2I &other) noexcept
 
Box2Ioperator= (Box2I const &) noexcept=default
 Standard assignment operator. More...
 
Box2Ioperator= (Box2I &&) noexcept=default
 
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. More...
 
bool isEmpty () const noexcept
 Return true if the box contains no points. More...
 
bool contains (Point2I const &point) const noexcept
 Return true if the box contains the point. More...
 
bool contains (Box2I const &other) const noexcept
 Return true if all points contained by other are also contained by this. More...
 
bool overlaps (Box2I const &other) const noexcept
 Return true if any points in other are also in this. More...
 
void grow (int buffer)
 Increase the size of the box by the given buffer amount in all directions. More...
 
void grow (Extent2I const &buffer)
 Increase the size of the box by the given buffer amount in each direction. More...
 
void shift (Extent2I const &offset)
 Shift the position of the box by the given offset. More...
 
void flipLR (int xExtent)
 Flip a bounding box about the y-axis given a parent box of extent (xExtent). More...
 
void flipTB (int yExtent)
 Flip a bounding box about the x-axis given a parent box of extent (yExtent). More...
 
void include (Point2I const &point)
 Expand this to ensure that this->contains(point). More...
 
void include (Box2I const &other)
 Expand this to ensure that this->contains(other). More...
 
void clip (Box2I const &other) noexcept
 Shrink this to ensure that other.contains(*this). More...
 
bool operator== (Box2I const &other) const noexcept
 Compare two boxes for equality. More...
 
bool operator!= (Box2I const &other) const noexcept
 Compare two boxes for equality. More...
 
std::size_t hash_value () const noexcept
 Return a hash of this object. More...
 
std::vector< Point2IgetCorners () const
 Get the corner points. More...
 
std::string toString () const
 
Min/Max Accessors

Return the minimum and maximum coordinates of the box (inclusive).

Point2I const getMin () const noexcept
 
int getMinX () const noexcept
 
int getMinY () const noexcept
 
Point2I const getMax () const noexcept
 
int getMaxX () const noexcept
 
int getMaxY () const noexcept
 
Begin/End Accessors

Return STL-style begin (inclusive) and end (exclusive) coordinates for the box.

Point2I const getBegin () const noexcept
 
int getBeginX () const noexcept
 
int getBeginY () const noexcept
 
Point2I const getEnd () const noexcept
 
int getEndX () const noexcept
 
int getEndY () const noexcept
 
Size Accessors

Return the size of the box in pixels.

Extent2I const getDimensions () const noexcept
 
int getWidth () const noexcept
 
int getHeight () const noexcept
 
int getArea () const
 
Center Accessors

Return the center coordinate of the box.

Point2D const getCenter () const noexcept
 
double getCenterX () const noexcept
 
double getCenterY () const noexcept
 

Static Public Member Functions

static Box2I makeCenteredBox (Point2D const &center, Extent const &size)
 Create a box centered as closely as possible on a particular point. More...
 

Detailed Description

An integer coordinate rectangle.

Box2I is an inclusive box that represents a rectangular region of pixels. A box never has negative dimensions; the empty box is defined to have zero-size dimensions, and is treated as though it does not have a well-defined position (regardless of the return value of getMin() or getMax() for an empty box).

Examples:
image2.cc, and maskedImage2.cc.

Definition at line 54 of file Box.h.

Member Typedef Documentation

◆ Element

Definition at line 58 of file Box.h.

◆ Extent

Definition at line 57 of file Box.h.

◆ Point

Definition at line 56 of file Box.h.

Member Enumeration Documentation

◆ EdgeHandlingEnum

Enumerator
EXPAND 
SHRINK 

Definition at line 60 of file Box.h.

Constructor & Destructor Documentation

◆ Box2I() [1/6]

lsst::geom::Box2I::Box2I ( )
inlinenoexcept

Construct an empty box.

Definition at line 63 of file Box.h.

63 : _minimum(0), _dimensions(0) {}

◆ Box2I() [2/6]

lsst::geom::Box2I::Box2I ( Point2I const &  minimum,
Point2I const &  maximum,
bool  invert = true 
)

Construct a box from its minimum and maximum points.

Parameters
[in]minimumMinimum (lower left) coordinate (inclusive).
[in]maximumMaximum (upper right) coordinate (inclusive).
[in]invertIf true (default), swap the minimum and maximum coordinates if minimum > maximum instead of creating an empty box.

Definition at line 31 of file Box.cc.

32  : _minimum(minimum), _dimensions(maximum - minimum) {
33  for (int n = 0; n < 2; ++n) {
34  if (_dimensions[n] < 0) {
35  if (invert) {
36  _minimum[n] += _dimensions[n];
37  _dimensions[n] = -_dimensions[n];
38  } else {
39  *this = Box2I();
40  return;
41  }
42  }
43  }
44  _dimensions += Extent2I(1);
45 }
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
Extent< int, 2 > Extent2I
Definition: Extent.h:397
Box2I() noexcept
Construct an empty box.
Definition: Box.h:63

◆ Box2I() [3/6]

lsst::geom::Box2I::Box2I ( Point2I const &  corner,
Extent2I const &  dimensions,
bool  invert = true 
)

Construct a box from one corner and dimensions.

Parameters
[in]cornerReference coordinate. This is the lower left corner if both dimensions are positive, but a right corner or upper corner if the corresponding dimension is negative and invert is set.
[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.
Exceptions
lsst::pex::exceptions::OverflowErrorThrown if the maximum Point2I would overflow.

Definition at line 47 of file Box.cc.

48  : _minimum(corner), _dimensions(dimensions) {
49  for (int n = 0; n < 2; ++n) {
50  if (_dimensions[n] == 0) {
51  *this = Box2I();
52  return;
53  } else if (_dimensions[n] < 0) {
54  if (invert) {
55  _minimum[n] += (_dimensions[n] + 1);
56  _dimensions[n] = -_dimensions[n];
57  } else {
58  *this = Box2I();
59  return;
60  }
61  }
62  }
63  if (!isEmpty() && any(getMin().gt(getMax()))) {
64  throw LSST_EXCEPT(pex::exceptions::OverflowError,
65  "Box dimensions too large; integer overflow detected.");
66  }
67 }
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
Point2I const getMax() const noexcept
Definition: Box.h:147
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
Point2I const getMin() const noexcept
Definition: Box.h:143
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Box2I() noexcept
Construct an empty box.
Definition: Box.h:63

◆ Box2I() [4/6]

lsst::geom::Box2I::Box2I ( Box2D const &  other,
EdgeHandlingEnum  edgeHandling = EXPAND 
)
explicit

Construct an integer box from a floating-point box.

Floating-point to integer 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. Converting a floating-point box to an integer box thus requires a choice on how to handle pixels which are only partially contained by the input floating-point box.

Parameters
[in]otherA floating-point box to convert.
[in]edgeHandlingIf EXPAND, the integer box will contain any pixels that overlap the floating-point box. If SHRINK, the integer box will contain only pixels completely contained by the floating-point box.
Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if other is not finite.

Definition at line 69 of file Box.cc.

69  : _minimum(), _dimensions() {
70  if (other.isEmpty()) {
71  *this = Box2I();
72  return;
73  }
74  if (!std::isfinite(other.getMinX()) || !std::isfinite(other.getMinY()) ||
75  !std::isfinite(other.getMaxX()) || !std::isfinite(other.getMaxY())) {
76  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Cannot convert non-finite Box2D to Box2I");
77  }
78  Point2D fpMin(other.getMin() + Extent2D(0.5));
79  Point2D fpMax(other.getMax() - Extent2D(0.5));
80  switch (edgeHandling) {
81  case EXPAND:
82  for (int n = 0; n < 2; ++n) {
83  _minimum[n] = static_cast<int>(std::floor(fpMin[n]));
84  _dimensions[n] = static_cast<int>(std::ceil(fpMax[n])) + 1 - _minimum[n];
85  }
86  break;
87  case SHRINK:
88  for (int n = 0; n < 2; ++n) {
89  _minimum[n] = static_cast<int>(std::ceil(fpMin[n]));
90  _dimensions[n] = static_cast<int>(std::floor(fpMax[n])) + 1 - _minimum[n];
91  }
92  break;
93  }
94 }
T ceil(T... args)
T floor(T... args)
Point< double, 2 > Point2D
Definition: Point.h:324
T isfinite(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
ItemVariant const * other
Definition: Schema.cc:56
Box2I() noexcept
Construct an empty box.
Definition: Box.h:63
Extent< double, 2 > Extent2D
Definition: Extent.h:400

◆ Box2I() [5/6]

lsst::geom::Box2I::Box2I ( Box2I const &  )
defaultnoexcept

Standard copy constructor.

◆ Box2I() [6/6]

lsst::geom::Box2I::Box2I ( Box2I &&  )
defaultnoexcept

◆ ~Box2I()

lsst::geom::Box2I::~Box2I ( )
defaultnoexcept

Member Function Documentation

◆ clip()

void lsst::geom::Box2I::clip ( Box2I const &  other)
noexcept

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

In particular, if other and this box do not overlap this box will become empty.

Parameters
otherthe box that must contain this one

Definition at line 194 of file Box.cc.

194  {
195  if (isEmpty()) return;
196  if (other.isEmpty()) {
197  *this = Box2I();
198  return;
199  }
200  Point2I maximum(getMax());
201  Point2I const& otherMin = other.getMin();
202  Point2I const otherMax = other.getMax();
203  for (int n = 0; n < 2; ++n) {
204  if (otherMin[n] > _minimum[n]) {
205  _minimum[n] = otherMin[n];
206  }
207  if (otherMax[n] < maximum[n]) {
208  maximum[n] = otherMax[n];
209  }
210  }
211  if (any(maximum.lt(_minimum))) {
212  *this = Box2I();
213  return;
214  }
215  _dimensions = Extent2I(1) + maximum - _minimum;
216 }
Point2I const getMax() const noexcept
Definition: Box.h:147
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
Point< int, 2 > Point2I
Definition: Point.h:321
Extent< int, 2 > Extent2I
Definition: Extent.h:397
ItemVariant const * other
Definition: Schema.cc:56
Box2I() noexcept
Construct an empty box.
Definition: Box.h:63

◆ contains() [1/2]

bool lsst::geom::Box2I::contains ( Point2I const &  point) const
noexcept

Return true if the box contains the point.

Definition at line 117 of file Box.cc.

117  {
118  return all(point.ge(this->getMin())) && all(point.le(this->getMax()));
119 }
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.

◆ contains() [2/2]

bool lsst::geom::Box2I::contains ( Box2I const &  other) const
noexcept

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.

Definition at line 121 of file Box.cc.

121  {
122  return other.isEmpty() ||
123  (all(other.getMin().ge(this->getMin())) && all(other.getMax().le(this->getMax())));
124 }
Point2I const getMax() const noexcept
Definition: Box.h:147
Point2I const getMin() const noexcept
Definition: Box.h:143
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.
ItemVariant const * other
Definition: Schema.cc:56

◆ flipLR()

void lsst::geom::Box2I::flipLR ( int  xExtent)

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

Definition at line 143 of file Box.cc.

143  {
144  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
145  // Apply flip about y-axis assumine parent coordinate system
146  _minimum[0] = xextent - (_minimum[0] + _dimensions[0]);
147  // _dimensions should remain unchanged
148 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194

◆ flipTB()

void lsst::geom::Box2I::flipTB ( int  yExtent)

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

Definition at line 150 of file Box.cc.

150  {
151  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
152  // Apply flip about y-axis assumine parent coordinate system
153  _minimum[1] = yextent - (_minimum[1] + _dimensions[1]);
154  // _dimensions should remain unchanged
155 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194

◆ getArea()

int lsst::geom::Box2I::getArea ( ) const
inline

Definition at line 176 of file Box.h.

176 { return getWidth() * getHeight(); }
int getHeight() const noexcept
Definition: Box.h:175
int getWidth() const noexcept
Definition: Box.h:174

◆ getBegin()

Point2I const lsst::geom::Box2I::getBegin ( ) const
inlinenoexcept

Definition at line 158 of file Box.h.

158 { return _minimum; }

◆ getBeginX()

int lsst::geom::Box2I::getBeginX ( ) const
inlinenoexcept

Definition at line 159 of file Box.h.

159 { return _minimum.getX(); }

◆ getBeginY()

int lsst::geom::Box2I::getBeginY ( ) const
inlinenoexcept

Definition at line 160 of file Box.h.

160 { return _minimum.getY(); }

◆ getCenter()

Point2D const lsst::geom::Box2I::getCenter ( ) const
noexcept

Definition at line 96 of file Box.cc.

96  {
97  return Box2D(*this).getCenter();
98 }

◆ getCenterX()

double lsst::geom::Box2I::getCenterX ( ) const
inlinenoexcept

Definition at line 186 of file Box.h.

186 { return this->getCenter().getX(); }
Point2D const getCenter() const noexcept
Definition: Box.cc:96

◆ getCenterY()

double lsst::geom::Box2I::getCenterY ( ) const
inlinenoexcept

Definition at line 187 of file Box.h.

187 { return this->getCenter().getY(); }
Point2D const getCenter() const noexcept
Definition: Box.cc:96

◆ getCorners()

std::vector< Point2I > lsst::geom::Box2I::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)

Definition at line 231 of file Box.cc.

231  {
232  std::vector<Point2I> retVec;
233  retVec.push_back(getMin());
234  retVec.push_back(Point2I(getMaxX(), getMinY()));
235  retVec.push_back(getMax());
236  retVec.push_back(Point2I(getMinX(), getMaxY()));
237  return retVec;
238 }
Point2I const getMax() const noexcept
Definition: Box.h:147
Point2I const getMin() const noexcept
Definition: Box.h:143
T push_back(T... args)
int getMaxY() const noexcept
Definition: Box.h:149
Point< int, 2 > Point2I
Definition: Point.h:321
int getMaxX() const noexcept
Definition: Box.h:148
int getMinX() const noexcept
Definition: Box.h:144
STL class.
int getMinY() const noexcept
Definition: Box.h:145

◆ getDimensions()

Extent2I const lsst::geom::Box2I::getDimensions ( ) const
inlinenoexcept

Definition at line 173 of file Box.h.

173 { return _dimensions; }

◆ getEnd()

Point2I const lsst::geom::Box2I::getEnd ( ) const
inlinenoexcept

Definition at line 162 of file Box.h.

162 { return _minimum + _dimensions; }

◆ getEndX()

int lsst::geom::Box2I::getEndX ( ) const
inlinenoexcept

Definition at line 163 of file Box.h.

163 { return _minimum.getX() + _dimensions.getX(); }

◆ getEndY()

int lsst::geom::Box2I::getEndY ( ) const
inlinenoexcept

Definition at line 164 of file Box.h.

164 { return _minimum.getY() + _dimensions.getY(); }

◆ getHeight()

int lsst::geom::Box2I::getHeight ( ) const
inlinenoexcept

Definition at line 175 of file Box.h.

175 { return _dimensions.getY(); }

◆ getMax()

Point2I const lsst::geom::Box2I::getMax ( ) const
inlinenoexcept

Definition at line 147 of file Box.h.

147 { return _minimum + _dimensions - Extent2I(1); }
Extent< int, 2 > Extent2I
Definition: Extent.h:397

◆ getMaxX()

int lsst::geom::Box2I::getMaxX ( ) const
inlinenoexcept

Definition at line 148 of file Box.h.

148 { return _minimum.getX() + _dimensions.getX() - 1; }

◆ getMaxY()

int lsst::geom::Box2I::getMaxY ( ) const
inlinenoexcept

Definition at line 149 of file Box.h.

149 { return _minimum.getY() + _dimensions.getY() - 1; }

◆ getMin()

Point2I const lsst::geom::Box2I::getMin ( ) const
inlinenoexcept

Definition at line 143 of file Box.h.

143 { return _minimum; }

◆ getMinX()

int lsst::geom::Box2I::getMinX ( ) const
inlinenoexcept

Definition at line 144 of file Box.h.

144 { return _minimum.getX(); }

◆ getMinY()

int lsst::geom::Box2I::getMinY ( ) const
inlinenoexcept

Definition at line 145 of file Box.h.

145 { return _minimum.getY(); }

◆ getSlices()

ndarray::View< boost::fusion::vector2< ndarray::index::Range, ndarray::index::Range > > lsst::geom::Box2I::getSlices ( ) const

Return slices to extract the box's region from an ndarray::Array.

Definition at line 112 of file Box.cc.

113  {
114  return ndarray::view(getBeginY(), getEndY())(getBeginX(), getEndX());
115 }
int getEndY() const noexcept
Definition: Box.h:164
int getBeginY() const noexcept
Definition: Box.h:160
int getBeginX() const noexcept
Definition: Box.h:159
int getEndX() const noexcept
Definition: Box.h:163

◆ getWidth()

int lsst::geom::Box2I::getWidth ( ) const
inlinenoexcept

Definition at line 174 of file Box.h.

174 { return _dimensions.getX(); }

◆ grow() [1/2]

void lsst::geom::Box2I::grow ( int  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 219 of file Box.h.

219 { grow(Extent2I(buffer)); }
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
Definition: Box.h:219
Extent< int, 2 > Extent2I
Definition: Extent.h:397

◆ grow() [2/2]

void lsst::geom::Box2I::grow ( Extent2I 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.

Definition at line 131 of file Box.cc.

131  {
132  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
133  _minimum -= buffer;
134  _dimensions += buffer * 2;
135  if (any(_dimensions.le(0))) *this = Box2I();
136 }
CoordinateExpr< N > le(Extent< T, N > const &other) const noexcept
Definition: Extent.cc:68
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
Box2I() noexcept
Construct an empty box.
Definition: Box.h:63

◆ hash_value()

std::size_t lsst::geom::Box2I::hash_value ( ) const
noexcept

Return a hash of this object.

Definition at line 226 of file Box.cc.

226  {
227  // Completely arbitrary seed
228  return utils::hashCombine(17, _minimum, _dimensions);
229 }
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35

◆ include() [1/2]

void lsst::geom::Box2I::include ( Point2I const &  point)

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

Definition at line 157 of file Box.cc.

157  {
158  if (isEmpty()) {
159  _minimum = point;
160  _dimensions = Extent2I(1);
161  return;
162  }
163  Point2I maximum(getMax());
164  for (int n = 0; n < 2; ++n) {
165  if (point[n] < _minimum[n]) {
166  _minimum[n] = point[n];
167  } else if (point[n] > maximum[n]) {
168  maximum[n] = point[n];
169  }
170  }
171  _dimensions = Extent2I(1) + maximum - _minimum;
172 }
Point2I const getMax() const noexcept
Definition: Box.h:147
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194
Point< int, 2 > Point2I
Definition: Point.h:321
Extent< int, 2 > Extent2I
Definition: Extent.h:397

◆ include() [2/2]

void lsst::geom::Box2I::include ( Box2I const &  other)

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

Definition at line 174 of file Box.cc.

174  {
175  if (other.isEmpty()) return;
176  if (this->isEmpty()) {
177  *this = other;
178  return;
179  }
180  Point2I maximum(getMax());
181  Point2I const& otherMin = other.getMin();
182  Point2I const otherMax = other.getMax();
183  for (int n = 0; n < 2; ++n) {
184  if (otherMin[n] < _minimum[n]) {
185  _minimum[n] = otherMin[n];
186  }
187  if (otherMax[n] > maximum[n]) {
188  maximum[n] = otherMax[n];
189  }
190  }
191  _dimensions = Extent2I(1) + maximum - _minimum;
192 }
Point2I const getMax() const noexcept
Definition: Box.h:147
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194
Point< int, 2 > Point2I
Definition: Point.h:321
Extent< int, 2 > Extent2I
Definition: Extent.h:397
ItemVariant const * other
Definition: Schema.cc:56

◆ isEmpty()

bool lsst::geom::Box2I::isEmpty ( ) const
inlinenoexcept

Return true if the box contains no points.

Definition at line 194 of file Box.h.

194 { return _dimensions.getX() == 0 && _dimensions.getY() == 0; }

◆ makeCenteredBox()

Box2I lsst::geom::Box2I::makeCenteredBox ( Point2D const &  center,
Box2I::Extent const &  size 
)
static

Create a box centered as closely as possible on a particular point.

Parameters
centerThe desired center of the box.
sizeThe desired width and height (in that order) of the box.
Returns
if size is positive, a box with size size; otherwise, an empty box. If the returned box is not empty, its center shall be within half a pixel of center in either dimension.
Exceptions
lsst::pex::exceptions::OverflowErrorThrown if the resulting box would overflow.
lsst::pex::exceptions::InvalidParameterErrorThrown if center is not finite.

Definition at line 100 of file Box.cc.

100  {
101  if (!std::isfinite(center[0]) || !std::isfinite(center[1])) {
102  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Cannot make Box2I with non-finite center");
103  }
104 
105  lsst::geom::Point2D corner(center);
106  corner.shift(-0.5 * lsst::geom::Extent2D(size));
107  // compensate for Box2I's coordinate conventions (where max = min + size - 1)
108  corner.shift(lsst::geom::Extent2D(0.5, 0.5));
109  return lsst::geom::Box2I(lsst::geom::Point2I(corner), size, false);
110 }
T isfinite(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
An integer coordinate rectangle.
Definition: Box.h:54

◆ operator!=()

bool lsst::geom::Box2I::operator!= ( Box2I const &  other) const
noexcept

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 222 of file Box.cc.

222  {
223  return other._minimum != this->_minimum || other._dimensions != this->_dimensions;
224 }
ItemVariant const * other
Definition: Schema.cc:56

◆ operator=() [1/2]

Box2I& lsst::geom::Box2I::operator= ( Box2I const &  )
defaultnoexcept

Standard assignment operator.

◆ operator=() [2/2]

Box2I& lsst::geom::Box2I::operator= ( Box2I &&  )
defaultnoexcept

◆ operator==()

bool lsst::geom::Box2I::operator== ( Box2I const &  other) const
noexcept

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 218 of file Box.cc.

218  {
219  return other._minimum == this->_minimum && other._dimensions == this->_dimensions;
220 }
ItemVariant const * other
Definition: Schema.cc:56

◆ overlaps()

bool lsst::geom::Box2I::overlaps ( Box2I const &  other) const
noexcept

Return true if any points in other are also in this.

Any overlap operation involving an empty box returns false.

Definition at line 126 of file Box.cc.

126  {
127  return !(other.isEmpty() || this->isEmpty() || any(other.getMax().lt(this->getMin())) ||
128  any(other.getMin().gt(this->getMax())));
129 }
Point2I const getMax() const noexcept
Definition: Box.h:147
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
Point2I const getMin() const noexcept
Definition: Box.h:143
ItemVariant const * other
Definition: Schema.cc:56

◆ shift()

void lsst::geom::Box2I::shift ( Extent2I const &  offset)

Shift the position of the box by the given offset.

Definition at line 138 of file Box.cc.

138  {
139  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
140  _minimum += offset;
141 }
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:194

◆ swap()

void lsst::geom::Box2I::swap ( Box2I other)
inlinenoexcept

Definition at line 128 of file Box.h.

128  {
129  _minimum.swap(other._minimum);
130  _dimensions.swap(other._dimensions);
131  }
void swap(Point &other) noexcept
Definition: Point.h:202
void swap(Extent &other) noexcept
Definition: Extent.h:245
ItemVariant const * other
Definition: Schema.cc:56

◆ toString()

std::string lsst::geom::Box2I::toString ( ) const
inline

Definition at line 277 of file Box.h.

277  {
278  return (boost::format("Box2I(%s,%s)") % _minimum.toString() % _dimensions.toString()).str();
279  }
std::string toString() const
Definition: Point.h:143
std::string toString() const
Definition: Extent.h:179
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168

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