39 #include "metaprogramming.hxx"
40 #include "numerictraits.hxx"
41 #include "tinyvector.hxx"
48 template<
class VALUETYPE>
49 struct EndInsidePolicy
51 static inline bool isEmptyRange(VALUETYPE b, VALUETYPE e)
56 static inline VALUETYPE pointEnd(VALUETYPE p)
63 template<
class VALUETYPE>
64 struct EndOutsidePolicy
66 static inline bool isEmptyRange(VALUETYPE b, VALUETYPE e)
71 static inline VALUETYPE pointEnd(VALUETYPE p)
87 template<
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())
129 : begin_(begin), end_(end)
163 Vector
const &
end()
const
200 end_ += newBegin - begin_;
222 VolumeType result(end_[0] - begin_[0]);
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;
272 return (begin_ == r.begin_) && (end_ == r.end_);
278 return (begin_ != r.begin_) || (end_ != r.end_);
291 for(
unsigned int i = 0; i < DIMENSION; ++i)
292 if(RangePolicy::isEmptyRange(begin_[i], end_[i]))
303 for(
unsigned int i = 0; i < DIMENSION; ++i)
304 if((p[i] < begin_[i]) ||
305 RangePolicy::isEmptyRange(p[i], end_[i]))
322 for(
unsigned int i = 0; i < DIMENSION; ++i)
323 if(r.end_[i] > end_[i])
337 for(
unsigned int i = 0; i < DIMENSION; ++i)
338 if(RangePolicy::isEmptyRange(r.begin_[i], end_[i]) ||
339 RangePolicy::isEmptyRange(begin_[i], r.end_[i]))
354 for(
unsigned int i = 0; i < DIMENSION; ++i)
355 end_[i] = RangePolicy::pointEnd(p[i]);
359 for(
unsigned int i = 0; i < DIMENSION; ++i)
363 if(RangePolicy::isEmptyRange(p[i], end_[i]))
364 end_[i] = RangePolicy::pointEnd(p[i]);
391 return this->
operator=(r);
393 for(
unsigned int i = 0; i < DIMENSION; ++i)
395 if(r.begin_[i] < begin_[i])
396 begin_[i] = r.begin_[i];
397 if(end_[i] < r.end_[i])
424 return this->
operator=(r);
426 for(
unsigned int i = 0; i < DIMENSION; ++i)
428 if(begin_[i] < r.begin_[i])
429 begin_[i] = r.begin_[i];
430 if(r.end_[i] < end_[i])
545 #endif // VIGRA_BOX_HXX
Vector size() const
Definition: box.hxx:232
void moveBy(Vector const &offset)
Definition: box.hxx:207
bool contains(Box const &r) const
Definition: box.hxx:316
Box(Vector const &size)
Definition: box.hxx:135
Box & operator/=(double scale)
Definition: box.hxx:476
Box operator/(double scale)
Definition: box.hxx:487
bool contains(Vector const &p) const
Definition: box.hxx:301
Box & operator&=(Box const &r)
Definition: box.hxx:419
Vector & end()
Definition: box.hxx:174
void setSize(Vector const &size)
Definition: box.hxx:240
Box & operator|=(Vector const &p)
Definition: box.hxx:349
Box & operator*=(double scale)
Definition: box.hxx:453
Box operator-(const Vector &offset)
Definition: box.hxx:533
VolumeType volume() const
Definition: box.hxx:217
Vector const & end() const
Definition: box.hxx:163
VALUETYPE value_type
Definition: box.hxx:93
void moveTo(Vector const &newBegin)
Definition: box.hxx:198
NumericTraits< VALUETYPE >::Promote VolumeType
Definition: box.hxx:97
Box operator&(Box const &r) const
Definition: box.hxx:441
Vector & begin()
Definition: box.hxx:152
Box()
Definition: box.hxx:119
Vector const & begin() const
Definition: box.hxx:143
Definition: accessor.hxx:43
Box & operator-=(const Vector &offset)
Definition: box.hxx:522
Box & operator+=(const Vector &offset)
Definition: box.hxx:499
Box operator|(Box const &r) const
Definition: box.hxx:407
Represent an n-dimensional box as a (begin, end) pair. Depending on the value type, end() is considered to be outside the box (as in the STL, for integer types), or inside (for floating point types). size() will always be end() - begin().
Definition: box.hxx:88
TinyVector< VALUETYPE, DIMENSION > Vector
Definition: box.hxx:101
void setEnd(Vector const &end)
Definition: box.hxx:190
Box(Vector const &begin, Vector const &end)
Definition: box.hxx:128
bool intersects(Box const &r) const
Definition: box.hxx:333
void addSize(Vector const &offset)
Definition: box.hxx:250
bool operator==(Box const &r) const
equality check
Definition: box.hxx:270
Box operator+(const Vector &offset)
Definition: box.hxx:510
bool isEmpty() const
Definition: box.hxx:289
Box operator*(double scale)
Definition: box.hxx:464
If< typename NumericTraits< VALUETYPE >::isIntegral, detail::EndOutsidePolicy< VALUETYPE >, detail::EndInsidePolicy< VALUETYPE > >::type RangePolicy
Definition: box.hxx:112
void setBegin(Vector const &begin)
Definition: box.hxx:182
void addBorder(VALUETYPE borderWidth)
Definition: box.hxx:260
Box & operator|=(Box const &r)
Definition: box.hxx:386
bool operator!=(Box const &r) const
inequality check
Definition: box.hxx:276
Box operator|(Vector const &p) const
Definition: box.hxx:375