diff options
Diffstat (limited to 'src/2geom/interval.h')
| -rw-r--r-- | src/2geom/interval.h | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/2geom/interval.h b/src/2geom/interval.h index 459f2cd49..19e08978c 100644 --- a/src/2geom/interval.h +++ b/src/2geom/interval.h @@ -59,57 +59,50 @@ public: _b[0] = v; _b[1] = u; } } - + double operator[](unsigned i) const { assert(i < 2); return _b[i]; } - double& operator[](unsigned i) { return _b[i]; } //Trust the user... - - Coord min() const { return _b[0]; } - Coord max() const { return _b[1]; } - Coord extent() const { return _b[1] - _b[0]; } - Coord middle() const { return (_b[1] + _b[0]) * 0.5; } - - bool isEmpty() const { return _b[0] == _b[1]; } - bool contains(Coord val) const { return _b[0] <= val && val <= _b[1]; } + inline double& operator[](unsigned i) { return _b[i]; } //Trust the user... + + inline Coord min() const { return _b[0]; } + inline Coord max() const { return _b[1]; } + inline Coord extent() const { return _b[1] - _b[0]; } + inline Coord middle() const { return (_b[1] + _b[0]) * 0.5; } + + inline bool isEmpty() const { return _b[0] == _b[1]; } + inline bool contains(Coord val) const { return _b[0] <= val && val <= _b[1]; } bool contains(const Interval & val) const { return _b[0] <= val._b[0] && val._b[1] <= _b[1]; } bool intersects(const Interval & val) const { return contains(val._b[0]) || contains(val._b[1]) || val.contains(*this); } - - static Interval fromArray(const Coord* c, int n) { - assert(n > 0); - Interval result(c[0]); - for(int i = 1; i < n; i++) result.extendTo(c[i]); - return result; - } - - bool operator==(Interval other) { return _b[0] == other._b[0] && _b[1] == other._b[1]; } - bool operator!=(Interval other) { return _b[0] != other._b[0] || _b[1] != other._b[1]; } - + + inline bool operator==(Interval other) { return _b[0] == other._b[0] && _b[1] == other._b[1]; } + inline bool operator!=(Interval other) { return _b[0] != other._b[0] || _b[1] != other._b[1]; } + //IMPL: OffsetableConcept //TODO: rename output_type to something else in the concept typedef Coord output_type; - Interval operator+(Coord amnt) { + inline Interval operator+(Coord amnt) { return Interval(_b[0] + amnt, _b[1] + amnt); } - Interval operator-(Coord amnt) { + inline Interval operator-(Coord amnt) { return Interval(_b[0] - amnt, _b[1] - amnt); } - Interval operator+=(Coord amnt) { + inline Interval operator+=(Coord amnt) { _b[0] += amnt; _b[1] += amnt; return *this; } - Interval operator-=(Coord amnt) { + inline Interval operator-=(Coord amnt) { _b[0] -= amnt; _b[1] -= amnt; return *this; } - + //IMPL: ScalableConcept - Interval operator-() const { return Interval(*this); } - Interval operator*(Coord s) const { return Interval(_b[0]*s, _b[1]*s); } - Interval operator/(Coord s) const { return Interval(_b[0]/s, _b[1]/s); } + inline Interval operator-() const { return Interval(*this); } + inline Interval operator*(Coord s) const { return Interval(_b[0]*s, _b[1]*s); } + inline Interval operator/(Coord s) const { return Interval(_b[0]/s, _b[1]/s); } Interval operator*=(Coord s) { if(s < 0) { Coord temp = _b[0]; @@ -133,7 +126,7 @@ public: } return *this; } - + //TODO: NaN handleage for the next two? //TODO: Evaluate if wrap behaviour is proper. //If val > max, then rather than becoming a min==max range, it 'wraps' over @@ -154,18 +147,25 @@ public: _b[1] = val; } } - - void extendTo(Coord val) { + + inline void extendTo(Coord val) { if(val < _b[0]) _b[0] = val; if(val > _b[1]) _b[1] = val; //no else, as we want to handle NaN } - - void expandBy(double amnt) { + + static Interval fromArray(const Coord* c, int n) { + assert(n > 0); + Interval result(c[0]); + for(int i = 1; i < n; i++) result.extendTo(c[i]); + return result; + } + + inline void expandBy(double amnt) { _b[0] -= amnt; _b[1] += amnt; } - - void unionWith(const Interval & a) { + + inline void unionWith(const Interval & a) { if(a._b[0] < _b[0]) _b[0] = a._b[0]; if(a._b[1] > _b[1]) _b[1] = a._b[1]; } |
