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");
72 return IntervalI(static_cast<Element>(min), size);
79 double min = center - 0.5 * size;
82 checkForOverflow(min,
"minimum");
83 checkForOverflow(min + size - 1,
"maximum");
84 return IntervalI(static_cast<BigElement>(min), size);
94 "Cannot convert non-finite IntervalD to IntervalI");
97 switch (edgeHandling) {
109 *
this = _fromMinMaxChecked(min, max);
119 return point >= this->
getMin() && point <= this->
getMax();
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())));
181 return _fromMinMaxChecked(
194 return other._min == this->_min &&
other._size == this->_size;
208 template <
typename T>
213 checkForOverflow(min,
"minimum");
214 checkForOverflow(max,
"maximum");
215 T size = 1 + max -
min;
216 checkForOverflow(size,
"size");
217 return IntervalI(static_cast<Element>(min), static_cast<Element>(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.");
250 Element min = center - 0.5 * size;
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();
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()) {
363 "Cannot set interval minimum to +infinity.");
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();
static IntervalI fromMaxSize(Element max, Element size)
Construct an interval from its upper bound and size.
Element getBegin() const noexcept
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.
Element getMax() const noexcept
bool isEmpty() const noexcept
Return true if the interval contains no points.
static IntervalD fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
IntervalD reflectedAbout(Element point) const
Reflect an interval about a point (returning a new object).
IntervalD dilatedBy(Element buffer) const
Increase the size of the interval by the given amount in both directions (returning a new object)...
IntervalI clippedTo(IntervalI const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new)
bool overlaps(IntervalI const &other) const noexcept
Return true if there are any points in both this and other.
static IntervalD fromMaxSize(Element max, Element size)
Construct an interval from its upper bound and size.
bool contains(Element point) const noexcept
Return true if the interval contains the point.
IntervalI expandedTo(Element other) const
Expand an interval to ensure that contains(other) is true (returning a new object).
ItemVariant const * other
Element getMin() const noexcept
IntervalD shiftedBy(Element offset) const
Shift the position of the interval by the given offset (returning a new object).
Element getSize() const noexcept
Return the size of the interval.
IntervalI dilatedBy(Element buffer) const
Increase the size of the interval by the given amount in both directions (returning a new object)...
Element getMax() const noexcept
bool isDisjointFrom(IntervalI const &other) const noexcept
Return true if there are no points in both this and other.
IntervalI reflectedAbout(Element point) const
Reflect an interval about a point (returning a new object).
Include all pixels that overlap the floating-point interval at all.
Element getEnd() const noexcept
A floating-point coordinate rectangle geometry.
IntervalI shiftedBy(Element offset) const
Shift the position of the interval by the given offset (returning a new object).) ...
static IntervalI fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
static IntervalI fromCenterSize(double center, Element size)
Create an interval centered as closely as possible on a particular point.
static IntervalD fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
A base class for image defects.
bool operator==(IntervalI const &other) const noexcept
Compare two intervals for equality.
bool isEmpty() const noexcept
Return true if the interval contains no points.
bool overlaps(IntervalD const &other) const noexcept
Return true if any points in other are also in this.
bool isDisjointFrom(IntervalD const &other) const noexcept
Return true if there are no points in both this and other.
IntervalD expandedTo(Element other) const
Expand an interval to ensure that contains(other) is true.
Element getSize() const noexcept
Return slice to extract the interval's region from an ndarray::Array.
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Element getMin() const noexcept
Reports errors in the logical structure of the program.
static IntervalI fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
Include only pixels that are wholly contained by the floating-point interval.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
bool operator!=(IntervalI const &other) const noexcept
Compare two intervals for equality.
ndarray::View< boost::fusion::vector1< ndarray::index::Range > > getSlice() const
Return slice to extract the interval's region from an ndarray::Array.
A 1-d integer coordinate range.
bool operator==(IntervalD const &other) const noexcept
Compare two intervals for equality.
std::string toString() const
IntervalD clippedTo(IntervalD const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
static IntervalD fromCenterSize(double center, Element size)
Construct an interval centered on a particular point.
Element getCenter() const noexcept
Return the center coordinate of the interval.
std::size_t hash_value() const noexcept
Return a hash of this object.
Reports invalid arguments.
bool contains(Element point) const
Return true if the interval contains the point.
std::string toString() const
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
std::size_t hash_value() const noexcept
Return a hash of this object.
bool operator!=(IntervalD const &other) const noexcept
Compare two intervals for equality.
IntervalI() noexcept
Construct an empty interval.
IntervalD() noexcept
Construct an empty interval.