Numeric range class, obsolete clip_range.
[lsnes.git] / src / library / range.cpp
blob4ff2709d40de4df7b854b16b5935cc847ae22aac
1 #include "range.hpp"
2 #include "minmax.hpp"
4 range range::make_b(uint32_t l, uint32_t h)
6 return range(l, h);
9 range::range(uint32_t l, uint32_t h)
11 _low = l;
12 _high = h;
15 range& range::operator+=(uint32_t o) throw()
17 _low += o;
18 _high += o;
20 return *this;
23 range& range::operator&=(const range& b) throw()
25 //Offset ranges down.
26 uint32_t offset = _low;
27 uint32_t L = _high - _low;
28 uint32_t A = b._low - _low;
29 uint32_t B = b._high - _low;
31 bool asl = (A < L); //There is initial overlap between ranges.
32 bool asb = (A <= B); //Range 2 does not warp around.
34 //If there is initial overlap, the range bottom is A+offset, otherwise 0+offset.
35 _low = offset + (asl ? A : 0);
36 //If asl EQU asb, then range top is min(L, B). Otherwise if asl, it is L, otherwise 0.
37 _high = offset + ((asl == asb) ? min(L, B) : (asl ? L : 0));
39 return *this;
42 bool range::in(uint32_t x) const throw()
44 return ((x - _low) < (_high - _low));