25#include "AstUtil/Logger.hpp"
26#include "AstUtil/Math.hpp"
50 double start()
const{
return start_;}
51 double stop()
const{
return stop_;}
52 double& start() {
return start_;}
53 double& stop() {
return stop_;}
54 double duration()
const{
return stop_ - start_;}
57 bool isEmpty()
const {
return !(start_ <= stop_); }
59 bool isPoint()
const {
return start_ == stop_; }
63 bool isValid()
const {
return start_ <= stop_; }
67 bool contains(
double t)
const {
return start_ <= t && t <= stop_; }
73 void setBounds(
double start,
double stop);
96 size_t discretizedCount(
double step)
const;
125 bool intersects(
const Interval& other)
const;
145 return Interval{+(std::numeric_limits<double>::infinity()),
146 -(std::numeric_limits<double>::infinity()) };
151 return Interval{-std::numeric_limits<double>::infinity(),
152 +std::numeric_limits<double>::infinity()};
155inline void Interval::setBounds(
double start,
double stop)
161inline void Interval::setEmpty()
163 start_ = +std::numeric_limits<double>::infinity();
164 stop_ = -std::numeric_limits<double>::infinity();
167inline void Interval::setWhole()
169 start_ = -std::numeric_limits<double>::infinity();
170 stop_ = +std::numeric_limits<double>::infinity();
175 start_ = (std::min)(start_, other.start());
176 stop_ = (std::max)(stop_, other.stop());
182 return Interval{(std::min)(start_, other.start()),
183 (std::max)(stop_, other.stop())};
188 double s = (propagate_nan::max)(start_, other.start_);
189 double t = (propagate_nan::min)(stop_, other.stop());
201 double s = (propagate_nan::max)(start_, other.start_);
202 double t = (propagate_nan::min)(stop_, other.stop());
209inline bool Interval::intersects(
const Interval &other)
const
212 return (propagate_nan::max)(start_, other.start()) <= (propagate_nan::min)(stop_, other.stop());
217 double dur = duration();
218 if(step > 0 && dur >= 0)
226inline size_t Interval::discretizedCount(
double step)
const
228 double dur = duration();
229 if(step > 0 && dur >= 0)
按步长采样的相对秒范围(惰性可迭代)
定义 DoubleRange.hpp:43
bool isNonEmpty() const
isValid() 的别名
定义 Interval.hpp:65
bool isDegenerate() const
isPoint() 的别名
定义 Interval.hpp:61
Interval operator&(const Interval &other) const
交集(返回副本,等价于 intersected)
定义 Interval.hpp:137
bool isValid() const
是否非空(start_ <= stop_,即点区间或有效区间)
定义 Interval.hpp:63
bool isPoint() const
是否为点区间(start_ == stop_,恰含一个瞬时,非空)
定义 Interval.hpp:59
bool isEmpty() const
是否为空区间(start_ > stop_,弱序否定;反向 / {+∞,-∞} 哨兵 / NaN 边界 → true)
定义 Interval.hpp:57
Interval & operator|=(const Interval &other)
原地并集(等价于 unite)
定义 Interval.hpp:128
Interval operator|(const Interval &other) const
并集(返回副本,等价于 united)
定义 Interval.hpp:131
bool contains(double t) const
是否包含给定瞬时 t(闭区间含端点)
定义 Interval.hpp:67
Interval & operator&=(const Interval &other)
原地交集(等价于 intersect)
定义 Interval.hpp:134
A_ALWAYS_INLINE size_t aDiscretizedCount(double span, double step)
计算闭区间 [0, span] 按 step 步长采样(含两端点)的采样点数
定义 Math.hpp:107