Skip to content

Commit

Permalink
libdeng2|Range: Added more operators
Browse files Browse the repository at this point in the history
Clamping a range and comparing the whole range to a number.
  • Loading branch information
skyjake committed May 26, 2013
1 parent 2b4e3fb commit b840ebf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion doomsday/libdeng2/include/de/core/range.h
Expand Up @@ -36,20 +36,32 @@ struct Range
Type start;
Type end;

Range(Type const &a = 0, Type const &b = 0) : start(a), end(b) {}
explicit Range(Type const &a = 0, Type const &b = 0) : start(a), end(b) {}
inline Type size() const { return end - start; }
inline bool contains(Type const &i) const { return i >= start && i < end; }
inline Range &operator |= (Type const &value) {
start = de::min(start, value);
end = de::max(end, value);
return *this;
}
inline Range &operator &= (Range const &other) {
start = de::max(start, other.start);
end = de::min(end, other.end);
if(end > start) end = start;
return *this;
}
inline bool operator == (Range const &other) const {
return start == other.start && end == other.end;
}
inline bool operator < (Range const &other) const {
return start < other.start;
}
inline bool operator < (Type const &value) const {
return start < value && end < value;
}
inline bool operator > (Type const &value) const {
return start > value && end > value;
}
inline Range<Type> operator + (Type offset) const {
return Range<Type>(start + offset, end + offset);
}
Expand Down

0 comments on commit b840ebf

Please sign in to comment.