LSSTApplications
19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
24 #include <type_traits>
26 #include "boost/format.hpp"
36 using BigElement =
long long;
42 void checkForOverflow(T
x,
char const* where) {
47 (
boost::format(
"Integer overflow (%d) in interval %s.") %
x % where).str());
54 return _fromMinMaxChecked(
static_cast<BigElement
>(
min),
static_cast<BigElement
>(
max));
61 BigElement
max =
static_cast<BigElement
>(
min) +
static_cast<BigElement
>(size) - 1;
62 checkForOverflow(
max,
"maximum");
70 BigElement
min =
static_cast<BigElement
>(
max) -
static_cast<BigElement
>(size) + 1;
71 checkForOverflow(
min,
"minimum");
79 double min = center - 0.5 * size;
82 checkForOverflow(
min,
"minimum");
83 checkForOverflow(
min + size - 1,
"maximum");
88 if (
other.isEmpty()) {
94 "Cannot convert non-finite IntervalD to IntervalI");
97 switch (edgeHandling) {
109 *
this = _fromMinMaxChecked(
min,
max);
119 return point >= this->getMin() && point <= this->getMax();
125 return other.isEmpty() || (
other.getMin() >= this->getMin() &&
other.getMax() <= this->getMax());
131 if (isEmpty() ||
other.isEmpty()) {
134 return getMin() >
other.getMax() || getMax() <
other.getMin();
141 BigElement
min =
static_cast<BigElement
>(
getMin()) - buffer;
142 BigElement
max =
static_cast<BigElement
>(
getMax()) + buffer;
143 return _fromMinMaxChecked(
min,
max);
150 BigElement
min =
static_cast<BigElement
>(
getMin()) + offset;
151 BigElement
max =
static_cast<BigElement
>(
getMax()) + offset;
152 checkForOverflow(
min,
"minimum");
153 checkForOverflow(
max,
"maximum");
161 BigElement
max = 2 *
static_cast<BigElement
>(point) -
getMin();
162 BigElement
min = 2 *
static_cast<BigElement
>(point) -
getMax();
163 return _fromMinMaxChecked(
min,
max);
170 return _fromMinMaxChecked(
std::min(
static_cast<BigElement
>(point),
static_cast<BigElement
>(
getMin())),
171 std::max(
static_cast<BigElement
>(point),
static_cast<BigElement
>(
getMax())));
175 if (
other.isEmpty()) {
181 return _fromMinMaxChecked(
187 if (isEmpty() ||
other.isEmpty()) {
208 template <
typename T>
213 checkForOverflow(
min,
"minimum");
214 checkForOverflow(
max,
"maximum");
216 checkForOverflow(size,
"size");
231 "Ambiguously infinite interval parameters; use fromMinMax to "
232 "construct infinite intervals instead.");
240 "Ambiguously infinite interval parameters; use fromMinMax to "
241 "construct infinite intervals instead.");
255 : _min(
other.getMin() - 0.5), _max(
other.getMax() + 0.5) {
266 "Cannot test whether an interval contains NaN.");
268 return point >= this->
getMin() && point <= this->
getMax();
272 return other.isEmpty() || (
other.getMin() >= this->getMin() &&
other.getMax() <= this->getMax());
278 if (isEmpty() ||
other.isEmpty()) {
281 return getMin() >
other.getMax() || getMax() <
other.getMin();
287 "Cannot dilate or erode with a non-finite buffer.");
289 return fromMinMax(_min - buffer, _max + buffer);
297 return fromMinMax(_min + offset, _max + offset);
308 return fromMinMax(2 * point - _max, 2 * point - _min);
326 if (
other.isEmpty()) {
328 }
else if (this->isEmpty()) {
336 if (this->isEmpty() ||
other.isEmpty()) {
344 return (
other.isEmpty() && this->isEmpty()) || (
other._min == this->_min &&
other._max == this->_max);
363 "Cannot set interval minimum to +infinity.");
365 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
366 "Cannot set interval maximum to -infinity.");
371 if (interval.
isEmpty())
return os <<
"IntervalI()";
372 return os <<
"IntervalI" << interval.
toString();
376 if (interval.
isEmpty())
return os <<
"IntervalD()";
377 return os <<
"IntervalD" << interval.
toString();
Element getMin() const noexcept
Return the size of the interval.
A 1-d integer coordinate range.
bool isEmpty() const noexcept
Return true if the interval contains no points.
bool isDisjointFrom(IntervalD const &other) const noexcept
Return true if there are no points in both this and other.
std::string toString() const
Return the size of the interval.
IntervalD() noexcept
Construct an empty interval.
std::size_t hash_value() const noexcept
Return a hash of this object.
static IntervalI fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
Element getBegin() const noexcept
Element getSize() const noexcept
Return the size of the interval.
ndarray::View< boost::fusion::vector1< ndarray::index::Range > > getSlice() const
Return slice to extract the interval's region from an ndarray::Array.
Element getMax() const noexcept
Return the size of the interval.
IntervalI expandedTo(Element other) const
Expand an interval to ensure that contains(other) is true (returning a new object).
bool operator==(IntervalD const &other) const noexcept
Compare two intervals for equality.
IntervalD clippedTo(IntervalD const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
bool isDisjointFrom(IntervalI const &other) const noexcept
Return true if there are no points in both this and other.
IntervalI shiftedBy(Element offset) const
Shift the position of the interval by the given offset (returning a new object).)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
EdgeHandlingEnum
Enum used to indicate how to handle conversions from floating-point to integer intervals.
static IntervalI fromCenterSize(double center, Element size)
Create an interval centered as closely as possible on a particular point.
std::size_t hash_value() const noexcept
Return a hash of this object.
table::Key< table::Array< int > > _size
IntervalD expandedTo(Element other) const
Expand an interval to ensure that contains(other) is true.
bool isEmpty() const noexcept
Return true if the interval contains no points.
IntervalI() noexcept
Construct an empty interval.
Element getMin() const noexcept
@ EXPAND
Include all pixels that overlap the floating-point interval at all.
ItemVariant const * other
IntervalD reflectedAbout(Element point) const
Reflect an interval about a point (returning a new object).
Reports errors in the logical structure of the program.
IntervalD dilatedBy(Element buffer) const
Increase the size of the interval by the given amount in both directions (returning a new object).
static IntervalI fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
IntervalI clippedTo(IntervalI const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new)
bool operator==(IntervalI const &other) const noexcept
Compare two intervals for equality.
A base class for image defects.
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
bool overlaps(IntervalD const &other) const noexcept
Return true if any points in other are also in this.
A floating-point coordinate rectangle geometry.
static IntervalD fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
Element getCenter() const noexcept
Return the center coordinate of the interval.
bool contains(Element point) const
Return true if the interval contains the point.
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Element getSize() const noexcept
Return slice to extract the interval's region from an ndarray::Array.
static IntervalI fromMaxSize(Element max, Element size)
Construct an interval from its upper bound and size.
Reports invalid arguments.
@ SHRINK
Include only pixels that are wholly contained by the floating-point interval.
bool operator!=(IntervalD const &other) const noexcept
Compare two intervals for equality.
bool contains(Element point) const noexcept
Return true if the interval contains the point.
bool operator!=(IntervalI const &other) const noexcept
Compare two intervals for equality.
IntervalD shiftedBy(Element offset) const
Shift the position of the interval by the given offset (returning a new object).
IntervalI dilatedBy(Element buffer) const
Increase the size of the interval by the given amount in both directions (returning a new object).
IntervalI reflectedAbout(Element point) const
Reflect an interval about a point (returning a new object).
static IntervalD fromCenterSize(double center, Element size)
Construct an interval centered on a particular point.
Element getEnd() const noexcept
bool overlaps(IntervalI const &other) const noexcept
Return true if there are any points in both this and other.
static IntervalD fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
std::string toString() const
Return slice to extract the interval's region from an ndarray::Array.
static IntervalD fromMaxSize(Element max, Element size)
Construct an interval from its upper bound and size.
Element getMax() const noexcept