LSSTApplications
20.0.0
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.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
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).)
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