range.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef EQ_RANGE_H
00019 #define EQ_RANGE_H
00020
00021 #include <eq/base/base.h>
00022
00023 #include <iostream>
00024
00025 namespace eq
00026 {
00030 class Range
00031 {
00032 public:
00037 Range() : start(0.f), end(1.f) {}
00038
00039 Range( const float start_, const float end_ )
00040 : start(start_), end(end_) {}
00042
00043 void apply( const Range& rhs )
00044 {
00045 const float w = end-start;
00046 end = start + rhs.end * w;
00047 start += rhs.start * w;
00048 }
00049
00050 bool operator == ( const Range& rhs ) const
00051 {
00052 return start==rhs.start && end==rhs.end;
00053 }
00054
00055 bool operator != ( const Range& rhs ) const
00056 {
00057 return start!=rhs.start || end!=rhs.end;
00058 }
00059
00060 void invalidate() { start=0.f; end=0.f; }
00061
00062 bool isValid() const
00063 { return ( start>=0.f && end <=1.f && (end - start) >= 0.f ); }
00064
00065 bool hasData() const { return (end - start) > 0.f; }
00066
00067 float start;
00068 float end;
00069
00070 EQ_EXPORT static const Range ALL;
00071 };
00072
00073 inline std::ostream& operator << ( std::ostream& os, const Range& range )
00074 {
00075 os << "range [ " << range.start << " " << range.end << " ]";
00076 return os;
00077 }
00078 }
00079
00080 #endif // EQ_RANGE_H