LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+13,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+11,19.0.0-21-g2644856+13,19.0.0-23-g84eeccb+1,19.0.0-24-g878c510+1,19.0.0-25-g6c8df7140,19.0.0-25-gb330496+1,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+12,19.0.0-3-g9c54d0d+12,19.0.0-3-gca68e65+8,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+11,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+13,19.0.0-30-g9c3fd16+1,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+13,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+13,19.0.0-4-ge404a01+12,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+13,19.0.0-6-gbaebbfb+12,19.0.0-61-gec4c6e08+1,19.0.0-7-g039c0b5+11,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+13,19.0.0-71-g41c0270,19.0.0-9-g2f02add+1,19.0.0-9-g463f923+12,w.2020.22
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
 
using Interval = IntervalI
 

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 (Interval const &x, Interval const &y)
 Construct a box from a pair of intervals. 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
 
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
 

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...
 

Center Accessors

Return the center coordinate of the box.

Point2D const getCenter () const noexcept
 1-d interval accessors More...
 
double getCenterX () const noexcept
 1-d interval accessors More...
 
double getCenterY () const noexcept
 1-d interval accessors More...
 
Interval getX () const
 1-d interval accessors More...
 
Interval getY () const
 1-d interval accessors More...
 
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 (Element x, Element y) const noexcept
 1-d interval accessors 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...
 
bool intersects (Box2I const &other) const noexcept
 1-d interval accessors More...
 
bool isDisjointFrom (Box2I const &other) const noexcept
 Return true if there are no points in both this and other. 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...
 
Box2I dilatedBy (Extent const &buffer) const
 Increase the size of the box by the given amount(s) on all sides (returning a new object). More...
 
Box2I dilatedBy (Element buffer) const
 1-d interval accessors More...
 
Box2I erodedBy (Extent const &buffer) const
 Decrease the size of the box by the given amount(s) on all sides (returning a new object). More...
 
Box2I erodedBy (Element buffer) const
 1-d interval accessors More...
 
Box2I shiftedBy (Extent const &offset) const
 Shift the position of the box by the given offset (returning a new object). More...
 
Box2I reflectedAboutX (Element x) const
 Reflect the box about a vertical line (returning a new object). More...
 
Box2I reflectedAboutY (Element y) const
 Reflect the box about a horizontal line (returning a new object). More...
 
Box2I expandedTo (Point const &other) const
 Expand the box to ensure that contains(other) is true (returning a new object). More...
 
Box2I expandedTo (Box2I const &other) const
 1-d interval accessors More...
 
Box2I clippedTo (Box2I const &other) const noexcept
 Shrink an interval to ensure that it is contained by other (returning a new object). 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
 1-d interval accessors 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 55 of file Box.h.

Member Typedef Documentation

◆ Element

Definition at line 59 of file Box.h.

◆ Extent

Definition at line 58 of file Box.h.

◆ Interval

Definition at line 61 of file Box.h.

◆ Point

Definition at line 57 of file Box.h.

Member Enumeration Documentation

◆ EdgeHandlingEnum

Enumerator
EXPAND 
SHRINK 

Definition at line 63 of file Box.h.

63 { EXPAND, SHRINK };

Constructor & Destructor Documentation

◆ Box2I() [1/7]

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

Construct an empty box.

Definition at line 66 of file Box.h.

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

◆ Box2I() [2/7]

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 }

◆ Box2I() [3/7]

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 }

◆ Box2I() [4/7]

lsst::geom::Box2I::Box2I ( Interval const &  x,
Interval const &  y 
)
inline

Construct a box from a pair of intervals.

Parameters
[in]xExtent in x direction.
[in]yExtent in y direction.

Definition at line 98 of file Box.h.

98  :
99  Box2I(Point(x.getMin(), y.getMin()), Point(x.getMax(), y.getMax()), false)
100  {}

◆ Box2I() [5/7]

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 88 of file Box.cc.

88  :
89  Box2I(IntervalI(other.getX(), translateEdgeHandling(edgeHandling)),
90  IntervalI(other.getY(), translateEdgeHandling(edgeHandling)))
91 {}

◆ Box2I() [6/7]

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

Standard copy constructor.

◆ Box2I() [7/7]

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 189 of file Box.cc.

189  {
190  if (isEmpty()) return;
191  if (other.isEmpty()) {
192  *this = Box2I();
193  return;
194  }
195  Point2I maximum(getMax());
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];
201  }
202  if (otherMax[n] < maximum[n]) {
203  maximum[n] = otherMax[n];
204  }
205  }
206  if (any(maximum.lt(_minimum))) {
207  *this = Box2I();
208  return;
209  }
210  _dimensions = Extent2I(1) + maximum - _minimum;
211 }

◆ clippedTo()

Box2I lsst::geom::Box2I::clippedTo ( Box2I const &  other) const
noexcept

Shrink an interval to ensure that it is contained by other (returning a new object).

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

Definition at line 243 of file Box.cc.

243  {
244  return Box2I(getX().clippedTo(other.getX()),
245  getY().clippedTo(other.getY()));
246 }

◆ contains() [1/3]

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 118 of file Box.cc.

118  {
119  return getX().contains(other.getX()) && getY().contains(other.getY());
120 }

◆ contains() [2/3]

bool lsst::geom::Box2I::contains ( Element  x,
Element  y 
) const
inlinenoexcept

1-d interval accessors

Definition at line 218 of file Box.h.

218 { return contains(Point2I(x, y)); }

◆ contains() [3/3]

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

Return true if the box contains the point.

Definition at line 114 of file Box.cc.

114  {
115  return getX().contains(point.getX()) && getY().contains(point.getY());
116 }

◆ dilatedBy() [1/2]

Box2I lsst::geom::Box2I::dilatedBy ( Element  buffer) const
inline

1-d interval accessors

Definition at line 295 of file Box.h.

295  {
296  return dilatedBy(Extent(buffer, buffer));
297  }

◆ dilatedBy() [2/2]

Box2I lsst::geom::Box2I::dilatedBy ( Extent const &  buffer) const

Increase the size of the box by the given amount(s) on all sides (returning a new object).

If buffer is negative, this is equivalent to eroding by -buffer.

If a final dimension of the box is less than or equal to zero, the new box will be empty.

Empty boxes remain empty after dilation.

Definition at line 213 of file Box.cc.

213  {
214  return Box2I(getX().dilatedBy(buffer.getX()),
215  getY().dilatedBy(buffer.getY()));
216 }

◆ erodedBy() [1/2]

Box2I lsst::geom::Box2I::erodedBy ( Element  buffer) const
inline

1-d interval accessors

Definition at line 313 of file Box.h.

313 { return dilatedBy(-buffer); }

◆ erodedBy() [2/2]

Box2I lsst::geom::Box2I::erodedBy ( Extent const &  buffer) const
inline

Decrease the size of the box by the given amount(s) on all sides (returning a new object).

If buffer is negative, this is equivalent to dilating by -buffer.

If a final dimension of the box is less than or equal to zero, the new box will be empty.

Empty boxes remain empty after erosion.

Definition at line 312 of file Box.h.

312 { return dilatedBy(-buffer); }

◆ expandedTo() [1/2]

Box2I lsst::geom::Box2I::expandedTo ( Box2I const &  other) const

1-d interval accessors

Definition at line 238 of file Box.cc.

238  {
239  return Box2I(getX().expandedTo(other.getX()),
240  getY().expandedTo(other.getY()));
241 }

◆ expandedTo() [2/2]

Box2I lsst::geom::Box2I::expandedTo ( Point const &  other) const

Expand the box to ensure that contains(other) is true (returning a new object).

Expanding an empty box with a single point yields an box with size=1 at that point; expanding an empty box with a second box is equivalent to assignment.

Definition at line 233 of file Box.cc.

233  {
234  return Box2I(getX().expandedTo(other.getX()),
235  getY().expandedTo(other.getY()));
236 }

◆ 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 138 of file Box.cc.

138  {
139  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
140  // Apply flip about y-axis assumine parent coordinate system
141  _minimum[0] = xextent - (_minimum[0] + _dimensions[0]);
142  // _dimensions should remain unchanged
143 }

◆ 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 145 of file Box.cc.

145  {
146  if (isEmpty()) return; // should we throw an exception here instead of a no-op?
147  // Apply flip about y-axis assumine parent coordinate system
148  _minimum[1] = yextent - (_minimum[1] + _dimensions[1]);
149  // _dimensions should remain unchanged
150 }

◆ getArea()

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

Definition at line 189 of file Box.h.

189 { return getWidth() * getHeight(); }

◆ getBegin()

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

Definition at line 171 of file Box.h.

171 { return _minimum; }

◆ getBeginX()

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

Definition at line 172 of file Box.h.

172 { return _minimum.getX(); }

◆ getBeginY()

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

Definition at line 173 of file Box.h.

173 { return _minimum.getY(); }

◆ getCenter()

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

1-d interval accessors

Definition at line 93 of file Box.cc.

93  {
94  return Box2D(*this).getCenter();
95 }

◆ getCenterX()

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

1-d interval accessors

Definition at line 199 of file Box.h.

199 { return this->getCenter().getX(); }

◆ getCenterY()

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

1-d interval accessors

Definition at line 200 of file Box.h.

200 { return this->getCenter().getY(); }

◆ 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 261 of file Box.cc.

261  {
262  std::vector<Point2I> retVec;
263  retVec.push_back(getMin());
264  retVec.push_back(Point2I(getMaxX(), getMinY()));
265  retVec.push_back(getMax());
266  retVec.push_back(Point2I(getMinX(), getMaxY()));
267  return retVec;
268 }

◆ getDimensions()

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

Definition at line 186 of file Box.h.

186 { return _dimensions; }

◆ getEnd()

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

Definition at line 175 of file Box.h.

175 { return _minimum + _dimensions; }

◆ getEndX()

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

Definition at line 176 of file Box.h.

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

◆ getEndY()

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

Definition at line 177 of file Box.h.

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

◆ getHeight()

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

Definition at line 188 of file Box.h.

188 { return _dimensions.getY(); }

◆ getMax()

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

Definition at line 160 of file Box.h.

160 { return _minimum + _dimensions - Extent2I(1); }

◆ getMaxX()

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

Definition at line 161 of file Box.h.

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

◆ getMaxY()

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

Definition at line 162 of file Box.h.

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

◆ getMin()

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

Definition at line 156 of file Box.h.

156 { return _minimum; }

◆ getMinX()

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

Definition at line 157 of file Box.h.

157 { return _minimum.getX(); }

◆ getMinY()

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

Definition at line 158 of file Box.h.

158 { 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 109 of file Box.cc.

110  {
111  return ndarray::view(getBeginY(), getEndY())(getBeginX(), getEndX());
112 }

◆ getWidth()

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

Definition at line 187 of file Box.h.

187 { return _dimensions.getX(); }

◆ getX()

Interval lsst::geom::Box2I::getX ( ) const
inline

1-d interval accessors

Definition at line 205 of file Box.h.

205 { return Interval::fromMinSize(getMinX(), getWidth()); }

◆ getY()

Interval lsst::geom::Box2I::getY ( ) const
inline

1-d interval accessors

Definition at line 206 of file Box.h.

206 { return Interval::fromMinSize(getMinY(), getHeight()); }

◆ grow() [1/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 130 of file Box.cc.

130  {
131  *this = dilatedBy(buffer);
132 }

◆ grow() [2/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 249 of file Box.h.

249 { grow(Extent2I(buffer)); }

◆ hash_value()

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

Return a hash of this object.

Definition at line 256 of file Box.cc.

256  {
257  // Completely arbitrary seed
258  return utils::hashCombine(17, _minimum, _dimensions);
259 }

◆ include() [1/2]

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

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

Definition at line 169 of file Box.cc.

169  {
170  if (other.isEmpty()) return;
171  if (this->isEmpty()) {
172  *this = other;
173  return;
174  }
175  Point2I maximum(getMax());
176  Point2I const& otherMin = other.getMin();
177  Point2I const otherMax = other.getMax();
178  for (int n = 0; n < 2; ++n) {
179  if (otherMin[n] < _minimum[n]) {
180  _minimum[n] = otherMin[n];
181  }
182  if (otherMax[n] > maximum[n]) {
183  maximum[n] = otherMax[n];
184  }
185  }
186  _dimensions = Extent2I(1) + maximum - _minimum;
187 }

◆ include() [2/2]

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

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

Definition at line 152 of file Box.cc.

152  {
153  if (isEmpty()) {
154  _minimum = point;
155  _dimensions = Extent2I(1);
156  return;
157  }
158  Point2I maximum(getMax());
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];
164  }
165  }
166  _dimensions = Extent2I(1) + maximum - _minimum;
167 }

◆ intersects()

bool lsst::geom::Box2I::intersects ( Box2I const &  other) const
inlinenoexcept

1-d interval accessors

Definition at line 235 of file Box.h.

235 { return overlaps(other); }

◆ isDisjointFrom()

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

Return true if there are no points in both this and other.

Definition at line 126 of file Box.cc.

126  {
127  return getX().isDisjointFrom(other.getX()) || getY().isDisjointFrom(other.getY());
128 }

◆ isEmpty()

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

Return true if the box contains no points.

Definition at line 213 of file Box.h.

213 { 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 97 of file Box.cc.

97  {
98  if (!std::isfinite(center[0]) || !std::isfinite(center[1])) {
99  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Cannot make Box2I with non-finite center");
100  }
101 
102  lsst::geom::Point2D corner(center);
103  corner.shift(-0.5 * lsst::geom::Extent2D(size));
104  // compensate for Box2I's coordinate conventions (where max = min + size - 1)
105  corner.shift(lsst::geom::Extent2D(0.5, 0.5));
106  return lsst::geom::Box2I(lsst::geom::Point2I(corner), size, false);
107 }

◆ operator!=()

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

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 252 of file Box.cc.

252  {
253  return other._minimum != this->_minimum || other._dimensions != this->_dimensions;
254 }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Standard assignment operator.

◆ operator==()

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

Compare two boxes for equality.

All empty boxes are equal.

Definition at line 248 of file Box.cc.

248  {
249  return other._minimum == this->_minimum && other._dimensions == this->_dimensions;
250 }

◆ 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 122 of file Box.cc.

122  {
123  return !isDisjointFrom(other);
124 }

◆ reflectedAboutX()

Box2I lsst::geom::Box2I::reflectedAboutX ( Element  x) const

Reflect the box about a vertical line (returning a new object).

Empty boxes remain empty when reflected.

Definition at line 223 of file Box.cc.

223  {
224  return Box2I(getX().reflectedAbout(x),
225  getY());
226 }

◆ reflectedAboutY()

Box2I lsst::geom::Box2I::reflectedAboutY ( Element  y) const

Reflect the box about a horizontal line (returning a new object).

Empty boxes remain empty when reflected.

Definition at line 228 of file Box.cc.

228  {
229  return Box2I(getX(),
230  getY().reflectedAbout(y));
231 }

◆ shift()

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

Shift the position of the box by the given offset.

Definition at line 134 of file Box.cc.

134  {
135  *this = shiftedBy(offset);
136 }

◆ shiftedBy()

Box2I lsst::geom::Box2I::shiftedBy ( Extent const &  offset) const

Shift the position of the box by the given offset (returning a new object).

Empty boxes remain empty when shifted.

Definition at line 218 of file Box.cc.

218  {
219  return Box2I(getX().shiftedBy(offset.getX()),
220  getY().shiftedBy(offset.getY()));
221 }

◆ swap()

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

Definition at line 141 of file Box.h.

141  {
142  _minimum.swap(other._minimum);
143  _dimensions.swap(other._dimensions);
144  }

◆ toString()

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

1-d interval accessors

Definition at line 385 of file Box.h.

385  {
386  return (boost::format("Box2I(%s,%s)") % _minimum.toString() % _dimensions.toString()).str();
387  }

The documentation for this class was generated from the following files:
y
int y
Definition: SpanSet.cc:49
lsst::geom::Box2I::getMax
Point2I const getMax() const noexcept
Definition: Box.h:160
lsst::geom::Box2I::getHeight
int getHeight() const noexcept
Definition: Box.h:188
std::vector
STL class.
pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
lsst::geom::Box2I::getMin
Point2I const getMin() const noexcept
Definition: Box.h:156
lsst::geom::IntervalI::isDisjointFrom
bool isDisjointFrom(IntervalI const &other) const noexcept
Return true if there are no points in both this and other.
Definition: Interval.cc:130
lsst::geom::Box2I::Point
Point2I Point
Definition: Box.h:57
lsst::geom::Point::swap
void swap(Point &other) noexcept
Definition: Point.h:202
lsst::geom::Box2I::isEmpty
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:213
lsst::geom::Box2I::getEndY
int getEndY() const noexcept
Definition: Box.h:177
lsst::geom::Box2I::EXPAND
@ EXPAND
Definition: Box.h:63
std::vector::push_back
T push_back(T... args)
lsst::geom::Box2I::shiftedBy
Box2I shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Definition: Box.cc:218
lsst::geom::Box2I::getY
Interval getY() const
1-d interval accessors
Definition: Box.h:206
lsst::geom::Box2I::getBeginY
int getBeginY() const noexcept
Definition: Box.h:173
std::isfinite
T isfinite(T... args)
lsst::geom::Box2I::getWidth
int getWidth() const noexcept
Definition: Box.h:187
lsst::geom::Box2I::grow
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
Definition: Box.h:249
x
double x
Definition: ChebyshevBoundedField.cc:277
lsst::geom::Box2I::Box2I
Box2I() noexcept
Construct an empty box.
Definition: Box.h:66
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::geom::Box2I::getBeginX
int getBeginX() const noexcept
Definition: Box.h:172
lsst::geom::Box2I::contains
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
Definition: Box.cc:114
lsst::geom::any
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
Definition: CoordinateExpr.h:89
lsst::geom::Box2I::clippedTo
Box2I clippedTo(Box2I const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
Definition: Box.cc:243
lsst::geom::IntervalI::fromMinSize
static IntervalI fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
Definition: Interval.cc:57
lsst::geom::Box2I::dilatedBy
Box2I dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object).
Definition: Box.cc:213
dimensions
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
lsst::geom::Box2I::SHRINK
@ SHRINK
Definition: Box.h:63
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::geom::Box2I::getCenter
Point2D const getCenter() const noexcept
1-d interval accessors
Definition: Box.cc:93
lsst::geom::Box2I::getEndX
int getEndX() const noexcept
Definition: Box.h:176
lsst::utils::hashCombine
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
lsst::geom::Box2I::getX
Interval getX() const
1-d interval accessors
Definition: Box.h:205
lsst::geom::Box2I::overlaps
bool overlaps(Box2I const &other) const noexcept
Return true if any points in other are also in this.
Definition: Box.cc:122
lsst::geom::Box2I::getMaxY
int getMaxY() const noexcept
Definition: Box.h:162
lsst::geom::Box2I::getMaxX
int getMaxX() const noexcept
Definition: Box.h:161
lsst::geom::Extent2I
Extent< int, 2 > Extent2I
Definition: Extent.h:397
lsst::geom::Point< double, 2 >
lsst::geom::IntervalI::contains
bool contains(Element point) const noexcept
Return true if the interval contains the point.
Definition: Interval.cc:116
lsst::geom::Point2I
Point< int, 2 > Point2I
Definition: Point.h:321
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst::geom::Box2I::getMinX
int getMinX() const noexcept
Definition: Box.h:157
lsst::geom::Box2I::expandedTo
Box2I expandedTo(Point const &other) const
Expand the box to ensure that contains(other) is true (returning a new object).
Definition: Box.cc:233
lsst::geom::Extent::swap
void swap(Extent &other) noexcept
Definition: Extent.h:245
lsst::geom::Extent< double, 2 >
lsst::sphgeom::invert
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
lsst::geom::Box2I::Extent
Extent2I Extent
Definition: Box.h:58
lsst::geom::Box2I::getMinY
int getMinY() const noexcept
Definition: Box.h:158
lsst::geom::Box2I::isDisjointFrom
bool isDisjointFrom(Box2I const &other) const noexcept
Return true if there are no points in both this and other.
Definition: Box.cc:126