LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lsst::geom::IntervalD Class Referencefinal

A floating-point coordinate rectangle geometry. More...

#include <Interval.h>

Public Types

using Element = double
 

Public Member Functions

 IntervalD () noexcept
 Construct an empty interval.
 
 IntervalD (IntervalI const &other) noexcept
 Construct a floating-point interval from an integer interval.
 
 IntervalD (IntervalD const &) noexcept=default
 Standard copy constructor.
 
 IntervalD (IntervalD &&) noexcept=default
 Standard move constructor.
 
 ~IntervalD () noexcept=default
 
void swap (IntervalD &other) noexcept
 
IntervalDoperator= (IntervalD const &) noexcept=default
 Standard copy assignment operator.
 
IntervalDoperator= (IntervalD &&) noexcept=default
 Standard move assignment operator.
 

Static Public Member Functions

template<typename Iter >
static IntervalD fromSpannedPoints (Iter first, Iter last)
 Construct an interval that contains all of the given points.
 
static IntervalD fromSpannedPoints (std::vector< Element > const &elements)
 Construct an interval that contains all of the given points.
 
static IntervalD fromSpannedPoints (ndarray::Array< Element const, 1 > const &elements)
 
static IntervalD fromMinMax (Element min, Element max)
 Construct an interval from its lower and upper bounds.
 
static IntervalD fromMinSize (Element min, Element size)
 Construct an interval from its lower bound and size.
 
static IntervalD fromMaxSize (Element max, Element size)
 Construct an interval from its upper bound and size.
 
static IntervalD fromCenterSize (double center, Element size)
 Construct an interval centered on a particular point.
 

Min/Max Accessors

Return the minimum (inclusive) and maximum (exclusive) coordinates of the interval.

Element getMin () const noexcept
 Return the size of the interval.
 
Element getMax () const noexcept
 Return the size of the interval.
 
Element getSize () const noexcept
 Return the size of the interval.
 
Element getCenter () const noexcept
 Return the center coordinate of the interval.
 
bool isEmpty () const noexcept
 Return true if the interval contains no points.
 
bool isFinite () const noexcept
 Return true if the interval's size is finite.
 
bool contains (Element point) const
 Return true if the interval contains the point.
 
bool contains (IntervalD const &other) const noexcept
 Return true if all points contained by other are also contained by this.
 
bool overlaps (IntervalD const &other) const noexcept
 Return true if any points in other are also in this.
 
bool intersects (IntervalD const &other) const noexcept
 Return the size of the interval.
 
bool isDisjointFrom (IntervalD const &other) const noexcept
 Return true if there are no points in both this and other.
 
IntervalD dilatedBy (Element buffer) const
 Increase the size of the interval by the given amount in both directions (returning a new object).
 
IntervalD erodedBy (Element buffer) const
 Decrease the size of the interval by the given amount in both directions (returning a new object).
 
IntervalD shiftedBy (Element offset) const
 Shift the position of the interval by the given offset (returning a new object).
 
IntervalD reflectedAbout (Element point) const
 Reflect an interval about a point (returning a new object).
 
IntervalD expandedTo (Element other) const
 Expand an interval to ensure that contains(other) is true.
 
IntervalD expandedTo (IntervalD const &other) const noexcept
 Expand an interval to ensure that contains(other) is true.
 
IntervalD clippedTo (IntervalD const &other) const noexcept
 Shrink an interval to ensure that it is contained by other (returning a new object).
 
bool operator== (IntervalD const &other) const noexcept
 Compare two intervals for equality.
 
bool operator!= (IntervalD const &other) const noexcept
 Compare two intervals for equality.
 
std::size_t hash_value () const noexcept
 Return a hash of this object.
 
std::string toString () const
 Return the size of the interval.
 

Detailed Description

A floating-point coordinate rectangle geometry.

IntervalD is closed (its bounds are considered included in the interval). An interval never has negative size; the empty interval is defined to zero-size size and its minimum and maximum values are set to NaN. Non-empty intervals representing infinitesimal points may also have zero size, but are not considered empty.

The existence of zero-size, non-empty intervals is an important, intentional difference between IntervalI and IntervalD, related to the fact that IntervalI models a discrete set while IntervalD (imperfectly, due to floating-point limitations) models a continuous set.

Definition at line 413 of file Interval.h.

Member Typedef Documentation

◆ Element

Definition at line 415 of file Interval.h.

Constructor & Destructor Documentation

◆ IntervalD() [1/4]

lsst::geom::IntervalD::IntervalD ( )
noexcept

Construct an empty interval.

Definition at line 222 of file Interval.cc.

◆ IntervalD() [2/4]

lsst::geom::IntervalD::IntervalD ( IntervalI const & other)
explicitnoexcept

Construct a floating-point interval from an integer interval.

Integer to floating-point interval 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. While the output floating-point interval thus has the same size as the input integer interval, its minimum/maximum coordinates are 0.5 smaller/greater.

Definition at line 254 of file Interval.cc.

255 : _min(other.getMin() - 0.5), _max(other.getMax() + 0.5) {
256 if (other.isEmpty()) *this = IntervalD();
257}
IntervalD() noexcept
Construct an empty interval.
Definition Interval.cc:222

◆ IntervalD() [3/4]

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

Standard copy constructor.

◆ IntervalD() [4/4]

lsst::geom::IntervalD::IntervalD ( IntervalD && )
defaultnoexcept

Standard move constructor.

◆ ~IntervalD()

lsst::geom::IntervalD::~IntervalD ( )
defaultnoexcept

Member Function Documentation

◆ clippedTo()

IntervalD lsst::geom::IntervalD::clippedTo ( IntervalD 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 the new interval will be empty.

Definition at line 335 of file Interval.cc.

335 {
336 if (this->isEmpty() || other.isEmpty()) {
337 return IntervalD();
338 } else {
339 return fromMinMax(std::max(this->getMin(), other.getMin()), std::min(this->getMax(), other.getMax()));
340 }
341}
Element getMin() const noexcept
Return the size of the interval.
Definition Interval.h:559
static IntervalD fromMinMax(Element min, Element max)
Construct an interval from its lower and upper bounds.
Definition Interval.cc:226
bool isEmpty() const noexcept
Return true if the interval contains no points.
Definition Interval.h:579
T max(T... args)
T min(T... args)

◆ contains() [1/2]

bool lsst::geom::IntervalD::contains ( Element point) const

Return true if the interval contains the point.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if point is NaN.

Definition at line 263 of file Interval.cc.

263 {
264 if (std::isnan(point)) {
265 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
266 "Cannot test whether an interval contains NaN.");
267 }
268 return point >= this->getMin() && point <= this->getMax();
269}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Element getMax() const noexcept
Return the size of the interval.
Definition Interval.h:560
T isnan(T... args)

◆ contains() [2/2]

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

Return true if all points contained by other are also contained by this.

An empty interval is contained by every other interval, including other empty intervals.

Definition at line 271 of file Interval.cc.

271 {
272 return other.isEmpty() || (other.getMin() >= this->getMin() && other.getMax() <= this->getMax());
273}

◆ dilatedBy()

IntervalD lsst::geom::IntervalD::dilatedBy ( Element buffer) const

Increase the size of the interval by the given amount in both directions (returning a new object).

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

If the final size of the interval is less than zero, the new interval will be empty.

Empty intervals remain empty after dilation. Infinite bounds are unaffected by dilation.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if buffer is not finite.

Definition at line 284 of file Interval.cc.

284 {
285 if (!std::isfinite(buffer)) {
286 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
287 "Cannot dilate or erode with a non-finite buffer.");
288 }
289 return fromMinMax(_min - buffer, _max + buffer);
290}
T isfinite(T... args)

◆ erodedBy()

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

Decrease the size of the interval by the given amount in both directions (returning a new object).

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

If the final size of the interval is less than zero, the new interval will be empty.

Empty intervals remain empty after erosion. Infinite bounds are unaffected by erosion.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if buffer is not finite.

Definition at line 648 of file Interval.h.

648{ return dilatedBy(-buffer); }
IntervalD dilatedBy(Element buffer) const
Increase the size of the interval by the given amount in both directions (returning a new object).
Definition Interval.cc:284

◆ expandedTo() [1/2]

IntervalD lsst::geom::IntervalD::expandedTo ( Element other) const

Expand an interval to ensure that contains(other) is true.

Expanding an empty interval with a single point yields an interval with size == 0 at that point.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if other is not finite.

Definition at line 314 of file Interval.cc.

314 {
315 if (!std::isfinite(point)) {
316 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Cannot expand to a non-finite point.");
317 }
318 if (isEmpty()) {
319 return fromMinMax(point, point);
320 } else {
321 return fromMinMax(std::min(point, _min), std::max(point, _max));
322 }
323}

◆ expandedTo() [2/2]

IntervalD lsst::geom::IntervalD::expandedTo ( IntervalD const & other) const
noexcept

Expand an interval to ensure that contains(other) is true.

Expanding an empty interval with a second interval is equivalent to assignment.

Expanding by an empty interval yields the original interval.

Definition at line 325 of file Interval.cc.

325 {
326 if (other.isEmpty()) {
327 return *this;
328 } else if (this->isEmpty()) {
329 return other;
330 } else {
331 return fromMinMax(std::min(this->getMin(), other.getMin()), std::max(this->getMax(), other.getMax()));
332 }
333}

◆ fromCenterSize()

IntervalD lsst::geom::IntervalD::fromCenterSize ( double center,
Element size )
static

Construct an interval centered on a particular point.

Parameters
centerThe desired center of the interval. May not be infinite.
sizeNumber of pixels in interval. May not be infinite.

If size < 0 or any parameter is NaN, an empty interval is returned.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if any parameter is infinite. This includes the case where one parameter is NaN and the other is infinite.

Definition at line 246 of file Interval.cc.

246 {
247 if (std::isinf(center) || std::isinf(size)) {
248 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Infinite values not supported.");
249 }
250 Element min = center - 0.5 * size;
252}
int min
static IntervalD fromMinSize(Element min, Element size)
Construct an interval from its lower bound and size.
Definition Interval.cc:228
T isinf(T... args)

◆ fromMaxSize()

IntervalD lsst::geom::IntervalD::fromMaxSize ( Element max,
Element size )
static

Construct an interval from its upper bound and size.

Parameters
[in]maxMaximum coordinate (inclusive).
[in]sizeSize of interval.

If size < 0 or any parameter is NaN, an empty interval is returned.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if min is infinite or if size is +infinity (-infinity yields an empty interval).

Definition at line 237 of file Interval.cc.

237 {
238 if (std::isinf(max) || (std::isinf(size) && size > 0)) {
239 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
240 "Ambiguously infinite interval parameters; use fromMinMax to "
241 "construct infinite intervals instead.");
242 }
243 return IntervalD(max - size, max);
244}
int max

◆ fromMinMax()

IntervalD lsst::geom::IntervalD::fromMinMax ( Element min,
Element max )
static

Construct an interval from its lower and upper bounds.

Parameters
[in]minMinimum coordinate (inclusive).
[in]maxMaximum coordinate (inclusive).

Bounds may be non-finite, with some restrictions.

  • If min is -inf and/or max is +inf, the interval has infinite size and is considered valid.
  • If max < min (regardless of whether one or both is infinite) or either is NaN, the interval is empty.
  • min == max == +inf or min == max == -inf is an error.
Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if min == max == inf or min == max == -inf.

Definition at line 226 of file Interval.cc.

226{ return IntervalD(min, max); }

◆ fromMinSize()

IntervalD lsst::geom::IntervalD::fromMinSize ( Element min,
Element size )
static

Construct an interval from its lower bound and size.

Parameters
[in]minMinimum coordinate (inclusive).
[in]sizeSize of interval.

If size < 0 or any parameter is NaN, an empty interval is returned.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if min is infinite or if size is +infinity (-infinity yields an empty interval).

Definition at line 228 of file Interval.cc.

228 {
229 if (std::isinf(min) || (std::isinf(size) && size > 0)) {
230 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
231 "Ambiguously infinite interval parameters; use fromMinMax to "
232 "construct infinite intervals instead.");
233 }
234 return IntervalD(min, min + size);
235}

◆ fromSpannedPoints() [1/3]

template<typename Iter >
static IntervalD lsst::geom::IntervalD::fromSpannedPoints ( Iter first,
Iter last )
inlinestatic

Construct an interval that contains all of the given points.

Parameters
[in]firstIterator to the beginning of a sequence of floating-point values.
[in]lastIterator to one-past-the-end of a sequence of floating-point values.

An empty interval is returned if first == last.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if any input point is non-finite.

Definition at line 434 of file Interval.h.

434 {
436 for (auto i = first; i != last; ++i) {
437 result = result.expandedTo(*i);
438 }
439 return result;
440 }
py::object result
Definition _schema.cc:429

◆ fromSpannedPoints() [2/3]

static IntervalD lsst::geom::IntervalD::fromSpannedPoints ( ndarray::Array< Element const, 1 > const & elements)
inlinestatic

Definition at line 457 of file Interval.h.

457 {
458 return fromSpannedPoints(elements.begin(), elements.end());
459 }
static IntervalD fromSpannedPoints(Iter first, Iter last)
Construct an interval that contains all of the given points.
Definition Interval.h:434

◆ fromSpannedPoints() [3/3]

static IntervalD lsst::geom::IntervalD::fromSpannedPoints ( std::vector< Element > const & elements)
inlinestatic

Construct an interval that contains all of the given points.

Parameters
[in]elementsPoints (floating-point values) to include in the interval.

An empty interval is returned if the given container has no elements.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if any input point is non-finite.

Definition at line 454 of file Interval.h.

454 {
455 return fromSpannedPoints(elements.begin(), elements.end());
456 }
T begin(T... args)
T end(T... args)

◆ getCenter()

IntervalD::Element lsst::geom::IntervalD::getCenter ( ) const
noexcept

Return the center coordinate of the interval.

Returns NaN for empty intervals and infinite intervals.

Definition at line 261 of file Interval.cc.

261{ return 0.5 * (_min + _max); }

◆ getMax()

Element lsst::geom::IntervalD::getMax ( ) const
inlinenoexcept

Return the size of the interval.

Empty intervals have zero size, but not all zero-size intervals are empty. Intervals with an infinite bound have infinite size.

Definition at line 560 of file Interval.h.

560{ return _max; }

◆ getMin()

Element lsst::geom::IntervalD::getMin ( ) const
inlinenoexcept

Return the size of the interval.

Empty intervals have zero size, but not all zero-size intervals are empty. Intervals with an infinite bound have infinite size.

Definition at line 559 of file Interval.h.

559{ return _min; }

◆ getSize()

IntervalD::Element lsst::geom::IntervalD::getSize ( ) const
noexcept

Return the size of the interval.

Empty intervals have zero size, but not all zero-size intervals are empty. Intervals with an infinite bound have infinite size.

Definition at line 259 of file Interval.cc.

259{ return isEmpty() ? 0.0 : (_max - _min); }

◆ hash_value()

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

Return a hash of this object.

Definition at line 349 of file Interval.cc.

349 {
350 // Completely arbitrary seed
351 return cpputils::hashCombine(17, _min, _max);
352}
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition hashCombine.h:35

◆ intersects()

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

Return the size of the interval.

Empty intervals have zero size, but not all zero-size intervals are empty. Intervals with an infinite bound have infinite size.

Definition at line 608 of file Interval.h.

608{ return overlaps(other); }
bool overlaps(IntervalD const &other) const noexcept
Return true if any points in other are also in this.
Definition Interval.cc:275

◆ isDisjointFrom()

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

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

Definition at line 277 of file Interval.cc.

277 {
278 if (isEmpty() || other.isEmpty()) {
279 return true;
280 }
281 return getMin() > other.getMax() || getMax() < other.getMin();
282}

◆ isEmpty()

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

Return true if the interval contains no points.

Definition at line 579 of file Interval.h.

579{ return std::isnan(_min); }

◆ isFinite()

bool lsst::geom::IntervalD::isFinite ( ) const
inlinenoexcept

Return true if the interval's size is finite.

Definition at line 582 of file Interval.h.

582{ return std::isfinite(getSize()); }
Element getSize() const noexcept
Return the size of the interval.
Definition Interval.cc:259

◆ operator!=()

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

Compare two intervals for equality.

All empty intervals are equal.

Definition at line 347 of file Interval.cc.

347{ return !(other == *this); }

◆ operator=() [1/2]

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

Standard move assignment operator.

◆ operator=() [2/2]

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

Standard copy assignment operator.

◆ operator==()

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

Compare two intervals for equality.

All empty intervals are equal.

Definition at line 343 of file Interval.cc.

343 {
344 return (other.isEmpty() && this->isEmpty()) || (other._min == this->_min && other._max == this->_max);
345}

◆ overlaps()

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

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

Any overlap operation involving an empty interval returns false.

Definition at line 275 of file Interval.cc.

275{ return !isDisjointFrom(other); }
bool isDisjointFrom(IntervalD const &other) const noexcept
Return true if there are no points in both this and other.
Definition Interval.cc:277

◆ reflectedAbout()

IntervalD lsst::geom::IntervalD::reflectedAbout ( Element point) const

Reflect an interval about a point (returning a new object).

Empty intervals remain empty when reflected. If an interval with an infinite bound is reflected, the opposite bound will become infinite with the opposite sign.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if point is not finite.

Definition at line 303 of file Interval.cc.

303 {
304 if (!std::isfinite(point)) {
305 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Cannot reflect about a non-finite point.");
306 }
307 if (!isEmpty()) {
308 return fromMinMax(2 * point - _max, 2 * point - _min);
309 } else {
310 return IntervalD();
311 }
312}

◆ shiftedBy()

IntervalD lsst::geom::IntervalD::shiftedBy ( Element offset) const

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

Empty intervals remain empty when shifted. Infinite bounds are unaffected by shifting.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorThrown if offset is not finite.

Definition at line 292 of file Interval.cc.

292 {
293 if (!std::isfinite(offset)) {
294 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Cannot shift with a non-finite offset.");
295 }
296 if (!isEmpty()) {
297 return fromMinMax(_min + offset, _max + offset);
298 } else {
299 return IntervalD();
300 }
301}

◆ swap()

void lsst::geom::IntervalD::swap ( IntervalD & other)
inlinenoexcept

Definition at line 541 of file Interval.h.

541 {
542 std::swap(_min, other._min);
543 std::swap(_max, other._max);
544 }
T swap(T... args)

◆ toString()

std::string lsst::geom::IntervalD::toString ( ) const

Return the size of the interval.

Empty intervals have zero size, but not all zero-size intervals are empty. Intervals with an infinite bound have infinite size.

Definition at line 354 of file Interval.cc.

354 {
355 return (boost::format("(min=%s, max=%s)") % getMin() % getMax()).str();
356}

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