25#include "AstUtil/Logger.hpp"
26#include "AstUtil/Math.hpp"
47 double start()
const{
return start_;}
48 double stop()
const{
return stop_;}
49 double& start() {
return start_;}
50 double& stop() {
return stop_;}
51 double duration()
const{
return stop_ - start_;}
54 bool isEmpty()
const {
return !(start_ <= stop_); }
56 bool isPoint()
const {
return start_ == stop_; }
60 bool isValid()
const {
return start_ <= stop_; }
64 bool contains(
double t)
const {
return start_ <= t && t <= stop_; }
70 void setBounds(
double start,
double stop);
93 size_t discretizedCount(
double step)
const;
122 bool intersects(
const Interval& other)
const;
142 return Interval{+(std::numeric_limits<double>::infinity()),
143 -(std::numeric_limits<double>::infinity()) };
146inline void Interval::setBounds(
double start,
double stop)
152inline void Interval::setEmpty()
154 start_ = +std::numeric_limits<double>::infinity();
155 stop_ = -std::numeric_limits<double>::infinity();
158inline void Interval::setWhole()
160 start_ = -std::numeric_limits<double>::infinity();
161 stop_ = +std::numeric_limits<double>::infinity();
166 start_ = (std::min)(start_, other.start());
167 stop_ = (std::max)(stop_, other.stop());
173 return Interval{(std::min)(start_, other.start()),
174 (std::max)(stop_, other.stop())};
179 double s = (propagate_nan::max)(start_, other.start_);
180 double t = (propagate_nan::min)(stop_, other.stop());
192 double s = (propagate_nan::max)(start_, other.start_);
193 double t = (propagate_nan::min)(stop_, other.stop());
200inline bool Interval::intersects(
const Interval &other)
const
203 return (propagate_nan::max)(start_, other.start()) <= (propagate_nan::min)(stop_, other.stop());
208 double dur = duration();
209 if(step > 0 && dur >= 0)
211 size_t n =
static_cast<size_t>(std::ceil(dur / step)) + 1;
218inline size_t Interval::discretizedCount(
double step)
const
220 double dur = duration();
221 if(step > 0 && dur >= 0)
223 return static_cast<size_t>(std::ceil(dur / step)) + 1;
按步长采样的相对秒范围(惰性可迭代)
定义 DoubleRange.hpp:41
bool isNonEmpty() const
isValid() 的别名
定义 Interval.hpp:62
bool isDegenerate() const
isPoint() 的别名
定义 Interval.hpp:58
Interval operator&(const Interval &other) const
交集(返回副本,等价于 intersected)
定义 Interval.hpp:134
bool isValid() const
是否非空(start_ <= stop_,即点区间或有效区间)
定义 Interval.hpp:60
bool isPoint() const
是否为点区间(start_ == stop_,恰含一个瞬时,非空)
定义 Interval.hpp:56
bool isEmpty() const
是否为空区间(start_ > stop_,弱序否定;反向 / {+∞,-∞} 哨兵 / NaN 边界 → true)
定义 Interval.hpp:54
Interval & operator|=(const Interval &other)
原地并集(等价于 unite)
定义 Interval.hpp:125
Interval operator|(const Interval &other) const
并集(返回副本,等价于 united)
定义 Interval.hpp:128
bool contains(double t) const
是否包含给定瞬时 t(闭区间含端点)
定义 Interval.hpp:64
Interval & operator&=(const Interval &other)
原地交集(等价于 intersect)
定义 Interval.hpp:131