39#include "metaprogramming.hxx"
40#include "numerictraits.hxx"
41#include "tinyvector.hxx"
48template<
class VALUETYPE>
51 static inline bool isEmptyRange(VALUETYPE b, VALUETYPE e)
56 static inline VALUETYPE pointEnd(VALUETYPE p)
63template<
class VALUETYPE>
64struct EndOutsidePolicy
66 static inline bool isEmptyRange(VALUETYPE b, VALUETYPE e)
71 static inline VALUETYPE pointEnd(VALUETYPE p)
87template<
class VALUETYPE,
unsigned int DIMENSION>
97 typedef typename NumericTraits<VALUETYPE>::Promote
VolumeType;
103 enum { Dimension = DIMENSION };
110 typedef typename If<typename NumericTraits<VALUETYPE>::isIntegral,
111 detail::EndOutsidePolicy<VALUETYPE>,
120 : begin_(NumericTraits<
Vector>::one())
200 end_ += newBegin - begin_;
223 for(
unsigned int i = 1; i < DIMENSION; ++i)
224 result *= end_[i] - begin_[i];
234 return end_ - begin_;
242 end_ = begin_ +
size;
262 for(
unsigned int i = 0; i < DIMENSION; ++i)
264 begin_[i] -= borderWidth;
265 end_[i] += borderWidth;
276 begin_ -= borderWidth;
285 return (begin_ == r.begin_) && (end_ == r.end_);
291 return (begin_ != r.begin_) || (end_ != r.end_);
304 for(
unsigned int i = 0; i < DIMENSION; ++i)
305 if(RangePolicy::isEmptyRange(begin_[i], end_[i]))
316 for(
unsigned int i = 0; i < DIMENSION; ++i)
317 if((p[i] < begin_[i]) ||
318 RangePolicy::isEmptyRange(p[i], end_[i]))
335 for(
unsigned int i = 0; i < DIMENSION; ++i)
336 if(r.end_[i] > end_[i])
350 for(
unsigned int i = 0; i < DIMENSION; ++i)
351 if(RangePolicy::isEmptyRange(r.begin_[i], end_[i]) ||
352 RangePolicy::isEmptyRange(begin_[i], r.end_[i]))
367 for(
unsigned int i = 0; i < DIMENSION; ++i)
368 end_[i] = RangePolicy::pointEnd(p[i]);
372 for(
unsigned int i = 0; i < DIMENSION; ++i)
376 if(RangePolicy::isEmptyRange(p[i], end_[i]))
377 end_[i] = RangePolicy::pointEnd(p[i]);
404 return this->operator=(r);
406 for(
unsigned int i = 0; i < DIMENSION; ++i)
408 if(r.begin_[i] < begin_[i])
409 begin_[i] = r.begin_[i];
410 if(end_[i] < r.end_[i])
437 return this->operator=(r);
439 for(
unsigned int i = 0; i < DIMENSION; ++i)
441 if(begin_[i] < r.begin_[i])
442 begin_[i] = r.begin_[i];
443 if(r.end_[i] < end_[i])
554template<
class VALUETYPE,
unsigned int DIMENSION>
555std::ostream& operator<< (std::ostream& stream,
const Box<VALUETYPE, DIMENSION> & box) {
556 stream<<
"["<<box.
begin()<<
", "<<box.
end()<<
" ]";
Represent an n-dimensional box as a (begin, end) pair. Depending on the value type,...
Definition box.hxx:89
If< typenameNumericTraits< VALUETYPE >::isIntegral, detail::EndOutsidePolicy< VALUETYPE >, detail::EndInsidePolicy< VALUETYPE > >::type RangePolicy
Definition box.hxx:112
Box operator|(Box const &r) const
Definition box.hxx:420
NumericTraits< VALUETYPE >::Promote VolumeType
Definition box.hxx:97
Vector const & end() const
Definition box.hxx:163
void setBegin(Vector const &begin)
Definition box.hxx:182
Vector size() const
Definition box.hxx:232
Vector & begin()
Definition box.hxx:152
void setSize(Vector const &size)
Definition box.hxx:240
TinyVector< VALUETYPE, DIMENSION > Vector
Definition box.hxx:101
void addSize(Vector const &offset)
Definition box.hxx:250
Box operator&(Box const &r) const
Definition box.hxx:454
Box & operator|=(Vector const &p)
Definition box.hxx:362
Box operator*(double scale) const
Definition box.hxx:477
Vector & end()
Definition box.hxx:174
Vector const & begin() const
Definition box.hxx:143
VALUETYPE value_type
Definition box.hxx:93
bool contains(Box const &r) const
Definition box.hxx:329
Box(Vector const &size)
Definition box.hxx:135
Box & operator/=(double scale)
Definition box.hxx:489
Box & operator+=(const Vector &offset)
Definition box.hxx:512
Box operator|(Vector const &p) const
Definition box.hxx:388
bool intersects(Box const &r) const
Definition box.hxx:346
Box & operator&=(Box const &r)
Definition box.hxx:432
Box operator/(double scale) const
Definition box.hxx:500
void moveTo(Vector const &newBegin)
Definition box.hxx:198
Box & operator*=(double scale)
Definition box.hxx:466
Box & operator-=(const Vector &offset)
Definition box.hxx:535
Box operator-(const Vector &offset) const
Definition box.hxx:546
bool contains(Vector const &p) const
Definition box.hxx:314
bool isEmpty() const
Definition box.hxx:302
void moveBy(Vector const &offset)
Definition box.hxx:207
void addBorder(const Vector &borderWidth)
Definition box.hxx:274
Box(Vector const &begin, Vector const &end)
Definition box.hxx:128
Box()
Definition box.hxx:119
Box & operator|=(Box const &r)
Definition box.hxx:399
VolumeType volume() const
Definition box.hxx:217
void addBorder(VALUETYPE borderWidth)
Definition box.hxx:260
bool operator==(Box const &r) const
equality check
Definition box.hxx:283
Box operator+(const Vector &offset) const
Definition box.hxx:523
bool operator!=(Box const &r) const
inequality check
Definition box.hxx:289
void setEnd(Vector const &end)
Definition box.hxx:190
iterator end()
Definition tinyvector.hxx:864
Class for fixed size vectors.
Definition tinyvector.hxx:1008