🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
Interval.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstUtil/Logger.hpp"
25
26AST_NAMESPACE_BEGIN
27
37{
38public:
39 static Interval Zero();
40 double start() const{return start_;}
41 double stop() const{return stop_;}
42 double& start() {return start_;}
43 double& stop() {return stop_;}
44 double duration() const{return stop_ - start_;}
45
49 void setStartStop(double start, double stop);
50
55 errc_t merge(const Interval& other);
56public:
57 double start_;
58 double stop_;
59};
60
61
62inline Interval Interval::Zero()
63{
64 return Interval{0.0, 0.0};
65}
66
67inline void Interval::setStartStop(double start, double stop)
68{
69 start_ = start;
70 stop_ = stop;
71}
72
73inline errc_t Interval::merge(const Interval &other)
74{
75 if (start_ > other.stop() || other.start() > stop_)
76 {
77 aError("merge interval failed, no overlap");
78 return eErrorInvalidParam;
79 }
80 start_ = std::min(start_, other.start());
81 stop_ = std::max(stop_, other.stop());
82 return eNoError;
83}
84
85
88AST_NAMESPACE_END
相对时间区间
定义 Interval.hpp:37