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 <boost/geometry/algorithms/intersects.hpp>
51 #include <boost/geometry/algorithms/within.hpp>
52 #include <boost/geometry/geometries/box.hpp>
53 
54 #include <geometry/Line.h>
55 #include <geometry/Size.h>
56 
57 #include <utils/IsCheapToCopy.h>
58 
59 namespace mira
60 {
61 
63 
74 template<typename T, int D, typename Derived>
75 class RectBase
76 {
77 public:
80  typedef boost::geometry::model::box<PointType> BoxType;
81 
82 public:
85 
88  {
89  for(int d=0; d<D; ++d) {
90  minCorner[d] = 0;
91  maxCorner[d] = -1;
92  }
93  }
94 
96  RectBase(T x, T y, T z, T width, T height, T depth) :
97  minCorner(x, y, z), maxCorner(x+width, y+height, z+depth) {}
98 
100  RectBase(T x, T y, T width, T height) :
101  minCorner(x, y), maxCorner(x+width, y+height) {}
102 
104  explicit RectBase(const PointType& pos, T width, T height) :
105  minCorner(pos), maxCorner(pos.x()+width, pos.y()+height) {}
106 
108  explicit RectBase(const PointType& pos, T width, T height, T depth) :
109  minCorner(pos), maxCorner(pos.x()+width, pos.y()+height, pos.z()+depth) {}
110 
113  explicit RectBase(const PointType& pos, const SizeType& s) :
114  minCorner(pos), maxCorner(pos+s) {}
115 
117  explicit RectBase(const BoxType& box) :
118  minCorner(box.min_corner()), maxCorner(box.max_corner()) {}
119 
127  explicit RectBase(const PointType& p1, const PointType& p2,
128  bool makeValid)
129  {
130  for(int d=0; d<D; ++d)
131  {
132  if(makeValid && (p1[d]>p2[d])) {
133  minCorner[d]=p2[d];
134  maxCorner[d]=p1[d];
135  } else {
136  minCorner[d]=p1[d];
137  maxCorner[d]=p2[d];
138  }
139  }
140  }
141 
143 
144 public:
146  template<typename Reflector>
147  void reflect(Reflector& reflector)
148  {
149  reflector.property("MinCorner", minCorner, "The minimum corner");
150  reflector.property("MaxCorner", maxCorner, "The maximum corner");
151  }
152 
153 public:
156 
158  operator BoxType() const {
159  return BoxType(minCorner, maxCorner);
160  }
161 
163 
164 public:
166  SizeType size() const {
167  return SizeType(maxCorner-minCorner);
168  }
169 
170 public:
173 
174  template <typename OtherDerived>
175  bool operator==(const RectBase<T,D, OtherDerived>& other) const {
176  return minCorner == other.minCorner && maxCorner == other.maxCorner;
177  }
178 
179  template <typename OtherDerived>
180  bool operator!=(const RectBase<T,D, OtherDerived>& other) const {
181  return !this->operator==(other);
182  }
183 
185 
186 public:
189 
191  template <typename OtherGeometry>
192  bool contains(const OtherGeometry& otherGeometry) const {
193  return boost::geometry::within(otherGeometry, *this);
194  }
195 
197  template <typename OtherGeometry>
198  bool intersects(const OtherGeometry& otherGeometry) const {
199  return boost::geometry::intersects(otherGeometry, *this);
200  }
201 
203  template <typename OtherGeometry>
204  bool disjoint(const OtherGeometry& otherGeometry) const {
205  return boost::geometry::disjoint(otherGeometry, *this);
206  }
207 
209 
210 public:
213 
219  bool isValid() const {
220  for(int d=0; d<D; ++d)
221  if(maxCorner[d]<minCorner[d])
222  return false;
223  return true;
224  }
225 
230  static Derived invalid() {
231  return Derived();
232  }
233 
239  Derived normalized() const
240  {
241  Derived r;
242  for(int d=0; d<D; ++d)
243  {
244  if(maxCorner[d]<minCorner[d]) {
245  r.maxCorner[d] = minCorner[d];
246  r.minCorner[d] = maxCorner[d];
247  } else {
248  r.maxCorner[d] = maxCorner[d];
249  r.minCorner[d] = minCorner[d];
250  }
251  }
252  return r;
253  }
254 
259  bool isNull() const {
260  for(int d=0; d<D; ++d)
261  if(maxCorner[d]!=minCorner[d])
262  return false;
263  return true;
264  }
265 
270  static Derived null() {
271  Derived r;
273  r.maxCorner = Eigen::Matrix<T,D,1>::Zero(D,1);
274  return r;
275  }
276 
280  static Derived zero() {
281  return null();
282  }
284 
285 public:
288 
298  Derived operator|(const Derived& other) const
299  {
300  if(!this->isValid())
301  return other;
302  if(!other.isValid())
303  return *((Derived*)this); // we are of type Derived
304 
305  Derived r;
306  for(int d=0; d<D; ++d) {
307  r.minCorner[d] = std::min(minCorner[d], other.minCorner[d]);
308  r.maxCorner[d] = std::max(maxCorner[d], other.maxCorner[d]);
309  }
310  return r;
311  }
312 
321  const Derived& operator|=(const Derived& other)
322  {
323  if(!isValid()) {
324  *this = other;
325  } else if(other.isValid()) {
326  for(int d=0; d<D; ++d) {
327  if(other.minCorner[d]<minCorner[d])
328  minCorner[d] = other.minCorner[d];
329  if(other.maxCorner[d]>maxCorner[d])
330  maxCorner[d] = other.maxCorner[d];
331  }
332  }
333  return *((Derived*)this); // we are of type Derived
334  }
335 
356  const Derived& operator|=(const PointType& p)
357  {
358  if(!isValid()) {
359  minCorner = p;
360  maxCorner = p;
361  } else {
362  for(int d=0; d<D; ++d) {
363  if(p[d]<minCorner[d])
364  minCorner[d] = p[d];
365  if(p[d]>maxCorner[d])
366  maxCorner[d] = p[d];
367  }
368  }
369  return *((Derived*)this); // we are of type Derived
370  }
371 
383  Derived operator&(const Derived& other) const
384  {
385  if(!isValid())
386  return invalid();
387  if(!other.isValid())
388  return invalid();
389 
390  Derived r;
391  for(int d=0; d<D; ++d) {
392  r.minCorner[d] = std::max(minCorner[d], other.minCorner[d]);
393  r.maxCorner[d] = std::min(maxCorner[d], other.maxCorner[d]);
394  }
395  return r;
396  }
397 
402  const Derived& operator&=(const Derived& other)
403  {
404  if(!isValid())
405  return *((Derived*)this);
406 
407  if(!other.isValid()) {
408  *this = other;
409  } else {
410  for(int d=0; d<D; ++d) {
411  minCorner[d] = std::max(minCorner[d], other.minCorner[d]);
412  maxCorner[d] = std::min(maxCorner[d], other.maxCorner[d]);
413  }
414  }
415  return *((Derived*)this);
416  }
418 
420  template<typename U, typename OtherDerived>
421  static Derived convertFrom(const RectBase<U,D, OtherDerived>& other) {
422  return Derived(PointType(other.minCorner.template cast<T>()),
423  PointType(other.maxCorner.template cast<T>()));
424  }
425 
429  const Derived& operator+=(const PointType& displacement)
430  {
431  minCorner+=displacement;
432  maxCorner+=displacement;
433  return *((Derived*)this);
434  }
435 
439  Derived operator+(const PointType& displacement) const
440  {
441  return Derived((PointType)(minCorner+displacement), (PointType)(maxCorner+displacement));
442  }
443 
444 public:
447 };
448 
450 
456 template<typename T, int D>
457 class Rect : public RectBase<T,D, Rect<T,D> >
458 {
459 public:
461  typedef typename Base::PointType PointType;
462  typedef typename Base::SizeType SizeType;
463  typedef typename Base::BoxType BoxType;
464 
465 public:
467  Rect() {}
468 
470  Rect(const PointType& p1, const PointType& p2,
471  bool makeValid = true) :
472  Base(p1, p2, makeValid) {}
473 };
474 
476 
482 template<typename T>
483 class Rect<T,2> : public RectBase<T,2, Rect<T,2> >
484 {
485 public:
487  typedef typename Base::PointType PointType;
488  typedef typename Base::SizeType SizeType;
489  typedef typename Base::BoxType BoxType;
490 
491 public:
494 
496  Rect() {}
497 
505  Rect(T x, T y, T width, T height) :
506  Base(x, y, width, height) {}
507 
514  Rect(const PointType& pos, T width, T height) :
515  Base(pos, width, height) {}
516 
522  Rect(const PointType& pos, const SizeType& s) :
523  Base(pos, s) {}
524 
526  explicit Rect(const BoxType& box) :
527  Base(box) {}
528 
530  explicit Rect(const cv::Rect_<T>& rect) :
531  Base(rect.x, rect.y, rect.width, rect.height) {}
532 
538  Rect(const PointType& p1, const PointType& p2,
539  bool makeValid = true) :
540  Base(p1, p2, makeValid) {}
541 
543 
544 public:
547 
549  operator cv::Rect_<T>() const
550  {
551  return cv::Rect_<T>(Base::minCorner, Base::size());
552  }
553 
555 
556 public:
559 
561  T& x0() { return this->minCorner[0]; }
563  T x0() const { return this->minCorner[0]; }
564 
566  T& y0() { return this->minCorner[1]; }
568  T y0() const { return this->minCorner[1]; }
569 
571  T& x1() { return this->maxCorner[0]; }
573  T x1() const { return this->maxCorner[0]; }
574 
576  T& y1() { return this->maxCorner[1]; }
578  T y1() const { return this->maxCorner[1]; }
579 
581  T width() const { return this->maxCorner[0] - this->minCorner[0]; }
583  T height() const { return this->maxCorner[1] - this->minCorner[1]; }
584 
586 
594  std::list<Rect<T,2>> operator-(const Rect<T,2>& other) const
595  {
596  if(!this->isValid())
597  return std::list<Rect<T,2>>();
598 
599  if(!other.isValid())
600  return std::list<Rect<T,2>>( {*this} );
601 
602 // if (this->disjoint(other)) // unfortunately, "touching" (intersections of width or
603  // height = 0) is considered intersecting by the boost
604  // geometry base (particularly irritating with T = int)
605  Rect<T,2> inter = *this & other;
606  if ((inter.width() <= 0) || (inter.height() <= 0))
607  return std::list<Rect<T,2>>( {*this} );
608 
609  if (other.contains(*this))
610  return std::list<Rect<T,2>>();
611 
612  std::list<Rect<T,2>> result;
613 
614  PointType tl(this->x0(), this->y1()); // this top left
615  PointType br(this->x1(), this->y0()); // this bottom right
616  const PointType& bl = this->minCorner; // this bottom left
617  const PointType& tr = this->maxCorner; // this top right
618 
619  PointType otl(other.x0(), other.y1()); // other top left
620  PointType obr(other.x1(), other.y0()); // other bottom right
621  const PointType& obl = other.minCorner; // other bottom left
622  const PointType& otr = other.maxCorner; // other top right
623 
624  Rect<T,2> rtl = Rect<T,2>(tl, otr) & *this;
625  Rect<T,2> rbl = Rect<T,2>(bl, otl) & *this;
626  Rect<T,2> rbr = Rect<T,2>(br, obl) & *this;
627  Rect<T,2> rtr = Rect<T,2>(tr, obr) & *this;
628 
629  if ((rtl.width() > 0) && (rtl.height() > 0)) result.push_back(rtl);
630  if ((rbl.width() > 0) && (rbl.height() > 0)) result.push_back(rbl);
631  if ((rbr.width() > 0) && (rbr.height() > 0)) result.push_back(rbr);
632  if ((rtr.width() > 0) && (rtr.height() > 0)) result.push_back(rtr);
633 
634  return result;
635  }
636 };
637 
639 
645 template<typename T>
646 class Rect<T,3> : public RectBase<T,3, Rect<T,3> >
647 {
648 public:
650  typedef typename Base::PointType PointType;
651  typedef typename Base::SizeType SizeType;
652  typedef typename Base::BoxType BoxType;
653 
654 public:
657 
658  Rect() {}
659 
668  Rect(T x, T y, T z, T width, T height, T depth) :
669  Base(x, y, z, width, height, depth) {}
670 
677  Rect(const PointType& pos, T width, T height, T depth) :
678  Base(pos, width, height, depth) {}
679 
684  Rect(const PointType& pos, const SizeType& s) :
685  Base(pos, s) {}
686 
688  explicit Rect(const BoxType& box) :
689  Base(box) {}
690 
694  Rect(const PointType& p1, const PointType& p2,
695  bool makeValid = true) :
696  Base(p1, p2, makeValid) {}
697 
699 
700 public:
703 
705  T& x0() { return this->minCorner[0]; }
707  T x0() const { return this->minCorner[0]; }
708 
710  T& y0() { return this->minCorner[1]; }
712  T y0() const { return this->minCorner[1]; }
713 
715  T& z0() { return this->minCorner[2]; }
717  T z0() const { return this->minCorner[2]; }
718 
720  T& x1() { return this->maxCorner[0]; }
722  T x1() const { return this->maxCorner[0]; }
723 
725  T& y1() { return this->maxCorner[1]; }
727  T y1() const { return this->maxCorner[1]; }
728 
730  T& z1() { return this->maxCorner[2]; }
732  T z1() const { return this->maxCorner[2]; }
733 
735  T width() const { return this->maxCorner[0] - this->minCorner[0]; }
737  T height() const { return this->maxCorner[1] - this->minCorner[1]; }
739  T depth() const { return this->maxCorner[2] - this->minCorner[2]; }
741 };
742 
744 
747 
750 
753 
756 
759 
762 
764 
765 template <>
766 class IsCheapToCopy<Rect2i> : public std::true_type {};
767 
768 template <>
769 class IsCheapToCopy<Rect2f> : public std::true_type {};
770 
771 template <>
772 class IsCheapToCopy<Rect2d> : public std::true_type {};
773 
774 template <>
775 class IsCheapToCopy<Box3i> : public std::true_type {};
776 
777 template <>
778 class IsCheapToCopy<Box3f> : public std::true_type {};
779 
780 template <>
781 class IsCheapToCopy<Box3d> : public std::true_type {};
782 
784 
785 }
786 
788 // BOOST specialization on Rect to accept them as geometry entity
789 namespace boost { namespace geometry { namespace traits {
790 
792 
793 template <typename T, int D, typename Derived>
794 struct tag<mira::RectBase<T,D, Derived> > { typedef box_tag type; };
795 
796 template <typename T, int D, typename Derived>
797 struct point_type<mira::RectBase<T,D, Derived> > { typedef mira::Point<T,D> type; };
798 
799 template <typename T, int D, std::size_t Dimension, typename Derived>
800 struct indexed_access<mira::RectBase<T,D, Derived>, min_corner, Dimension>
801 {
802  typedef typename geometry::coordinate_type<mira::Point<T,D> >::type coordinate_type;
803  static inline coordinate_type get(mira::RectBase<T,D,Derived> const& b) {
804  return geometry::get<Dimension>(b.minCorner);
805  }
806  static inline void set(mira::RectBase<T,D,Derived>& b, coordinate_type const& value) {
807  geometry::set<Dimension>(b.minCorner, value);
808  }
809 };
810 
811 template <typename T, int D, std::size_t Dimension, typename Derived>
812 struct indexed_access<mira::RectBase<T,D, Derived>, max_corner, Dimension>
813 {
814  typedef typename geometry::coordinate_type<mira::Point<T,D>>::type coordinate_type;
815  static inline coordinate_type get(mira::RectBase<T,D, Derived> const& b) {
816  return geometry::get<Dimension>(b.maxCorner);
817  }
818  static inline void set(mira::RectBase<T,D, Derived>& b, coordinate_type const& value) {
819  geometry::set<Dimension>(b.maxCorner, value);
820  }
821 };
822 
823 template <typename T, int D>
824 struct tag<mira::Rect<T,D> > : public tag<mira::RectBase<T,D, mira::Rect<T,D>>> {};
825 
826 template <typename T, int D>
827 struct point_type<mira::Rect<T,D> > : public point_type<mira::RectBase<T,D,mira::Rect<T,D>>> {};
828 
829 template <typename T, int D, std::size_t Dimension>
830 struct indexed_access<mira::Rect<T,D>, min_corner, Dimension> :
831  public indexed_access<mira::RectBase<T,D,mira::Rect<T,D>>, min_corner, Dimension> {};
832 
833 template <typename T, int D, std::size_t Dimension>
834 struct indexed_access<mira::Rect<T,D>, max_corner, Dimension> :
835  public indexed_access<mira::RectBase<T,D,mira::Rect<T,D>>, max_corner, Dimension> {};
836 
838 
839 }}}
841 
843 
844 #endif
Rect class for defining rectangles.
Definition: Rect.h:457
Rect< int, 3 > Box3i
A 3D box with integer precision.
Definition: Rect.h:755
Derived operator|(const Derived &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: Rect.h:298
T & y0()
Returns the y-coordinate of the lower corner.
Definition: Rect.h:710
T y0() const
Returns the y-coordinate of the lower corner.
Definition: Rect.h:712
A class for a n-dimensional line.
Rect< int, 2 > Rect2i
A 2D rect with integer precision.
Definition: Rect.h:746
Definition: SyncTimedRead.h:62
static Derived zero()
Same as null().
Definition: Rect.h:280
RectBase(const BoxType &box)
Creating an n-dimensional object from boost::model::box.
Definition: Rect.h:117
Derived operator &(const Derived &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: Rect.h:383
RectBase< T, D, Rect< T, D > > Base
Definition: Rect.h:460
const Derived & operator &=(const Derived &other)
Intersects the rectangle with the given rectangle.
Definition: Rect.h:402
T depth() const
Returns the depth.
Definition: Rect.h:739
General point class template.
Definition: Point.h:140
RectBase< T, 3, Rect< T, 3 > > Base
Definition: Rect.h:649
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Base::PointType PointType
Definition: Rect.h:461
RectBase(const PointType &pos, T width, T height)
A constructor for the 2D case.
Definition: Rect.h:104
T & y1()
Returns the y-coordinate of the upper corner.
Definition: Rect.h:725
Rect(const PointType &pos, T width, T height, T depth)
a constructor to create a 3D rect
Definition: Rect.h:677
Rect< float, 3 > Box3f
A 3D box with floating point precision.
Definition: Rect.h:758
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:219
T & y0()
Returns the y-coordinate of the lower corner.
Definition: Rect.h:566
Derived normalized() const
Returns the normalized Rect, where the maxCorner and minCorner components are swapped if necessary to...
Definition: Rect.h:239
RectBase(const PointType &p1, const PointType &p2, bool makeValid)
Create an n-dimensional object from specifying two corners.
Definition: Rect.h:127
T & z0()
Returns the z-coordinate of the lower corner.
Definition: Rect.h:715
Rect< float, 2 > Rect2f
A 2D rect with floating point precision.
Definition: Rect.h:749
PointType minCorner
Definition: Rect.h:445
T width() const
Returns the width.
Definition: Rect.h:735
boost::geometry::model::box< PointType > BoxType
Definition: Rect.h:80
Rect(const PointType &pos, T width, T height)
A constructor to create a 2D rect.
Definition: Rect.h:514
Point< T, D > PointType
Definition: Rect.h:78
Rect(const PointType &pos, const SizeType &s)
A constructor to create a 2D rect.
Definition: Rect.h:522
Base::PointType PointType
Definition: Rect.h:487
T & y1()
Returns the y-coordinate of the upper corner.
Definition: Rect.h:576
Rect(const cv::Rect_< T > &rect)
copy constructor from OpenCV rect
Definition: Rect.h:530
T & x1()
Returns the x-coordinate of the upper corner.
Definition: Rect.h:571
RectBase< T, 2, Rect< T, 2 > > Base
Definition: Rect.h:486
Rect()
the default constructor
Definition: Rect.h:658
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:429
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
a constructor to create a 3D rect
Definition: Rect.h:694
RectBase(T x, T y, T width, T height)
A constructor for the 2D case.
Definition: Rect.h:100
T x0() const
Returns the x-coordinate of the lower corner.
Definition: Rect.h:563
T width() const
Returns the width.
Definition: Rect.h:581
bool isNull() const
Returns true, if all extends (i.e.
Definition: Rect.h:259
Rect(const BoxType &box)
copy constructor from boost::BoxType
Definition: Rect.h:688
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:722
T z1() const
Returns the z-coordinate of the upper corner.
Definition: Rect.h:732
static Derived invalid()
Returns an invalid rect with negative extends.
Definition: Rect.h:230
Rect< double, 2 > Rect2d
A 2D rect with 64 bit floating point precision.
Definition: Rect.h:752
Base::SizeType SizeType
Definition: Rect.h:651
Size< T, D > SizeType
Definition: Rect.h:79
T y1() const
Returns the y-coordinate of the upper corner.
Definition: Rect.h:578
RectBase(const PointType &pos, T width, T height, T depth)
A constructor for the 3D case.
Definition: Rect.h:108
Base::PointType PointType
Definition: Rect.h:650
PointType maxCorner
Definition: Rect.h:446
Rect(const PointType &pos, const SizeType &s)
a constructor to create a 3D rect
Definition: Rect.h:684
Base::BoxType BoxType
Definition: Rect.h:489
Base::BoxType BoxType
Definition: Rect.h:463
This class provides templatized multidimensional sizes for multidimensional geometric objects...
T & x1()
Returns the x-coordinate of the upper corner.
Definition: Rect.h:720
Rect()
The default constructor.
Definition: Rect.h:496
T height() const
Returns the height.
Definition: Rect.h:737
T & x0()
Returns the x-coordinate of the lower corner.
Definition: Rect.h:561
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
A constructor to create a 2D rect.
Definition: Rect.h:538
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
A constructor to initialize from 2 points.
Definition: Rect.h:470
static Derived null()
Returns a null-Rect which extends are null (minCorner and maxCorner) are set to 0.
Definition: Rect.h:270
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:113
T & z1()
Returns the z-coordinate of the upper corner.
Definition: Rect.h:730
T x0() const
Returns the x-coordinate of the lower corner.
Definition: Rect.h:707
Base::SizeType SizeType
Definition: Rect.h:488
bool operator==(const RectBase< T, D, OtherDerived > &other) const
Definition: Rect.h:175
void reflect(Reflector &reflector)
the method to serialize this object
Definition: Rect.h:147
Rect(const BoxType &box)
copy constructor from boost::BoxType
Definition: Rect.h:526
RectBase()
The default constructor, creates an invalid rect with negative extends.
Definition: Rect.h:87
T y1() const
Returns the y-coordinate of the upper corner.
Definition: Rect.h:727
T x1() const
Returns the x-coordinate of the upper corner.
Definition: Rect.h:573
Base::BoxType BoxType
Definition: Rect.h:652
T y0() const
Returns the y-coordinate of the lower corner.
Definition: Rect.h:568
bool disjoint(const OtherGeometry &otherGeometry) const
this method checks for non-intersections with other geometry
Definition: Rect.h:204
Rect(T x, T y, T width, T height)
A constructor to create a 2D rect.
Definition: Rect.h:505
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:761
Base::SizeType SizeType
Definition: Rect.h:462
static Derived convertFrom(const RectBase< U, D, OtherDerived > &other)
Converts from a Rect of a different type.
Definition: Rect.h:421
T height() const
Returns the height.
Definition: Rect.h:583
Rect(T x, T y, T z, T width, T height, T depth)
a constructor to create a 3D rect
Definition: Rect.h:668
SizeType size() const
return the size of the multidimensional rect
Definition: Rect.h:166
bool contains(const OtherGeometry &otherGeometry) const
this method checks if a given geometry is enclosed by this box
Definition: Rect.h:192
RectBase(T x, T y, T z, T width, T height, T depth)
A constructor for the 3D case.
Definition: Rect.h:96
The base class for rectangles.
Definition: Rect.h:75
T z0() const
Returns the z-coordinate of the lower corner.
Definition: Rect.h:717
bool intersects(const OtherGeometry &otherGeometry) const
this method checks for intersections with other geometry
Definition: Rect.h:198
bool operator!=(const RectBase< T, D, OtherDerived > &other) const
Definition: Rect.h:180
T & x0()
Returns the x-coordinate of the lower corner.
Definition: Rect.h:705
const Derived & operator|=(const PointType &p)
Unites this rectangle with the given point.
Definition: Rect.h:356
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:594
Rect()
The default constructor.
Definition: Rect.h:467
const Derived & operator|=(const Derived &other)
Unites this rectangle with the given rectangle.
Definition: Rect.h:321
Specialization for 2D.
Definition: Rect.h:483
Derived operator+(const PointType &displacement) const
Returns a rect that is moved by the specified displacement.
Definition: Rect.h:439