LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | List of all members
lsst::sphgeom::Interval< Derived, Scalar > Class Template Reference

Interval represents a closed interval of the real numbers by its upper and lower bounds. More...

#include <Interval.h>

Public Member Functions

 Interval ()
 This constructor creates an empty interval.
 
 Interval (Scalar x)
 This constructor creates a closed interval containing only x.
 
 Interval (Scalar x, Scalar y)
 This constructor creates an interval from the given endpoints.
 
bool operator== (Interval const &i) const
 Two closed intervals are equal if their endpoints are the same, or both are empty.
 
bool operator!= (Interval const &i) const
 
bool operator== (Scalar x) const
 A closed interval is equal to a point x if both endpoints equal x.
 
bool operator!= (Scalar x) const
 
Scalar getA () const
 getA returns the lower endpoint of this interval.
 
Scalar getB () const
 getB returns the upper endpoint of this interval.
 
bool isEmpty () const
 isEmpty returns true if this interval does not contain any points.
 
Scalar getCenter () const
 getCenter returns the center of this interval.
 
Scalar getSize () const
 getSize returns the size (length, width) of this interval.
 
IntervaldilateBy (Scalar x)
 For positive x, dilateBy morphologically dilates this interval by [-x,x], which is equivalent to the taking the Minkowski sum with [-x,x].
 
IntervalerodeBy (Scalar x)
 
Derived dilatedBy (Scalar x) const
 
Derived erodedBy (Scalar x) const
 
bool contains (Scalar x) const
 
bool contains (Interval const &x) const
 
bool isDisjointFrom (Scalar x) const
 
bool isDisjointFrom (Interval const &x) const
 
bool intersects (Scalar x) const
 
bool intersects (Interval const &x) const
 
bool isWithin (Scalar x) const
 
bool isWithin (Interval const &x) const
 
Relationship relate (Scalar x) const
 
Relationship relate (Interval const &x) const
 
IntervalclipTo (Scalar x)
 
IntervalclipTo (Interval const &x)
 
Derived clippedTo (Scalar x) const
 
Derived clippedTo (Interval const &x) const
 
IntervalexpandTo (Scalar x)
 
IntervalexpandTo (Interval const &x)
 
Derived expandedTo (Scalar x) const
 
Derived expandedTo (Interval const &x) const
 

Detailed Description

template<typename Derived, typename Scalar>
class lsst::sphgeom::Interval< Derived, Scalar >

Interval represents a closed interval of the real numbers by its upper and lower bounds.

It is parameterized by the Scalar type, which must be constructible from a double.

An interval with identical upper and lower bounds contains a single point, and is equal to that scalar bound.

An interval with an upper bound less than its lower bound is empty (contains no points), as are intervals with NaN as either bound.

Definition at line 55 of file Interval.h.

Constructor & Destructor Documentation

◆ Interval() [1/3]

template<typename Derived , typename Scalar >
lsst::sphgeom::Interval< Derived, Scalar >::Interval ( )
inline

This constructor creates an empty interval.

Definition at line 58 of file Interval.h.

58: _a(1.0), _b(0.0) {}

◆ Interval() [2/3]

template<typename Derived , typename Scalar >
lsst::sphgeom::Interval< Derived, Scalar >::Interval ( Scalar x)
inlineexplicit

This constructor creates a closed interval containing only x.

Definition at line 61 of file Interval.h.

61: _a(x), _b(x) {}

◆ Interval() [3/3]

template<typename Derived , typename Scalar >
lsst::sphgeom::Interval< Derived, Scalar >::Interval ( Scalar x,
Scalar y )
inline

This constructor creates an interval from the given endpoints.

Definition at line 64 of file Interval.h.

64: _a(x), _b(y) {}
int y
Definition SpanSet.cc:48

Member Function Documentation

◆ clippedTo() [1/2]

template<typename Derived , typename Scalar >
Derived lsst::sphgeom::Interval< Derived, Scalar >::clippedTo ( Interval< Derived, Scalar > const & x) const
inline

clippedTo returns the intersection of this interval and x.

Definition at line 192 of file Interval.h.

192 {
193 return Interval(*this).clipTo(x);
194 }
Interval()
This constructor creates an empty interval.
Definition Interval.h:58

◆ clippedTo() [2/2]

template<typename Derived , typename Scalar >
Derived lsst::sphgeom::Interval< Derived, Scalar >::clippedTo ( Scalar x) const
inline

clippedTo returns the intersection of this interval and x.

Definition at line 190 of file Interval.h.

190{ return Interval(*this).clipTo(x); }

◆ clipTo() [1/2]

template<typename Derived , typename Scalar >
Interval & lsst::sphgeom::Interval< Derived, Scalar >::clipTo ( Interval< Derived, Scalar > const & x)
inline

clipTo shrinks this interval until all its points are in x.

Definition at line 177 of file Interval.h.

177 {
178 if (x.isEmpty()) {
179 *this = x;
180 } else if (!isEmpty()) {
181 _a = std::max(_a, x._a);
182 _b = std::min(_b, x._b);
183 }
184 return *this;
185 }
bool isEmpty() const
isEmpty returns true if this interval does not contain any points.
Definition Interval.h:90
T max(T... args)
T min(T... args)

◆ clipTo() [2/2]

template<typename Derived , typename Scalar >
Interval & lsst::sphgeom::Interval< Derived, Scalar >::clipTo ( Scalar x)
inline

clipTo shrinks this interval until all its points are in x.

Definition at line 166 of file Interval.h.

166 {
167 if (x != x) {
168 _a = x;
169 _b = x;
170 } else {
171 _a = std::max(_a, x);
172 _b = std::min(_b, x);
173 }
174 return *this;
175 }

◆ contains() [1/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::contains ( Interval< Derived, Scalar > const & x) const
inline

contains returns true if the intersection of this interval and x is equal to x.

Definition at line 109 of file Interval.h.

109 {
110 if (x.isEmpty()) {
111 return true;
112 } else if (isEmpty()) {
113 return false;
114 }
115 return _a <= x._a && _b >= x._b;
116 }

◆ contains() [2/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::contains ( Scalar x) const
inline

contains returns true if the intersection of this interval and x is equal to x.

Definition at line 105 of file Interval.h.

105 {
106 return (_a <= x && x <= _b) || x != x;
107 }

◆ dilateBy()

template<typename Derived , typename Scalar >
Interval & lsst::sphgeom::Interval< Derived, Scalar >::dilateBy ( Scalar x)
inline

For positive x, dilateBy morphologically dilates this interval by [-x,x], which is equivalent to the taking the Minkowski sum with [-x,x].

For negative x, it morphologically erodes this interval by [x,-x]. If x is zero or NaN, or this interval is empty, there is no effect.

Definition at line 237 of file Interval.h.

237 {
238 if (x == x && !isEmpty()) {
239 _a = _a - x;
240 _b = _b + x;
241 }
242 return *this;
243 }

◆ dilatedBy()

template<typename Derived , typename Scalar >
Derived lsst::sphgeom::Interval< Derived, Scalar >::dilatedBy ( Scalar x) const
inline

Definition at line 246 of file Interval.h.

246{ return Interval(*this).dilateBy(x); }

◆ erodeBy()

template<typename Derived , typename Scalar >
Interval & lsst::sphgeom::Interval< Derived, Scalar >::erodeBy ( Scalar x)
inline

Definition at line 245 of file Interval.h.

245{ return dilateBy(-x); }
Interval & dilateBy(Scalar x)
For positive x, dilateBy morphologically dilates this interval by [-x,x], which is equivalent to the ...
Definition Interval.h:237

◆ erodedBy()

template<typename Derived , typename Scalar >
Derived lsst::sphgeom::Interval< Derived, Scalar >::erodedBy ( Scalar x) const
inline

Definition at line 247 of file Interval.h.

247{ return Interval(*this).erodeBy(x); }

◆ expandedTo() [1/2]

template<typename Derived , typename Scalar >
Derived lsst::sphgeom::Interval< Derived, Scalar >::expandedTo ( Interval< Derived, Scalar > const & x) const
inline

expandedTo returns the smallest interval containing the union of this interval and x.

Definition at line 227 of file Interval.h.

227 {
228 return Interval(*this).expandTo(x);
229 }

◆ expandedTo() [2/2]

template<typename Derived , typename Scalar >
Derived lsst::sphgeom::Interval< Derived, Scalar >::expandedTo ( Scalar x) const
inline

expandedTo returns the smallest interval containing the union of this interval and x.

Definition at line 225 of file Interval.h.

225{ return Interval(*this).expandTo(x); }

◆ expandTo() [1/2]

template<typename Derived , typename Scalar >
Interval & lsst::sphgeom::Interval< Derived, Scalar >::expandTo ( Interval< Derived, Scalar > const & x)
inline

expandTo minimally expands this interval to contain x.

Definition at line 211 of file Interval.h.

211 {
212 if (isEmpty()) {
213 *this = x;
214 } else if (!x.isEmpty()) {
215 _a = std::min(_a, x._a);
216 _b = std::max(_b, x._b);
217 }
218 return *this;
219 }

◆ expandTo() [2/2]

template<typename Derived , typename Scalar >
Interval & lsst::sphgeom::Interval< Derived, Scalar >::expandTo ( Scalar x)
inline

expandTo minimally expands this interval to contain x.

Definition at line 199 of file Interval.h.

199 {
200 if (isEmpty()) {
201 _a = x;
202 _b = x;
203 } else if (x < _a) {
204 _a = x;
205 } else if (x > _b) {
206 _b = x;
207 }
208 return *this;
209 }

◆ getA()

template<typename Derived , typename Scalar >
Scalar lsst::sphgeom::Interval< Derived, Scalar >::getA ( ) const
inline

getA returns the lower endpoint of this interval.

The return value for empty intervals is arbitrary.

Definition at line 83 of file Interval.h.

83{ return _a; }

◆ getB()

template<typename Derived , typename Scalar >
Scalar lsst::sphgeom::Interval< Derived, Scalar >::getB ( ) const
inline

getB returns the upper endpoint of this interval.

The return value for empty intervals is arbitrary.

Definition at line 87 of file Interval.h.

87{ return _b; }

◆ getCenter()

template<typename Derived , typename Scalar >
Scalar lsst::sphgeom::Interval< Derived, Scalar >::getCenter ( ) const
inline

getCenter returns the center of this interval.

It is arbitrary for empty intervals.

Definition at line 96 of file Interval.h.

96{ return 0.5 * (_a + _b); }

◆ getSize()

template<typename Derived , typename Scalar >
Scalar lsst::sphgeom::Interval< Derived, Scalar >::getSize ( ) const
inline

getSize returns the size (length, width) of this interval.

It is zero for single-point intervals, and NaN or negative for empty intervals.

Definition at line 100 of file Interval.h.

100{ return _b - _a; }

◆ intersects() [1/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::intersects ( Interval< Derived, Scalar > const & x) const
inline

intersects returns true if the intersection of this interval and x is non-empty.

Definition at line 139 of file Interval.h.

139 {
140 return !isDisjointFrom(x);
141 }
bool isDisjointFrom(Scalar x) const
Definition Interval.h:122

◆ intersects() [2/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::intersects ( Scalar x) const
inline

intersects returns true if the intersection of this interval and x is non-empty.

Definition at line 137 of file Interval.h.

137{ return _a <= x && x <= _b; }

◆ isDisjointFrom() [1/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::isDisjointFrom ( Interval< Derived, Scalar > const & x) const
inline

isDisjointFrom returns true if the intersection of this interval and x is empty.

Definition at line 126 of file Interval.h.

126 {
127 if (isEmpty() || x.isEmpty()) {
128 return true;
129 }
130 return _a > x._b || _b < x._a;
131 }

◆ isDisjointFrom() [2/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::isDisjointFrom ( Scalar x) const
inline

isDisjointFrom returns true if the intersection of this interval and x is empty.

Definition at line 122 of file Interval.h.

122 {
123 return !intersects(x);
124 }
bool intersects(Scalar x) const
Definition Interval.h:137

◆ isEmpty()

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::isEmpty ( ) const
inline

isEmpty returns true if this interval does not contain any points.

Definition at line 90 of file Interval.h.

90 {
91 return !(_a <= _b); // returns true when _a and/or _b is NaN
92 }

◆ isWithin() [1/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::isWithin ( Interval< Derived, Scalar > const & x) const
inline

isWithin returns true if the intersection of this interval and x is this interval.

Definition at line 151 of file Interval.h.

151 {
152 return x.contains(*this);
153 }

◆ isWithin() [2/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::isWithin ( Scalar x) const
inline

isWithin returns true if the intersection of this interval and x is this interval.

Definition at line 147 of file Interval.h.

147 {
148 return (_a == x && _b == x) || isEmpty();
149 }

◆ operator!=() [1/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::operator!= ( Interval< Derived, Scalar > const & i) const
inline

Definition at line 72 of file Interval.h.

72{ return !(*this == i); }

◆ operator!=() [2/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::operator!= ( Scalar x) const
inline

Definition at line 79 of file Interval.h.

79{ return !(*this == x); }

◆ operator==() [1/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::operator== ( Interval< Derived, Scalar > const & i) const
inline

Two closed intervals are equal if their endpoints are the same, or both are empty.

Definition at line 68 of file Interval.h.

68 {
69 return (_a == i._a && _b == i._b) || (i.isEmpty() && isEmpty());
70 }

◆ operator==() [2/2]

template<typename Derived , typename Scalar >
bool lsst::sphgeom::Interval< Derived, Scalar >::operator== ( Scalar x) const
inline

A closed interval is equal to a point x if both endpoints equal x.

Definition at line 75 of file Interval.h.

75 {
76 return (_a == x && _b == x) || (x != x && isEmpty());
77 }

◆ relate() [1/2]

template<typename Derived , typename Scalar >
Relationship lsst::sphgeom::Interval< Derived, Scalar >::relate ( Interval< Derived, Scalar > const & x) const

relate returns a bitset S describing the spatial relationships between this interval and x. For each relation that holds, the bitwise AND of S and the corresponding Relationship will be non-zero.

Definition at line 276 of file Interval.h.

278{
279 if (isEmpty()) {
280 if (x.isEmpty()) {
281 return CONTAINS | DISJOINT | WITHIN;
282 }
283 return DISJOINT | WITHIN;
284 }
285 if (x.isEmpty()) {
286 return CONTAINS | DISJOINT;
287 }
288 if (_a == x._a && _b == x._b) {
289 return CONTAINS | WITHIN;
290 }
291 if (_a > x._b || _b < x._a) {
292 return DISJOINT;
293 }
294 if (_a <= x._a && _b >= x._b) {
295 return CONTAINS;
296 }
297 if (x._a <= _a && x._b >= _b) {
298 return WITHIN;
299 }
300 return INTERSECTS;
301}

◆ relate() [2/2]

template<typename Derived , typename Scalar >
Relationship lsst::sphgeom::Interval< Derived, Scalar >::relate ( Scalar x) const

relate returns a bitset S describing the spatial relationships between this interval and x. For each relation that holds, the bitwise AND of S and the corresponding Relationship will be non-zero.

Definition at line 256 of file Interval.h.

256 {
257 if (isEmpty()) {
258 if (x != x) {
259 return CONTAINS | DISJOINT | WITHIN;
260 }
261 return DISJOINT | WITHIN;
262 }
263 if (x != x) {
264 return CONTAINS | DISJOINT;
265 }
266 if (_a == x && _b == x) {
267 return CONTAINS | WITHIN;
268 }
269 if (intersects(x)) {
270 return CONTAINS;
271 }
272 return DISJOINT;
273}

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