MIRA
Rect.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_RECT_H_
48 #define _MIRA_RECT_H_
49 
50 #include <geometry/Line.h>
51 #include <geometry/Size.h>
52 
53 #include <utils/IsCheapToCopy.h>
54 
55 namespace mira
56 {
57 
59 
70 template<typename T, int D, typename Derived>
71 class RectBase
72 {
73 public:
76  typedef boost::geometry::model::box<PointType> BoxType;
77 
78 public:
81 
84  {
85  for(int d=0; d<D; ++d) {
86  minCorner[d] = 0;
87  maxCorner[d] = -1;
88  }
89  }
90 
92  RectBase(T x, T y, T z, T width, T height, T depth) :
93  minCorner(x, y, z), maxCorner(x+width, y+height, z+depth) {}
94 
96  RectBase(T x, T y, T width, T height) :
97  minCorner(x, y), maxCorner(x+width, y+height) {}
98 
100  explicit RectBase(const PointType& pos, T width, T height) :
101  minCorner(pos), maxCorner(pos.x()+width, pos.y()+height) {}
102 
104  explicit RectBase(const PointType& pos, T width, T height, T depth) :
105  minCorner(pos), maxCorner(pos.x()+width, pos.y()+height, pos.z()+depth) {}
106 
109  explicit RectBase(const PointType& pos, const SizeType& s) :
110  minCorner(pos), maxCorner(pos+s) {}
111 
113  explicit RectBase(const BoxType& box) :
114  minCorner(box.min_corner()), maxCorner(box.max_corner()) {}
115 
123  explicit RectBase(const PointType& p1, const PointType& p2,
124  bool makeValid)
125  {
126  for(int d=0; d<D; ++d)
127  {
128  if(makeValid && (p1[d]>p2[d])) {
129  minCorner[d]=p2[d];
130  maxCorner[d]=p1[d];
131  } else {
132  minCorner[d]=p1[d];
133  maxCorner[d]=p2[d];
134  }
135  }
136  }
137 
139 
140 public:
142  template<typename Reflector>
143  void reflect(Reflector& reflector)
144  {
145  reflector.property("MinCorner", minCorner, "The minimum corner");
146  reflector.property("MaxCorner", maxCorner, "The maximum corner");
147  }
148 
149 public:
152 
154  operator BoxType() const {
155  return BoxType(minCorner, maxCorner);
156  }
157 
159 
160 public:
162  SizeType size() const {
163  return SizeType(maxCorner-minCorner);
164  }
165 
166 public:
169 
170  template <typename OtherDerived>
171  bool operator==(const RectBase<T,D, OtherDerived>& other) const {
172  return minCorner == other.minCorner && maxCorner == other.maxCorner;
173  }
174 
175  template <typename OtherDerived>
176  bool operator!=(const RectBase<T,D, OtherDerived>& other) const {
177  return !this->operator==(other);
178  }
179 
181 
182 public:
185 
187  template <typename OtherGeometry>
188  bool contains(const OtherGeometry& otherGeometry) const {
189  return boost::geometry::within(otherGeometry, *this);
190  }
191 
193  template <typename OtherGeometry>
194  bool intersects(const OtherGeometry& otherGeometry) const {
195  return boost::geometry::intersects(otherGeometry, *this);
196  }
197 
199  template <typename OtherGeometry>
200  bool disjoint(const OtherGeometry& otherGeometry) const {
201  return boost::geometry::disjoint(otherGeometry, *this);
202  }
203 
205 
206 public:
209 
215  bool isValid() const {
216  for(int d=0; d<D; ++d)
217  if(maxCorner[d]<minCorner[d])
218  return false;
219  return true;
220  }
221 
226  static Derived invalid() {
227  return Derived();
228  }
229 
235  Derived normalized() const
236  {
237  Derived r;
238  for(int d=0; d<D; ++d)
239  {
240  if(maxCorner[d]<minCorner[d]) {
241  r.maxCorner[d] = minCorner[d];
242  r.minCorner[d] = maxCorner[d];
243  } else {
244  r.maxCorner[d] = maxCorner[d];
245  r.minCorner[d] = minCorner[d];
246  }
247  }
248  return r;
249  }
250 
255  bool isNull() const {
256  for(int d=0; d<D; ++d)
257  if(maxCorner[d]!=minCorner[d])
258  return false;
259  return true;
260  }
261 
266  static Derived null() {
267  Derived r;
269  r.maxCorner = Eigen::Matrix<T,D,1>::Zero(D,1);
270  return r;
271  }
272 
276  static Derived zero() {
277  return null();
278  }
280 
281 public:
284 
294  Derived operator|(const Derived& other) const
295  {
296  if(!this->isValid())
297  return other;
298  if(!other.isValid())
299  return *((Derived*)this); // we are of type Derived
300 
301  Derived r;
302  for(int d=0; d<D; ++d) {
303  r.minCorner[d] = std::min(minCorner[d], other.minCorner[d]);
304  r.maxCorner[d] = std::max(maxCorner[d], other.maxCorner[d]);
305  }
306  return r;
307  }
308 
317  const Derived& operator|=(const Derived& other)
318  {
319  if(!isValid()) {
320  *this = other;
321  } else if(other.isValid()) {
322  for(int d=0; d<D; ++d) {
323  if(other.minCorner[d]<minCorner[d])
324  minCorner[d] = other.minCorner[d];
325  if(other.maxCorner[d]>maxCorner[d])
326  maxCorner[d] = other.maxCorner[d];
327  }
328  }
329  return *((Derived*)this); // we are of type Derived
330  }
331 
352  const Derived& operator|=(const PointType& p)
353  {
354  if(!isValid()) {
355  minCorner = p;
356  maxCorner = p;
357  } else {
358  for(int d=0; d<D; ++d) {
359  if(p[d]<minCorner[d])
360  minCorner[d] = p[d];
361  if(p[d]>maxCorner[d])
362  maxCorner[d] = p[d];
363  }
364  }
365  return *((Derived*)this); // we are of type Derived
366  }
367 
379  Derived operator&(const Derived& other) const
380  {
381  if(!isValid())
382  return invalid();
383  if(!other.isValid())
384  return invalid();
385 
386  Derived r;
387  for(int d=0; d<D; ++d) {
388  r.minCorner[d] = std::max(minCorner[d], other.minCorner[d]);
389  r.maxCorner[d] = std::min(maxCorner[d], other.maxCorner[d]);
390  }
391  return r;
392  }
393 
398  const Derived& operator&=(const Derived& other)
399  {
400  if(!isValid())
401  return *((Derived*)this);
402 
403  if(!other.isValid()) {
404  *this = other;
405  } else {
406  for(int d=0; d<D; ++d) {
407  minCorner[d] = std::max(minCorner[d], other.minCorner[d]);
408  maxCorner[d] = std::min(maxCorner[d], other.maxCorner[d]);
409  }
410  }
411  return *((Derived*)this);
412  }
414 
416  template<typename U, typename OtherDerived>
417  static Derived convertFrom(const RectBase<U,D, OtherDerived>& other) {
418  return Derived(PointType(other.minCorner.template cast<T>()),
419  PointType(other.maxCorner.template cast<T>()));
420  }
421 
425  const Derived& operator+=(const PointType& displacement)
426  {
427  minCorner+=displacement;
428  maxCorner+=displacement;
429  return *((Derived*)this);
430  }
431 
435  Derived operator+(const PointType& displacement) const
436  {
437  return Derived((PointType)(minCorner+displacement), (PointType)(maxCorner+displacement));
438  }
439 
440 public:
443 };
444 
446 
452 template<typename T, int D>
453 class Rect : public RectBase<T,D, Rect<T,D> >
454 {
455 public:
457  typedef typename Base::PointType PointType;
458  typedef typename Base::SizeType SizeType;
459  typedef typename Base::BoxType BoxType;
460 
461 public:
463  Rect() {}
464 
466  Rect(const PointType& p1, const PointType& p2,
467  bool makeValid = true) :
468  Base(p1, p2, makeValid) {}
469 };
470 
472 
478 template<typename T>
479 class Rect<T,2> : public RectBase<T,2, Rect<T,2> >
480 {
481 public:
483  typedef typename Base::PointType PointType;
484  typedef typename Base::SizeType SizeType;
485  typedef typename Base::BoxType BoxType;
486 
487 public:
490 
492  Rect() {}
493 
501  Rect(T x, T y, T width, T height) :
502  Base(x, y, width, height) {}
503 
510  Rect(const PointType& pos, T width, T height) :
511  Base(pos, width, height) {}
512 
518  Rect(const PointType& pos, const SizeType& s) :
519  Base(pos, s) {}
520 
522  explicit Rect(const BoxType& box) :
523  Base(box) {}
524 
526  explicit Rect(const cv::Rect_<T>& rect) :
527  Base(rect.x, rect.y, rect.width, rect.height) {}
528 
534  Rect(const PointType& p1, const PointType& p2,
535  bool makeValid = true) :
536  Base(p1, p2, makeValid) {}
537 
539 
540 public:
543 
545  operator cv::Rect_<T>() const
546  {
547  return cv::Rect_<T>(Base::minCorner, Base::size());
548  }
549 
551 
552 public:
555 
557  T& x0() { return this->minCorner[0]; }
559  T x0() const { return this->minCorner[0]; }
560 
562  T& y0() { return this->minCorner[1]; }
564  T y0() const { return this->minCorner[1]; }
565 
567  T& x1() { return this->maxCorner[0]; }
569  T x1() const { return this->maxCorner[0]; }
570 
572  T& y1() { return this->maxCorner[1]; }
574  T y1() const { return this->maxCorner[1]; }
575 
577  T width() const { return this->maxCorner[0] - this->minCorner[0]; }
579  T height() const { return this->maxCorner[1] - this->minCorner[1]; }
580 
582 
590  std::list<Rect<T,2>> operator-(const Rect<T,2>& other) const
591  {
592  if(!this->isValid())
593  return std::list<Rect<T,2>>();
594 
595  if(!other.isValid())
596  return std::list<Rect<T,2>>( {*this} );
597 
598 // if (this->disjoint(other)) // unfortunately, "touching" (intersections of width or
599  // height = 0) is considered intersecting by the boost
600  // geometry base (particularly irritating with T = int)
601  Rect<T,2> inter = *this & other;
602  if ((inter.width() <= 0) || (inter.height() <= 0))
603  return std::list<Rect<T,2>>( {*this} );
604 
605  if (other.contains(*this))
606  return std::list<Rect<T,2>>();
607 
608  std::list<Rect<T,2>> result;
609 
610  PointType tl(this->x0(), this->y1()); // this top left
611  PointType br(this->x1(), this->y0()); // this bottom right
612  const PointType& bl = this->minCorner; // this bottom left
613  const PointType& tr = this->maxCorner; // this top right
614 
615  PointType otl(other.x0(), other.y1()); // other top left
616  PointType obr(other.x1(), other.y0()); // other bottom right
617  const PointType& obl = other.minCorner; // other bottom left
618  const PointType& otr = other.maxCorner; // other top right
619 
620  Rect<T,2> rtl = Rect<T,2>(tl, otr) & *this;
621  Rect<T,2> rbl = Rect<T,2>(bl, otl) & *this;
622  Rect<T,2> rbr = Rect<T,2>(br, obl) & *this;
623  Rect<T,2> rtr = Rect<T,2>(tr, obr) & *this;
624 
625  if ((rtl.width() > 0) && (rtl.height() > 0)) result.push_back(rtl);
626  if ((rbl.width() > 0) && (rbl.height() > 0)) result.push_back(rbl);
627  if ((rbr.width() > 0) && (rbr.height() > 0)) result.push_back(rbr);
628  if ((rtr.width() > 0) && (rtr.height() > 0)) result.push_back(rtr);
629 
630  return result;
631  }
632 };
633 
635 
641 template<typename T>
642 class Rect<T,3> : public RectBase<T,3, Rect<T,3> >
643 {
644 public:
646  typedef typename Base::PointType PointType;
647  typedef typename Base::SizeType SizeType;
648  typedef typename Base::BoxType BoxType;
649 
650 public:
653 
654  Rect() {}
655 
664  Rect(T x, T y, T z, T width, T height, T depth) :
665  Base(x, y, z, width, height, depth) {}
666 
673  Rect(const PointType& pos, T width, T height, T depth) :
674  Base(pos, width, height, depth) {}
675 
680  Rect(const PointType& pos, const SizeType& s) :
681  Base(pos, s) {}
682 
684  explicit Rect(const BoxType& box) :
685  Base(box) {}
686 
690  Rect(const PointType& p1, const PointType& p2,
691  bool makeValid = true) :
692  Base(p1, p2, makeValid) {}
693 
695 
696 public:
699 
701  T& x0() { return this->minCorner[0]; }
703  T x0() const { return this->minCorner[0]; }
704 
706  T& y0() { return this->minCorner[1]; }
708  T y0() const { return this->minCorner[1]; }
709 
711  T& z0() { return this->minCorner[2]; }
713  T z0() const { return this->minCorner[2]; }
714 
716  T& x1() { return this->maxCorner[0]; }
718  T x1() const { return this->maxCorner[0]; }
719 
721  T& y1() { return this->maxCorner[1]; }
723  T y1() const { return this->maxCorner[1]; }
724 
726  T& z1() { return this->maxCorner[2]; }
728  T z1() const { return this->maxCorner[2]; }
729 
731  T width() const { return this->maxCorner[0] - this->minCorner[0]; }
733  T height() const { return this->maxCorner[1] - this->minCorner[1]; }
735  T depth() const { return this->maxCorner[2] - this->minCorner[2]; }
737 };
738 
740 
743 
746 
749 
752 
755 
758 
760 
761 template <>
762 class IsCheapToCopy<Rect2i> : public std::true_type {};
763 
764 template <>
765 class IsCheapToCopy<Rect2f> : public std::true_type {};
766 
767 template <>
768 class IsCheapToCopy<Rect2d> : public std::true_type {};
769 
770 template <>
771 class IsCheapToCopy<Box3i> : public std::true_type {};
772 
773 template <>
774 class IsCheapToCopy<Box3f> : public std::true_type {};
775 
776 template <>
777 class IsCheapToCopy<Box3d> : public std::true_type {};
778 
780 
781 }
782 
784 // BOOST specialization on Rect to accept them as geometry entity
785 namespace boost { namespace geometry { namespace traits {
786 
788 
789 template <typename T, int D, typename Derived>
790 struct tag<mira::RectBase<T,D, Derived> > { typedef box_tag type; };
791 
792 template <typename T, int D, typename Derived>
793 struct point_type<mira::RectBase<T,D, Derived> > { typedef mira::Point<T,D> type; };
794 
795 template <typename T, int D, std::size_t Dimension, typename Derived>
796 struct indexed_access<mira::RectBase<T,D, Derived>, min_corner, Dimension>
797 {
798  typedef typename geometry::coordinate_type<mira::Point<T,D> >::type coordinate_type;
799  static inline coordinate_type get(mira::RectBase<T,D,Derived> const& b) {
800  return geometry::get<Dimension>(b.minCorner);
801  }
802  static inline void set(mira::RectBase<T,D,Derived>& b, coordinate_type const& value) {
803  geometry::set<Dimension>(b.minCorner, value);
804  }
805 };
806 
807 template <typename T, int D, std::size_t Dimension, typename Derived>
808 struct indexed_access<mira::RectBase<T,D, Derived>, max_corner, Dimension>
809 {
810  typedef typename geometry::coordinate_type<mira::Point<T,D>>::type coordinate_type;
811  static inline coordinate_type get(mira::RectBase<T,D, Derived> const& b) {
812  return geometry::get<Dimension>(b.maxCorner);
813  }
814  static inline void set(mira::RectBase<T,D, Derived>& b, coordinate_type const& value) {
815  geometry::set<Dimension>(b.maxCorner, value);
816  }
817 };
818 
819 template <typename T, int D>
820 struct tag<mira::Rect<T,D> > : public tag<mira::RectBase<T,D, mira::Rect<T,D>>> {};
821 
822 template <typename T, int D>
823 struct point_type<mira::Rect<T,D> > : public point_type<mira::RectBase<T,D,mira::Rect<T,D>>> {};
824 
825 template <typename T, int D, std::size_t Dimension>
826 struct indexed_access<mira::Rect<T,D>, min_corner, Dimension> :
827  public indexed_access<mira::RectBase<T,D,mira::Rect<T,D>>, min_corner, Dimension> {};
828 
829 template <typename T, int D, std::size_t Dimension>
830 struct indexed_access<mira::Rect<T,D>, max_corner, Dimension> :
831  public indexed_access<mira::RectBase<T,D,mira::Rect<T,D>>, max_corner, Dimension> {};
832 
834 
835 }}}
837 
839 
840 #endif
Rect class for defining rectangles.
Definition: Rect.h:453
Rect< int, 3 > Box3i
A 3D box with integer precision.
Definition: Rect.h:751
Derived operator|(const Derived &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: Rect.h:294
T & y0()
Returns the y-coordinate of the lower corner.
Definition: Rect.h:706
T y0() const
Returns the y-coordinate of the lower corner.
Definition: Rect.h:708
A class for a n-dimensional line.
Rect< int, 2 > Rect2i
A 2D rect with integer precision.
Definition: Rect.h:742
Definition: SyncTimedRead.h:62
static Derived zero()
Same as null().
Definition: Rect.h:276
RectBase(const BoxType &box)
Creating an n-dimensional object from boost::model::box.
Definition: Rect.h:113
Derived operator &(const Derived &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: Rect.h:379
RectBase< T, D, Rect< T, D > > Base
Definition: Rect.h:456
const Derived & operator &=(const Derived &other)
Intersects the rectangle with the given rectangle.
Definition: Rect.h:398
T depth() const
Returns the depth.
Definition: Rect.h:735
General point class template.
Definition: Point.h:135
RectBase< T, 3, Rect< T, 3 > > Base
Definition: Rect.h:645
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Base::PointType PointType
Definition: Rect.h:457
RectBase(const PointType &pos, T width, T height)
A constructor for the 2D case.
Definition: Rect.h:100
T & y1()
Returns the y-coordinate of the upper corner.
Definition: Rect.h:721
Rect(const PointType &pos, T width, T height, T depth)
a constructor to create a 3D rect
Definition: Rect.h:673
Rect< float, 3 > Box3f
A 3D box with floating point precision.
Definition: Rect.h:754
bool isValid() const
Returns true if this is a valid Rect where the maxCorner&#39;s components are not smaller than the minCor...
Definition: Rect.h:215
T & y0()
Returns the y-coordinate of the lower corner.
Definition: Rect.h:562
Derived normalized() const
Returns the normalized Rect, where the maxCorner and minCorner components are swapped if necessary to...
Definition: Rect.h:235
RectBase(const PointType &p1, const PointType &p2, bool makeValid)
Create an n-dimensional object from specifying two corners.
Definition: Rect.h:123
T & z0()
Returns the z-coordinate of the lower corner.
Definition: Rect.h:711
Rect< float, 2 > Rect2f
A 2D rect with floating point precision.
Definition: Rect.h:745
PointType minCorner
Definition: Rect.h:441
T width() const
Returns the width.
Definition: Rect.h:731
boost::geometry::model::box< PointType > BoxType
Definition: Rect.h:76
Rect(const PointType &pos, T width, T height)
A constructor to create a 2D rect.
Definition: Rect.h:510
Point< T, D > PointType
Definition: Rect.h:74
Rect(const PointType &pos, const SizeType &s)
A constructor to create a 2D rect.
Definition: Rect.h:518
Base::PointType PointType
Definition: Rect.h:483
T & y1()
Returns the y-coordinate of the upper corner.
Definition: Rect.h:572
Rect(const cv::Rect_< T > &rect)
copy constructor from OpenCV rect
Definition: Rect.h:526
T & x1()
Returns the x-coordinate of the upper corner.
Definition: Rect.h:567
RectBase< T, 2, Rect< T, 2 > > Base
Definition: Rect.h:482
Rect()
the default constructor
Definition: Rect.h:654
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
const Derived & operator+=(const PointType &displacement)
Moves the rect (the minCorner and the maxCorner) by the specified displacement.
Definition: Rect.h:425
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
a constructor to create a 3D rect
Definition: Rect.h:690
RectBase(T x, T y, T width, T height)
A constructor for the 2D case.
Definition: Rect.h:96
T x0() const
Returns the x-coordinate of the lower corner.
Definition: Rect.h:559
T width() const
Returns the width.
Definition: Rect.h:577
bool isNull() const
Returns true, if all extends (i.e.
Definition: Rect.h:255
Rect(const BoxType &box)
copy constructor from boost::BoxType
Definition: Rect.h:684
Type trait to define if a class is cheap to copy.
T x1() const
Returns the x-coordinate of the upper corner.
Definition: Rect.h:718
T z1() const
Returns the z-coordinate of the upper corner.
Definition: Rect.h:728
static Derived invalid()
Returns an invalid rect with negative extends.
Definition: Rect.h:226
Rect< double, 2 > Rect2d
A 2D rect with 64 bit floating point precision.
Definition: Rect.h:748
Base::SizeType SizeType
Definition: Rect.h:647
Size< T, D > SizeType
Definition: Rect.h:75
T y1() const
Returns the y-coordinate of the upper corner.
Definition: Rect.h:574
RectBase(const PointType &pos, T width, T height, T depth)
A constructor for the 3D case.
Definition: Rect.h:104
Base::PointType PointType
Definition: Rect.h:646
PointType maxCorner
Definition: Rect.h:442
Rect(const PointType &pos, const SizeType &s)
a constructor to create a 3D rect
Definition: Rect.h:680
Base::BoxType BoxType
Definition: Rect.h:485
Base::BoxType BoxType
Definition: Rect.h:459
This class provides templatized multidimensional sizes for multidimensional geometric objects...
T & x1()
Returns the x-coordinate of the upper corner.
Definition: Rect.h:716
Rect()
The default constructor.
Definition: Rect.h:492
T height() const
Returns the height.
Definition: Rect.h:733
T & x0()
Returns the x-coordinate of the lower corner.
Definition: Rect.h:557
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
A constructor to create a 2D rect.
Definition: Rect.h:534
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
A constructor to initialize from 2 points.
Definition: Rect.h:466
static Derived null()
Returns a null-Rect which extends are null (minCorner and maxCorner) are set to 0.
Definition: Rect.h:266
RectBase(const PointType &pos, const SizeType &s)
a constructor to construct the rect, cube or whatever by defining the lower corner and specifying an ...
Definition: Rect.h:109
T & z1()
Returns the z-coordinate of the upper corner.
Definition: Rect.h:726
T x0() const
Returns the x-coordinate of the lower corner.
Definition: Rect.h:703
Base::SizeType SizeType
Definition: Rect.h:484
bool operator==(const RectBase< T, D, OtherDerived > &other) const
Definition: Rect.h:171
void reflect(Reflector &reflector)
the method to serialize this object
Definition: Rect.h:143
Rect(const BoxType &box)
copy constructor from boost::BoxType
Definition: Rect.h:522
RectBase()
The default constructor, creates an invalid rect with negative extends.
Definition: Rect.h:83
T y1() const
Returns the y-coordinate of the upper corner.
Definition: Rect.h:723
T x1() const
Returns the x-coordinate of the upper corner.
Definition: Rect.h:569
Base::BoxType BoxType
Definition: Rect.h:648
T y0() const
Returns the y-coordinate of the lower corner.
Definition: Rect.h:564
bool disjoint(const OtherGeometry &otherGeometry) const
this method checks for non-intersections with other geometry
Definition: Rect.h:200
Rect(T x, T y, T width, T height)
A constructor to create a 2D rect.
Definition: Rect.h:501
Size class for defining sizes with different data types.
Definition: Size.h:69
Rect< double, 3 > Box3d
A 3D box with 64 bit floating point precision.
Definition: Rect.h:757
Base::SizeType SizeType
Definition: Rect.h:458
static Derived convertFrom(const RectBase< U, D, OtherDerived > &other)
Converts from a Rect of a different type.
Definition: Rect.h:417
T height() const
Returns the height.
Definition: Rect.h:579
Rect(T x, T y, T z, T width, T height, T depth)
a constructor to create a 3D rect
Definition: Rect.h:664
SizeType size() const
return the size of the multidimensional rect
Definition: Rect.h:162
bool contains(const OtherGeometry &otherGeometry) const
this method checks if a given geometry is enclosed by this box
Definition: Rect.h:188
RectBase(T x, T y, T z, T width, T height, T depth)
A constructor for the 3D case.
Definition: Rect.h:92
The base class for rectangles.
Definition: Rect.h:71
T z0() const
Returns the z-coordinate of the lower corner.
Definition: Rect.h:713
bool intersects(const OtherGeometry &otherGeometry) const
this method checks for intersections with other geometry
Definition: Rect.h:194
bool operator!=(const RectBase< T, D, OtherDerived > &other) const
Definition: Rect.h:176
T & x0()
Returns the x-coordinate of the lower corner.
Definition: Rect.h:701
const Derived & operator|=(const PointType &p)
Unites this rectangle with the given point.
Definition: Rect.h:352
std::list< Rect< T, 2 > > operator-(const Rect< T, 2 > &other) const
Intersects the rectangle with the inverse of the given rectangle, i.e.
Definition: Rect.h:590
Rect()
The default constructor.
Definition: Rect.h:463
const Derived & operator|=(const Derived &other)
Unites this rectangle with the given rectangle.
Definition: Rect.h:317
Specialization for 2D.
Definition: Rect.h:479
Derived operator+(const PointType &displacement) const
Returns a rect that is moved by the specified displacement.
Definition: Rect.h:435