25#include "AstUtil/Logger.hpp"
26#include "AstUtil/Math.hpp"
51 double start()
const{
return start_;}
52 double stop()
const{
return stop_;}
53 double& start() {
return start_;}
54 double& stop() {
return stop_;}
55 double duration()
const{
return stop_ - start_;}
58 bool isEmpty()
const {
return !(start_ <= stop_); }
60 bool isPoint()
const {
return start_ == stop_; }
64 bool isValid()
const {
return start_ <= stop_; }
68 bool contains(
double t)
const {
return start_ <= t && t <= stop_; }
74 void setBounds(
double start,
double stop);
97 size_t discretizedCount(
double step)
const;
126 bool intersects(
const Interval& other)
const;
141 std::string toString()
const;
149 return Interval{+(std::numeric_limits<double>::infinity()),
150 -(std::numeric_limits<double>::infinity()) };
155 return Interval{-std::numeric_limits<double>::infinity(),
156 +std::numeric_limits<double>::infinity()};
159inline void Interval::setBounds(
double start,
double stop)
165inline void Interval::setEmpty()
167 start_ = +std::numeric_limits<double>::infinity();
168 stop_ = -std::numeric_limits<double>::infinity();
171inline void Interval::setWhole()
173 start_ = -std::numeric_limits<double>::infinity();
174 stop_ = +std::numeric_limits<double>::infinity();
179 start_ = (std::min)(start_, other.start());
180 stop_ = (std::max)(stop_, other.stop());
186 return Interval{(std::min)(start_, other.start()),
187 (std::max)(stop_, other.stop())};
192 double s = (propagate_nan::max)(start_, other.start_);
193 double t = (propagate_nan::min)(stop_, other.stop());
205 double s = (propagate_nan::max)(start_, other.start_);
206 double t = (propagate_nan::min)(stop_, other.stop());
213inline bool Interval::intersects(
const Interval &other)
const
216 return (propagate_nan::max)(start_, other.start()) <= (propagate_nan::min)(stop_, other.stop());
221 double dur = duration();
222 if(step > 0 && dur >= 0)
230inline size_t Interval::discretizedCount(
double step)
const
232 double dur = duration();
233 if(step > 0 && dur >= 0)
按步长采样的相对秒范围(惰性可迭代)
定义 DoubleRange.hpp:43
bool isNonEmpty() const
isValid() 的别名
定义 Interval.hpp:66
bool isDegenerate() const
isPoint() 的别名
定义 Interval.hpp:62
Interval operator&(const Interval &other) const
交集(返回副本,等价于 intersected)
定义 Interval.hpp:138
bool isValid() const
是否非空(start_ <= stop_,即点区间或有效区间)
定义 Interval.hpp:64
bool isPoint() const
是否为点区间(start_ == stop_,恰含一个瞬时,非空)
定义 Interval.hpp:60
bool isEmpty() const
是否为空区间(start_ > stop_,弱序否定;反向 / {+∞,-∞} 哨兵 / NaN 边界 → true)
定义 Interval.hpp:58
Interval & operator|=(const Interval &other)
原地并集(等价于 unite)
定义 Interval.hpp:129
Interval operator|(const Interval &other) const
并集(返回副本,等价于 united)
定义 Interval.hpp:132
bool contains(double t) const
是否包含给定瞬时 t(闭区间含端点)
定义 Interval.hpp:68
Interval & operator&=(const Interval &other)
原地交集(等价于 intersect)
定义 Interval.hpp:135
A_ALWAYS_INLINE size_t aDiscretizedCount(double span, double step)
计算闭区间 [0, span] 按 step 步长采样(含两端点)的采样点数
定义 Math.hpp:107