Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TIMERANGE_H
00030 #define TIMERANGE_H
00031
00032 #include <QtCore>
00033 #include "GeopsyCoreDLLExport.h"
00034
00035 namespace GeopsyCore {
00036
00037 class GEOPSYCORE_EXPORT TimeRange
00038 {
00039 public:
00040 inline TimeRange();
00041 inline TimeRange(const TimeRange& o) {operator=(o);}
00042 inline TimeRange(double start, double end);
00043 ~TimeRange() {}
00044
00045 inline void operator=(const TimeRange& o);
00046
00047 double start() const {return _start;}
00048 double end() const {return _end;}
00049
00050 inline void setStart(double m);
00051 inline void setEnd(double m);
00052 inline void sort();
00053
00054 inline void shift(double s);
00055 inline TimeRange shifted(double s) const;
00056 inline void scale(double center, double factor);
00057
00058 int lengthSamples(double deltaT) const {return (int)round(lengthSeconds()/deltaT);}
00059 double lengthSeconds() const {return _end-_start;}
00060
00061 inline TimeRange intersection(const TimeRange& tw) const;
00062 inline bool intersects(const TimeRange& tw) const;
00063
00064 void printDebug() const;
00065 private:
00066 double _start;
00067 double _end;
00068 };
00069
00070 inline TimeRange::TimeRange()
00071 {
00072 _start=0.0;
00073 _end=0.0;
00074 }
00075
00076 inline TimeRange::TimeRange(double start, double end)
00077 {
00078 if(start>end) {
00079 _start=end;
00080 _end=start;
00081 } else {
00082 _start=start;
00083 _end=end;
00084 }
00085 }
00086
00087 inline void TimeRange::operator=(const TimeRange& o)
00088 {
00089 _start=o._start;
00090 _end=o._end;
00091 }
00092
00093 inline void TimeRange::setStart(double m)
00094 {
00095 _start=m;
00096 }
00097
00098 inline void TimeRange::setEnd(double m)
00099 {
00100 _end=m;
00101 }
00102
00103 inline void TimeRange::sort()
00104 {
00105 if(_start>_end) {
00106 qSwap(_start, _end);
00107 }
00108 }
00109
00110 inline void TimeRange::shift(double s)
00111 {
00112 _start+=s;
00113 _end+=s;
00114 }
00115
00116 inline TimeRange TimeRange::shifted(double s) const
00117 {
00118 return TimeRange(_start+s, _end+s);
00119 }
00120
00121 inline void TimeRange::scale(double center, double factor)
00122 {
00123 _start=center+(_start-center)*factor;
00124 _end=center+(_end-center)*factor;
00125 }
00126
00127 inline TimeRange TimeRange::intersection(const TimeRange& tw) const
00128 {
00129 TimeRange res;
00130 if(tw._end < _start || tw._start > _end)
00131 return res;
00132 if(tw._start < _start && _start < tw._end)
00133 res._start=_start;
00134 else
00135 res._start=tw._start;
00136 if(tw._start < _end && _end < tw._end)
00137 res._end=_end;
00138 else
00139 res._end=tw._end;
00140 return res;
00141 }
00142
00143 inline bool TimeRange::intersects(const TimeRange& tw) const
00144 {
00145 if(tw._end < _start || tw._start > _end)
00146 return false;
00147 return true;
00148 }
00149
00150 }
00151
00152
00153 Q_DECLARE_METATYPE(GeopsyCore::TimeRange);
00154
00155 #endif // TIMERANGE_H