LSST Applications  21.0.0+3c14b91618,21.0.0+9f51b1e3f7,21.0.0-1-ga51b5d4+6691386486,21.0.0-10-g2408eff+1a328412bf,21.0.0-10-g560fb7b+52fd22d7b4,21.0.0-10-g8d1d15d+2f9043cae0,21.0.0-10-gcf60f90+d15de71c48,21.0.0-11-g25eff31+d43066e4ef,21.0.0-15-g490e301a+a676f0d5cf,21.0.0-2-g103fe59+4758c8ef83,21.0.0-2-g1367e85+a9f57e981a,21.0.0-2-g45278ab+9f51b1e3f7,21.0.0-2-g5242d73+a9f57e981a,21.0.0-2-g7f82c8f+1bcc828e4f,21.0.0-2-g8f08a60+e6fd6d9ff9,21.0.0-2-ga326454+1bcc828e4f,21.0.0-2-gde069b7+66c51b65da,21.0.0-2-gecfae73+251b9830c3,21.0.0-2-gfc62afb+a9f57e981a,21.0.0-20-g09baf175d+e1e7d1c708,21.0.0-3-g357aad2+854c3902c3,21.0.0-3-g4be5c26+a9f57e981a,21.0.0-3-g65f322c+feaa1990e9,21.0.0-3-g7d9da8d+3c14b91618,21.0.0-3-ge02ed75+bda8df9b93,21.0.0-4-g591bb35+bda8df9b93,21.0.0-4-g65b4814+52fd22d7b4,21.0.0-4-g88306b8+656365ce3f,21.0.0-4-gccdca77+86bf7a300d,21.0.0-4-ge8a399c+b99e86088e,21.0.0-5-gd00fb1e+6a0dc09319,21.0.0-51-gd3b42663+bf9f0d1c8b,21.0.0-6-g2d4f3f3+9f51b1e3f7,21.0.0-7-g04766d7+ee2ae02087,21.0.0-7-g98eecf7+3609eddee2,21.0.0-7-gde99fe0+bda8df9b93,21.0.0-8-gd70ce6f+79e45e76e4,master-gac4afde19b+bda8df9b93,w.2021.10
LSST Data Management Base Package
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. More...
 
 IntervalD (IntervalI const &other) noexcept
 Construct a floating-point interval from an integer interval. More...
 
 IntervalD (IntervalD const &) noexcept=default
 Standard copy constructor. More...
 
 IntervalD (IntervalD &&) noexcept=default
 Standard move constructor. More...
 
 ~IntervalD () noexcept=default
 
void swap (IntervalD &other) noexcept
 
IntervalDoperator= (IntervalD const &) noexcept=default
 Standard copy assignment operator. More...
 
IntervalDoperator= (IntervalD &&) noexcept=default
 Standard move assignment operator. More...
 

Static Public Member Functions

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

Min/Max Accessors

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

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

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 }
ItemVariant const * other
Definition: Schema.cc:56
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:430

◆ 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 utils::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 }
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

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