PCL
Rectangle.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.16
6 // ----------------------------------------------------------------------------
7 // pcl/Rectangle.h - Released 2019-09-29T12:27:26Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Rectangle_h
53 #define __PCL_Rectangle_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/Flags.h>
60 #include <pcl/Math.h>
61 #include <pcl/Point.h>
62 #include <pcl/Relational.h>
63 
64 #ifdef __PCL_QT_INTERFACE
65 # include <QtCore/QRect>
66 # ifndef __PCL_QT_NO_RECT_DRAWING_HELPERS
67 # include <QtGui/QPainter>
68 # include <QtGui/QBrush>
69 # endif
70 #endif
71 
72 namespace pcl
73 {
74 
75 // ----------------------------------------------------------------------------
76 
90 namespace Clip
91 {
92  enum mask_type
93  {
94  Left = 0x01, // Clipped at the left side
95  Top = 0x02, // Clipped at the top side
96  Right = 0x04, // Clipped at the right side
97  Bottom = 0x08 // Clipped at the bottom side
98  };
99 }
100 
105 
106 // ----------------------------------------------------------------------------
107 
123 template <typename T> inline
124 bool IsPoint( T x0, T y0, T x1, T y1 )
125 {
126  return x0 == x1 && y0 == y1;
127 }
128 
141 template <typename T> inline
142 bool IsLine( T x0, T y0, T x1, T y1 )
143 {
144  return ((x0 == x1) ^ (y0 == y1)) != 0;
145 }
146 
158 template <typename T> inline
159 bool IsHorizontalLine( T x0, T y0, T x1, T y1 )
160 {
161  return y0 == y1 && x0 != x1;
162 }
163 
175 template <typename T> inline
176 bool IsVerticalLine( T x0, T y0, T x1, T y1 )
177 {
178  return x0 == x1 && y0 != y1;
179 }
180 
192 template <typename T> inline
193 bool IsPointOrLine( T x0, T y0, T x1, T y1 )
194 {
195  return x0 == x1 || y0 == y1;
196 }
197 
209 template <typename T> inline
210 bool IsRect( T x0, T y0, T x1, T y1 )
211 {
212  return x0 != x1 && y0 != y1;
213 }
214 
225 template <typename T> inline
226 bool IsNormalRect( T x0, T y0, T x1, T y1 )
227 {
228  return x0 < x1 && y0 < y1;
229 }
230 
242 template <typename T> inline
243 bool IsOrderedRect( T x0, T y0, T x1, T y1 )
244 {
245  return x0 <= x1 && y0 <= y1;
246 }
247 
259 template <typename T> inline
260 void OrderRect( T& x0, T& y0, T& x1, T& y1 )
261 {
262  if ( x1 < x0 )
263  pcl::Swap( x0, x1 );
264  if ( y1 < y0 )
265  pcl::Swap( y0, y1 );
266 }
267 
268 // ----------------------------------------------------------------------------
269 
270 /*
271  * ### NB: Template class GenericRectangle cannot have virtual member
272  * functions. This is because internal PCL and Core routines rely on
273  * GenericRectangle<int>, GenericRectangle<float> and
274  * GenericRectangle<double> to be directly castable to int*, float* and
275  * double*, respectively. See also the PCL_ASSERT_RECT_SIZE() macro.
276  */
277 
278 #define PCL_ASSERT_RECT_SIZE() \
279  static_assert( sizeof( *this ) == 4*sizeof( T ), "Invalid sizeof( GenericRectangle<> )" )
280 
312 template <typename T>
313 class PCL_CLASS GenericRectangle
314 {
315 public:
316 
320  typedef T component;
321 
326 
327  /*
328  * Rectangle coordinates: x0=left, y0=top, x1=right, y1=bottom.
329  * The x1 (right) and y1 (bottom) coordinates are excluded from the
330  * rectangular area, so we always have: width=x1-x0 and height=y1-y0.
331  */
332  component x0;
333  component y0;
334  component x1;
335  component y1;
336 
341  constexpr GenericRectangle()
342  {
343  PCL_ASSERT_RECT_SIZE();
344  }
345 
356  template <typename T1>
357  constexpr GenericRectangle( T1 left, T1 top, T1 right, T1 bottom ) :
358  x0( component( left ) ), y0( component( top ) ),
359  x1( component( right ) ), y1( component( bottom ) )
360  {
361  PCL_ASSERT_RECT_SIZE();
362  }
363 
389  template <typename T1>
390  GenericRectangle( std::initializer_list<T1> l )
391  {
392  PCL_ASSERT_RECT_SIZE();
393  switch ( l.size() )
394  {
395  default:
396  case 4: y1 = component( l.begin()[3] );
397  case 3: x1 = component( l.begin()[2] );
398  case 2: y0 = component( l.begin()[1] );
399  case 1: x0 = component( l.begin()[0] );
400  case 0: break;
401  }
402  switch ( l.size() )
403  {
404  case 0: x0 = component( 0 );
405  case 1: y0 = component( 0 );
406  case 2: x1 = component( 0 );
407  case 3: y1 = component( 0 );
408  default:
409  case 4: break;
410  }
411  }
412 
422  template <typename T1>
423  GenericRectangle( const pcl::GenericPoint<T1>& leftTop, const pcl::GenericPoint<T1>& rightBottom ) :
424  GenericRectangle( component( leftTop.x ), component( leftTop.y ),
425  component( rightBottom.x ), component( rightBottom.y ) )
426  {
427  PCL_ASSERT_RECT_SIZE();
428  }
429 
438  constexpr GenericRectangle( component width, component height ) :
439  GenericRectangle( component( 0 ), component( 0 ), width, height )
440  {
441  PCL_ASSERT_RECT_SIZE();
442  }
443 
451  constexpr GenericRectangle( component d ) :
452  GenericRectangle( d, d, d, d )
453  {
454  PCL_ASSERT_RECT_SIZE();
455  }
456 
461  template <typename T1>
463  GenericRectangle( component( r.x0 ), component( r.y0 ),
464  component( r.x1 ), component( r.y1 ) )
465  {
466  PCL_ASSERT_RECT_SIZE();
467  }
468 
469 #ifdef __PCL_QT_INTERFACE
470  GenericRectangle( const QRect& r ) :
471  GenericRectangle( component( r.left() ), component( r.top() ),
472  component( r.right()+1 ), component( r.bottom()+1 ) )
473  {
474  PCL_ASSERT_RECT_SIZE();
475  }
476 
477  GenericRectangle( const QPoint& p0, const QPoint& p1 ) :
478  GenericRectangle( component( p0.x() ), component( p0.y() ),
479  component( p1.x() ), component( p1.y() ) )
480  {
481  PCL_ASSERT_RECT_SIZE();
482  }
483 #endif
484 
489  component Left() const
490  {
491  return x0;
492  }
493 
498  component Top() const
499  {
500  return y0;
501  }
502 
507  component Right() const
508  {
509  return x1;
510  }
511 
516  component Bottom() const
517  {
518  return y1;
519  }
520 
525  point LeftTop() const
526  {
527  return point( pcl::Min( x0, x1 ), pcl::Min( y0, y1 ) );
528  }
529 
533  point TopLeft() const
534  {
535  return LeftTop();
536  }
537 
542  point RightTop() const
543  {
544  return point( pcl::Max( x0, x1 ), pcl::Min( y0, y1 ) );
545  }
546 
550  point TopRight() const
551  {
552  return RightTop();
553  }
554 
559  point LeftBottom() const
560  {
561  return point( pcl::Min( x0, x1 ), pcl::Max( y0, y1 ) );
562  }
563 
567  point BottomLeft() const
568  {
569  return LeftBottom();
570  }
571 
576  point RightBottom() const
577  {
578  return point( pcl::Max( x0, x1 ), pcl::Max( y0, y1 ) );
579  }
580 
584  point BottomRight() const
585  {
586  return RightBottom();
587  }
588 
592  point Center() const
593  {
594  return point( (x0 + x1)/2, (y0 + y1)/2 );
595  }
596 
600  point CenterTop() const
601  {
602  return point( (x0 + x1)/2, pcl::Min( y0, y1 ) );
603  }
604 
608  point CenterBottom() const
609  {
610  return point( (x0 + x1)/2, pcl::Min( y0, y1 ) );
611  }
612 
616  point CenterLeft() const
617  {
618  return point( pcl::Min( x0, x1 ), (y0 + y1)/2 );
619  }
620 
624  point CenterRight() const
625  {
626  return point( pcl::Min( x0, x1 ), (y0 + y1)/2 );
627  }
628 
633  component Width() const
634  {
635  return pcl::Abs( x1 - x0 );
636  }
637 
642  component Height() const
643  {
644  return pcl::Abs( y1 - y0 );
645  }
646 
651  component Perimeter() const
652  {
653  component w = Width(), h = Height();
654  return w+w+h+h;
655  }
656 
663  component ManhattanDistance() const
664  {
665  return Width() + Height();
666  }
667 
672  component Area() const
673  {
674  return pcl::Abs( (x1 - x0)*(y1 - y0) );
675  }
676 
681  double CenterX() const
682  {
683  return 0.5*(x0 + x1);
684  }
685 
690  double CenterY() const
691  {
692  return 0.5*(y0 + y1);
693  }
694 
701  double Hypot() const
702  {
703  double w = x1 - x0, h = y1 - y0;
704  return w*w + h*h;
705  }
706 
711  double Diagonal() const
712  {
713  return pcl::Sqrt( Hypot() );
714  }
715 
719  bool IsPoint() const
720  {
721  return pcl::IsPoint( x0, y0, x1, y1 );
722  }
723 
727  bool IsLine() const
728  {
729  return pcl::IsLine( x0, y0, x1, y1 );
730  }
731 
735  bool IsHorizontalLine() const
736  {
737  return pcl::IsHorizontalLine( x0, y0, x1, y1 );
738  }
739 
743  bool IsVerticalLine() const
744  {
745  return pcl::IsVerticalLine( x0, y0, x1, y1 );
746  }
747 
751  bool IsPointOrLine() const
752  {
753  return pcl::IsPointOrLine( x0, y0, x1, y1 );
754  }
755 
760  bool IsRect() const
761  {
762  return pcl::IsRect( x0, y0, x1, y1 );
763  }
764 
768  bool IsNormal() const
769  {
770  return pcl::IsNormalRect( x0, y0, x1, y1 );
771  }
772 
776  bool IsOrdered() const
777  {
778  return pcl::IsOrderedRect( x0, y0, x1, y1 );
779  }
780 
784  void Order()
785  {
786  pcl::OrderRect( x0, y0, x1, y1 );
787  }
788 
793  {
794  GenericRectangle r = *this;
795  r.Order();
796  return r;
797  }
798 
807  template <typename T1>
808  ClipFlags ClipCode( T1 x, T1 y ) const
809  {
810  ClipFlags clip; // defaults to zero
811 
812  if ( x0 <= x1 )
813  {
814  if ( x < x0 ) clip |= Clip::Left;
815  if ( x > x1 ) clip |= Clip::Right;
816  }
817  else
818  {
819  if ( x < x1 ) clip |= Clip::Left;
820  if ( x > x0 ) clip |= Clip::Right;
821  }
822 
823  if ( y0 <= y1 )
824  {
825  if ( y < y0 ) clip |= Clip::Top;
826  if ( y > y1 ) clip |= Clip::Bottom;
827  }
828  else
829  {
830  if ( y < y1 ) clip |= Clip::Top;
831  if ( y > y0 ) clip |= Clip::Bottom;
832  }
833 
834  return clip;
835  }
836 
844  template <typename T1>
845  ClipFlags ClipCode( const pcl::GenericPoint<T1>& p ) const
846  {
847  return ClipCode( p.x, p.y );
848  }
849 
854  template <typename T1>
855  bool Includes( T1 x, T1 y ) const
856  {
857  return ((x0 < x1) ? (x >= x0 && x <= x1) : (x >= x1 && x <= x0)) &&
858  ((y0 < y1) ? (y >= y0 && y <= y1) : (y >= y1 && y <= y0));
859  }
860 
864  template <typename T1>
865  bool Includes( const pcl::GenericPoint<T1>& p ) const
866  {
867  return Includes( p.x, p.y );
868  }
869 
873  template <typename T1>
874  bool Includes( const GenericRectangle<T1>& r ) const
875  {
876  return Includes( r.x0, r.y0 ) && Includes( r.x1, r.y1 );
877  }
878 
879 #ifdef __PCL_QT_INTERFACE
880  bool Includes( const QPoint& p ) const
881  {
882  return Includes( p.x(), p.y() );
883  }
884 
885  bool Includes( const QRect& r ) const
886  {
887  return Includes( r.left(), r.top() ) && Includes( r.right()+1, r.bottom()+1 );
888  }
889 #endif
890 
899  template <typename T1>
900  bool IncludesFast( T1 x, T1 y ) const
901  {
902  return x >= x0 && y >= y0 && x <= x1 && y <= y1;
903  }
904 
912  template <typename T1>
913  bool IncludesFast( const pcl::GenericPoint<T1>& p ) const
914  {
915  return IncludesFast( p.x, p.y );
916  }
917 
928  template <typename T1>
929  bool Intersects( T1 left, T1 top, T1 right, T1 bottom ) const
930  {
931  OrderRect( left, top, right, bottom );
932  return ((x0 < x1) ? (right >= x0 && left <= x1) : (right >= x1 && left <= x0)) &&
933  ((y0 < y1) ? (bottom >= y0 && top <= y1) : (bottom >= y1 && top <= y0));
934  }
935 
939  template <typename T1>
940  bool Intersects( const pcl::GenericRectangle<T1>& r ) const
941  {
942  return Intersects( r.x0, r.y0, r.x1, r.y1 );
943  }
944 
945 #ifdef __PCL_QT_INTERFACE
946  bool Intersects( const QRect& r ) const
947  {
948  return Intersects( r.left(), r.top(), r.right()+1, r.bottom()+1 );
949  }
950 #endif
951 
971  template <typename T1>
972  bool IntersectsFast( T1 left, T1 top, T1 right, T1 bottom ) const
973  {
974  return right >= x0 && left <= x1 && bottom >= y0 && top <= y1;
975  }
976 
983  template <typename T1>
985  {
986  return IntersectsFast( r.x0, r.y0, r.x1, r.y1 );
987  }
988 
993  template <typename T1>
994  void Unite( const GenericRectangle<T1>& r )
995  {
996  Unite( r.x0, r.y0, r.x1, r.y1 );
997  }
998 
1009  template <typename T1>
1010  void Unite( T1 left, T1 top, T1 right, T1 bottom )
1011  {
1012  x0 = pcl::Min( x0, component( left ) );
1013  y0 = pcl::Min( y0, component( top ) );
1014  x1 = pcl::Max( x1, component( right ) );
1015  y1 = pcl::Max( y1, component( bottom ) );
1016  }
1017 
1021  template <typename T1>
1023  {
1024  GenericRectangle r1 = *this;
1025  r1.Unite( r );
1026  return r1;
1027  }
1028 
1033  template <typename T1>
1034  GenericRectangle& operator |=( const GenericRectangle<T1>& r )
1035  {
1036  Unite( r );
1037  return *this;
1038  }
1039 
1040 #ifdef __PCL_QT_INTERFACE
1041  void Unite( const QRect& r )
1042  {
1043  Unite( r.left(), r.top(), r.right()+1, r.bottom()+1 );
1044  }
1045 
1046  GenericRectangle Union( const QRect& r ) const
1047  {
1048  GenericRectangle r1 = *this;
1049  r1.Unite( r );
1050  return r1;
1051  }
1052 
1053  GenericRectangle& operator |=( const QRect& r )
1054  {
1055  Unite( r );
1056  return *this;
1057  }
1058 #endif
1059 
1064  template <typename T1>
1066  {
1067  return Intersect( r.x0, r.y0, r.x1, r.y1 );
1068  }
1069 
1080  template <typename T1>
1081  bool Intersect( T1 left, T1 top, T1 right, T1 bottom )
1082  {
1083  x0 = pcl::Max( x0, component( left ) );
1084  y0 = pcl::Max( y0, component( top ) );
1085  x1 = pcl::Min( x1, component( right ) );
1086  y1 = pcl::Min( y1, component( bottom ) );
1087  return IsNormal();
1088  }
1089 
1094  template <typename T1>
1096  {
1097  GenericRectangle r1 = *this;
1098  (void)r1.Intersect( r );
1099  return r1;
1100  }
1101 
1106  template <typename T1>
1107  GenericRectangle& operator &=( const GenericRectangle<T1>& r )
1108  {
1109  Intersect( r );
1110  return *this;
1111  }
1112 
1113 #ifdef __PCL_QT_INTERFACE
1114  bool Intersect( const QRect& r )
1115  {
1116  return Intersect( r.left(), r.top(), r.right()+1, r.bottom()+1 );
1117  }
1118 
1119  GenericRectangle Intersection( const QRect& r ) const
1120  {
1121  GenericRectangle r1 = *this;
1122  (void)r1.Intersect( r );
1123  return r1;
1124  }
1125 
1126  GenericRectangle& operator &=( const QRect& r )
1127  {
1128  Intersect( r );
1129  return *this;
1130  }
1131 #endif
1132 
1139  template <typename T1>
1140  void Set( T1 left, T1 top, T1 right, T1 bottom )
1141  {
1142  x0 = component( left );
1143  y0 = component( top );
1144  x1 = component( right );
1145  y1 = component( bottom );
1146  }
1147 
1155  template <typename T1>
1157  {
1158  MoveTo( p.x, p.y );
1159  }
1160 
1168  template <typename T1>
1169  void MoveTo( T1 x, T1 y )
1170  {
1171  component dx = x1 - x0, dy = y1 - y0;
1172  x0 = component( x );
1173  y0 = component( y );
1174  x1 = x0 + dx;
1175  y1 = y0 + dy;
1176  }
1177 
1178 #ifdef __PCL_QT_INTERFACE
1179  void MoveTo( const QPoint& p )
1180  {
1181  MoveTo( p.x(), p.y() );
1182  }
1183 #endif
1184 
1191  template <typename T1>
1193  {
1194  GenericRectangle r( *this );
1195  r.MoveTo( p );
1196  return r;
1197  }
1198 
1205  template <typename T1>
1206  GenericRectangle MovedTo( T1 x, T1 y ) const
1207  {
1208  GenericRectangle r( *this );
1209  r.MoveTo( x, y );
1210  return r;
1211  }
1212 
1217  template <typename T1>
1219  {
1220  MoveBy( d.x, d.y );
1221  }
1222 
1228  template <typename T1>
1229  void MoveBy( T1 dx, T1 dy )
1230  {
1231  x0 += component( dx );
1232  y0 += component( dy );
1233  x1 += component( dx );
1234  y1 += component( dy );
1235  }
1236 
1246  template <typename T1>
1247  void MoveBy( T1 dxy )
1248  {
1249  x0 += component( dxy );
1250  y0 += component( dxy );
1251  x1 += component( dxy );
1252  y1 += component( dxy );
1253  }
1254 
1255 #ifdef __PCL_QT_INTERFACE
1256  void MoveBy( const QPoint& p )
1257  {
1258  MoveBy( p.x(), p.y() );
1259  }
1260 #endif
1261 
1268  template <typename T1>
1270  {
1271  GenericRectangle r( *this );
1272  r.MoveBy( d );
1273  return r;
1274  }
1275 
1282  template <typename T1>
1283  GenericRectangle MovedBy( T1 dx, T1 dy ) const
1284  {
1285  GenericRectangle r( *this );
1286  r.MoveBy( dx, dy );
1287  return r;
1288  }
1289 
1300  template <typename T1>
1301  void ResizeTo( T1 w, T1 h )
1302  {
1303  if ( x0 <= x1 )
1304  x1 = x0 + component( w );
1305  else
1306  x0 = x1 + component( w );
1307 
1308  if ( y0 <= y1 )
1309  y1 = y0 + component( h );
1310  else
1311  y0 = y1 + component( h );
1312  }
1313 
1320  template <typename T1>
1321  GenericRectangle ResizedTo( T1 w, T1 h ) const
1322  {
1323  GenericRectangle r( *this );
1324  r.ResizeTo( w, h );
1325  return r;
1326  }
1327 
1339  template <typename T1>
1340  void ResizeBy( T1 dw, T1 dh )
1341  {
1342  if ( x0 <= x1 )
1343  x1 += component( dw );
1344  else
1345  x0 += component( dw );
1346 
1347  if ( y0 <= y1 )
1348  y1 += component( dh );
1349  else
1350  y0 += component( dh );
1351  }
1352 
1359  template <typename T1>
1360  GenericRectangle ResizedBy( T1 dw, T1 dh ) const
1361  {
1362  GenericRectangle r( *this );
1363  r.ResizeBy( dw, dh );
1364  return r;
1365  }
1366 
1375  template <typename T1>
1376  void SetWidth( T1 w )
1377  {
1378  if ( x0 <= x1 )
1379  x1 = x0 + component( w );
1380  else
1381  x0 = x1 + component( w );
1382  }
1383 
1392  template <typename T1>
1393  void SetHeight( T1 h )
1394  {
1395  if ( y0 <= y1 )
1396  y1 = y0 + component( h );
1397  else
1398  y0 = y1 + component( h );
1399  }
1400 
1406  template <typename T1>
1407  void InflateBy( T1 dx, T1 dy )
1408  {
1409  if ( x1 < x0 )
1410  dx = -dx;
1411  if ( y1 < y0 )
1412  dy = -dy;
1413  x0 -= dx;
1414  y0 -= dy;
1415  x1 += dx;
1416  y1 += dy;
1417  }
1418 
1424  template <typename T1>
1425  void InflateBy( T1 d )
1426  {
1427  if ( x0 <= x1 )
1428  x0 -= d, x1 += d;
1429  else
1430  x0 += d, x1 -= d;
1431 
1432  if ( y0 <= y1 )
1433  y0 -= d, y1 += d;
1434  else
1435  y0 += d, y1 -= d;
1436  }
1437 
1442  template <typename T1>
1443  GenericRectangle InflatedBy( T1 dx, T1 dy ) const
1444  {
1445  GenericRectangle r( *this );
1446  r.InflateBy( dx, dy );
1447  return r;
1448  }
1449 
1454  template <typename T1>
1456  {
1457  GenericRectangle r( *this );
1458  r.InflateBy( d );
1459  return r;
1460  }
1461 
1467  template <typename T1>
1468  void DeflateBy( T1 dx, T1 dy )
1469  {
1470  if ( x1 < x0 )
1471  dx = -dx;
1472  if ( y1 < y0 )
1473  dy = -dy;
1474  x0 += dx;
1475  y0 += dy;
1476  x1 -= dx;
1477  y1 -= dy;
1478  }
1479 
1485  template <typename T1>
1486  void DeflateBy( T1 d )
1487  {
1488  if ( x0 <= x1 )
1489  x0 += d, x1 -= d;
1490  else
1491  x0 -= d, x1 += d;
1492 
1493  if ( y0 <= y1 )
1494  y0 += d, y1 -= d;
1495  else
1496  y0 -= d, y1 += d;
1497  }
1498 
1503  template <typename T1>
1504  GenericRectangle DeflatedBy( T1 dx, T1 dy ) const
1505  {
1506  GenericRectangle r( *this );
1507  r.DeflateBy( dx, dy );
1508  return r;
1509  }
1510 
1515  template <typename T1>
1517  {
1518  GenericRectangle r( *this );
1519  r.DeflateBy( d );
1520  return r;
1521  }
1522 
1529  template <typename T1>
1531  {
1532  GenericRectangle r( *this );
1533  r.SetWidth( w );
1534  return r;
1535  }
1536 
1543  template <typename T1>
1545  {
1546  GenericRectangle r( *this );
1547  r.SetHeight( h );
1548  return r;
1549  }
1550 
1556  template <typename T1, typename T2>
1557  void Rotate( T1 angle, T2 xc, T2 yc )
1558  {
1559  T1 sa, ca; pcl::SinCos( angle, sa, ca );
1560  pcl::Rotate( x0, y0, sa, ca, xc, yc );
1561  pcl::Rotate( x1, y1, sa, ca, xc, yc );
1562  }
1563 
1568  template <typename T1, typename T2>
1569  void Rotate( T1 angle, const GenericPoint<T2>& center )
1570  {
1571  Rotate( angle, center.x, center.y );
1572  }
1573 
1579  template <typename T1, typename T2>
1580  void Rotate( T1 sa, T1 ca, T2 xc, T2 yc )
1581  {
1582  pcl::Rotate( x0, y0, sa, ca, xc, yc );
1583  pcl::Rotate( x1, y1, sa, ca, xc, yc );
1584  }
1585 
1591  template <typename T1, typename T2>
1592  void Rotate( T1 sa, T1 ca, const GenericPoint<T2>& center )
1593  {
1594  Rotate( sa, ca, center.x, center.y );
1595  }
1596 
1602  template <typename T1, typename T2>
1603  GenericRectangle Rotated( T1 angle, T2 xc, T2 yc ) const
1604  {
1605  GenericRectangle r( *this );
1606  r.Rotate( angle, xc, yc );
1607  return r;
1608  }
1609 
1615  template <typename T1, typename T2>
1616  GenericRectangle Rotated( T1 angle, const GenericPoint<T2>& center ) const
1617  {
1618  GenericRectangle r( *this );
1619  r.Rotate( angle, center );
1620  return r;
1621  }
1622 
1629  template <typename T1, typename T2>
1630  GenericRectangle Rotated( T1 sa, T1 ca, T2 xc, T2 yc ) const
1631  {
1632  GenericRectangle r( *this );
1633  r.Rotate( sa, ca, xc, yc );
1634  return r;
1635  }
1636 
1643  template <typename T1, typename T2>
1644  GenericRectangle Rotated( T1 sa, T1 ca, const GenericPoint<T2>& center ) const
1645  {
1646  GenericRectangle r( *this );
1647  r.Rotate( sa, ca, center );
1648  return r;
1649  }
1650 
1655  void Round()
1656  {
1657  x0 = component( pcl::Round( double( x0 ) ) );
1658  y0 = component( pcl::Round( double( y0 ) ) );
1659  x1 = component( pcl::Round( double( x1 ) ) );
1660  y1 = component( pcl::Round( double( y1 ) ) );
1661  }
1662 
1667  void Round( int n )
1668  {
1669  PCL_PRECONDITION( n >= 0 )
1670  if ( n < 0 )
1671  n = 0;
1672  x0 = component( pcl::Round( double( x0 ), n ) );
1673  y0 = component( pcl::Round( double( y0 ), n ) );
1674  x1 = component( pcl::Round( double( x1 ), n ) );
1675  y1 = component( pcl::Round( double( y1 ), n ) );
1676  }
1677 
1683  {
1684  return GenericRectangle( component( pcl::Round( double( x0 ) ) ), component( pcl::Round( double( y0 ) ) ),
1685  component( pcl::Round( double( x1 ) ) ), component( pcl::Round( double( y1 ) ) ) );
1686  }
1687 
1692  GenericRectangle Rounded( int n ) const
1693  {
1694  PCL_PRECONDITION( n >= 0 )
1695  return GenericRectangle( component( pcl::Round( double( x0 ), n ) ), component( pcl::Round( double( y0 ), n ) ),
1696  component( pcl::Round( double( x1 ), n ) ), component( pcl::Round( double( y1 ), n ) ) );
1697  }
1698 
1704  {
1705  return GenericRectangle<int>( pcl::RoundInt( double( x0 ) ), pcl::RoundInt( double( y0 ) ),
1706  pcl::RoundInt( double( x1 ) ), pcl::RoundInt( double( y1 ) ) );
1707  }
1708 
1714  void Truncate()
1715  {
1716  x0 = component( pcl::Trunc( double( x0 ) ) );
1717  y0 = component( pcl::Trunc( double( y0 ) ) );
1718  x1 = component( pcl::Trunc( double( x1 ) ) );
1719  y1 = component( pcl::Trunc( double( y1 ) ) );
1720  }
1721 
1729  {
1730  return GenericRectangle( component( pcl::Trunc( double( x0 ) ) ), component( pcl::Trunc( double( y0 ) ) ),
1731  component( pcl::Trunc( double( x1 ) ) ), component( pcl::Trunc( double( y1 ) ) ) );
1732  }
1733 
1741  {
1742  return GenericRectangle<int>( pcl::TruncInt( double( x0 ) ), pcl::TruncInt( double( y0 ) ),
1743  pcl::TruncInt( double( x1 ) ), pcl::TruncInt( double( y1 ) ) );
1744  }
1745 
1750  template <typename T1>
1751  GenericRectangle& operator =( const GenericRectangle<T1>& r )
1752  {
1753  x0 = component( r.x0 );
1754  y0 = component( r.y0 );
1755  x1 = component( r.x1 );
1756  y1 = component( r.y1 );
1757  return *this;
1758  }
1759 
1767  template <typename T1>
1768  GenericRectangle& operator =( const pcl::GenericPoint<T1>& p )
1769  {
1770  x0 = x1 = component( p.x );
1771  y0 = y1 = component( p.y );
1772  return *this;
1773  }
1774 
1781  GenericRectangle& operator =( component d )
1782  {
1783  x0 = y0 = x1 = y1 = d;
1784  return *this;
1785  }
1786 
1787 #ifdef __PCL_QT_INTERFACE
1788  GenericRectangle& operator =( const QRect& r )
1789  {
1790  x0 = component( r.left() );
1791  y0 = component( r.top() );
1792  x1 = component( r.right()+1 );
1793  y1 = component( r.bottom()+1 );
1794  return *this;
1795  }
1796 #endif
1797 
1810  template <typename T1>
1811  GenericRectangle& operator +=( const GenericRectangle<T1>& r )
1812  {
1813  x0 += component( r.x0 );
1814  y0 += component( r.y0 );
1815  x1 += component( r.x1 );
1816  y1 += component( r.y1 );
1817  return *this;
1818  }
1819 
1833  template <typename T1>
1834  GenericRectangle& operator +=( const pcl::GenericPoint<T1>& p )
1835  {
1836  x0 += component( p.x );
1837  y0 += component( p.y );
1838  x1 += component( p.x );
1839  y1 += component( p.y );
1840  return *this;
1841  }
1842 
1857  GenericRectangle& operator +=( component d )
1858  {
1859  x0 += d;
1860  y0 += d;
1861  x1 += d;
1862  y1 += d;
1863  return *this;
1864  }
1865 
1866 #ifdef __PCL_QT_INTERFACE
1867  GenericRectangle& operator +=( const QPoint& p )
1868  {
1869  component dx = component( p.x() ), dy = component( p.y() );
1870  x0 += dx;
1871  y0 += dy;
1872  x1 += dx;
1873  y1 += dy;
1874  return *this;
1875  }
1876 #endif
1877 
1890  template <typename T1>
1891  GenericRectangle& operator -=( const GenericRectangle<T1>& r )
1892  {
1893  x0 -= component( r.x0 );
1894  y0 -= component( r.y0 );
1895  x1 -= component( r.x1 );
1896  y1 -= component( r.y1 );
1897  return *this;
1898  }
1899 
1913  template <typename T1>
1914  GenericRectangle& operator -=( const pcl::GenericPoint<T1>& p )
1915  {
1916  x0 -= component( p.x );
1917  y0 -= component( p.y );
1918  x1 -= component( p.x );
1919  y1 -= component( p.y );
1920  return *this;
1921  }
1922 
1937  GenericRectangle& operator -=( component d )
1938  {
1939  x0 -= d;
1940  y0 -= d;
1941  x1 -= d;
1942  y1 -= d;
1943  return *this;
1944  }
1945 
1946 #ifdef __PCL_QT_INTERFACE
1947  GenericRectangle& operator -=( const QPoint& p )
1948  {
1949  component dx = component( p.x() ), dy = component( p.y() );
1950  x0 -= dx;
1951  y0 -= dy;
1952  x1 -= dx;
1953  y1 -= dy;
1954  return *this;
1955  }
1956 #endif
1957 
1970  template <typename T1>
1971  GenericRectangle& operator *=( const GenericRectangle<T1>& r )
1972  {
1973  x0 *= component( r.x0 );
1974  y0 *= component( r.y0 );
1975  x1 *= component( r.x1 );
1976  y1 *= component( r.y1 );
1977  return *this;
1978  }
1979 
1994  template <typename T1>
1995  GenericRectangle& operator *=( const pcl::GenericPoint<T1>& p )
1996  {
1997  x0 *= component( p.x );
1998  y0 *= component( p.y );
1999  x1 *= component( p.x );
2000  y1 *= component( p.y );
2001  return *this;
2002  }
2003 
2018  GenericRectangle& operator *=( component d )
2019  {
2020  x0 *= d;
2021  y0 *= d;
2022  x1 *= d;
2023  y1 *= d;
2024  return *this;
2025  }
2026 
2027 #ifdef __PCL_QT_INTERFACE
2028  GenericRectangle& operator *=( const QPoint& p )
2029  {
2030  component dx = component( p.x() ), dy = component( p.y() );
2031  x0 *= dx; y0 *= dy; x1 *= dx; y1 *= dy;
2032  return *this;
2033  }
2034 #endif
2035 
2048  template <typename T1>
2049  GenericRectangle& operator /=( const GenericRectangle<T1>& r )
2050  {
2051  PCL_PRECONDITION( component( r.x0 ) != component( 0 ) && component( r.y0 ) != component( 0 ) &&
2052  component( r.x1 ) != component( 0 ) && component( r.y1 ) != component( 0 ) )
2053  x0 /= component( r.x0 );
2054  y0 /= component( r.y0 );
2055  x1 /= component( r.x1 );
2056  y1 /= component( r.y1 );
2057  return *this;
2058  }
2059 
2074  template <typename T1>
2075  GenericRectangle& operator /=( const pcl::GenericPoint<T1>& p )
2076  {
2077  PCL_PRECONDITION( component( p.x ) != component( 0 ) && component( p.y ) != component( 0 ) )
2078  x0 /= component( p.x );
2079  y0 /= component( p.y );
2080  x1 /= component( p.x );
2081  y1 /= component( p.y );
2082  return *this;
2083  }
2084 
2099  GenericRectangle& operator /=( component d )
2100  {
2101  PCL_PRECONDITION( d != component( 0 ) )
2102  x0 /= d; y0 /= d; x1 /= d; y1 /= d;
2103  return *this;
2104  }
2105 
2106 #ifdef __PCL_QT_INTERFACE
2107  GenericRectangle& operator /=( const QPoint& p )
2108  {
2109  PCL_PRECONDITION( component( p.x() ) != component( 0 ) && component( p.y() ) != component( 0 ) )
2110  component dx = component( p.x() ), dy = component( p.y() );
2111  x0 /= dx;
2112  y0 /= dy;
2113  x1 /= dx;
2114  y1 /= dy;
2115  return *this;
2116  }
2117 #endif
2118 
2123  {
2124  return *this;
2125  }
2126 
2134  {
2135  return GenericRectangle( -x0, -y0, -x1, -y1 );
2136  }
2137 
2138 #ifdef __PCL_QT_INTERFACE
2139  operator QRect() const
2140  {
2141  return QRect( int( x0 ), int( y0 ), int( x1-x0 ), int( y1-y0 ) );
2142  }
2143 #endif
2144 
2145 #ifdef __PCL_QT_INTERFACE
2146 # ifndef __PCL_QT_NO_RECT_DRAWING_HELPERS
2147 
2148  void Draw( QPainter& p, const QBrush* b ) const
2149  {
2150  int rx0, ry0, rx1, ry1;
2151 
2152  if ( x0 <= x1 )
2153  rx0 = x0, rx1 = x1;
2154  else
2155  rx0 = x1, rx1 = x0;
2156 
2157  if ( y0 <= y1 )
2158  ry0 = y0, ry1 = y1;
2159  else
2160  ry0 = y1, ry1 = y0;
2161 
2162  if ( rx1 - rx0 <= 1 )
2163  {
2164  if ( ry1 - ry0 <= 1 )
2165  p.drawPoint( rx0, ry0 );
2166  else
2167  p.drawLine( rx0, ry0, rx0, ry1-1 );
2168  }
2169  else if ( ry1 - ry0 <= 1 )
2170  {
2171  p.drawLine( rx0, ry0, rx1-1, ry0 );
2172  }
2173  else
2174  {
2175 # if ( QT_VERSION >= 0x040000 )
2176  int w = rx1-rx0-1, h = ry1-ry0-1;
2177 # else
2178  int w = rx1-rx0, h = ry1-ry0;
2179 # endif
2180  if ( b != 0 )
2181  p.fillRect( rx0, ry0, w, h, *b );
2182  p.drawRect( rx0, ry0, w, h );
2183  }
2184  }
2185 
2186  void Draw( QPainter& p ) const
2187  {
2188  Draw( p, 0 );
2189  }
2190 
2191  void Draw( QPainter& p, const QColor& c ) const
2192  {
2193  QBrush b( c );
2194  Draw( p, &b );
2195  }
2196 
2197 # endif // !__PCL_QT_NO_RECT_DRAWING_HELPERS
2198 #endif // __PCL_QT_INTERFACE
2199 
2200 }; // GenericRectangle<T>
2201 
2202 #undef PCL_ASSERT_RECT_SIZE
2203 
2204 // ----------------------------------------------------------------------------
2205 
2215 template <typename T1, typename T2> inline
2217 {
2218  return r1.x0 == r2.x0 && r1.y0 == r2.y0 && r1.x1 == r2.x1 && r1.y1 == r2.y1;
2219 }
2220 
2226 template <typename T> inline
2227 bool operator ==( const GenericRectangle<T>& r1, T d2 )
2228 {
2229  return r1.x0 == d2 && r1.y0 == d2 && r1.x1 == d2 && r1.y1 == d2;
2230 }
2231 
2238 template <typename T> inline
2239 bool operator ==( T d1, const GenericRectangle<T>& r2 )
2240 {
2241  return d1 == r2.x0 && d1 == r2.y0 && d1 == r2.x1 && d1 == r2.y1;
2242 }
2243 
2250 template <typename T1, typename T2> inline
2251 bool operator <( const GenericRectangle<T1>& r1, const GenericRectangle<T2>& r2 )
2252 {
2253  T1 x01 = Min( r1.x0, r1.x1 ); T1 y01 = Min( r1.y0, r1.y1 );
2254  T1 x11 = Max( r1.x0, r1.x1 ); T1 y11 = Max( r1.y0, r1.y1 );
2255  T2 x02 = Min( r2.x0, r2.x1 ); T2 y02 = Min( r2.y0, r2.y1 );
2256  T2 x12 = Max( r2.x0, r2.x1 ); T2 y12 = Max( r2.y0, r2.y1 );
2257  if ( y01 != y02 )
2258  return y01 < y02;
2259  if ( x01 != x02 )
2260  return x01 < x02;
2261  if ( y11 != y12 )
2262  return y11 < y12;
2263  return x11 < x12;
2264 }
2265 
2281 template <typename T1, typename T2> inline
2283 {
2284  return GenericRectangle<T1>( T1( r1.x0 + r2.x0 ), T1( r1.y0 + r2.y0 ),
2285  T1( r1.x1 + r2.x1 ), T1( r1.y1 + r2.y1 ) );
2286 }
2287 
2302 template <typename T1, typename T2> inline
2304 {
2305  return GenericRectangle<T1>( T1( r1.x0 + p2.x ), T1( r1.y0 + p2.y ),
2306  T1( r1.x1 + p2.x ), T1( r1.y1 + p2.y ) );
2307 }
2308 
2318 template <typename T1, typename T2> inline
2320 {
2321  return GenericRectangle<T2>( T2( p1.x + r2.x0 ), T2( p1.y + r2.y0 ),
2322  T2( p1.x + r2.x1 ), T2( p1.y + r2.y1 ) );
2323 }
2324 
2339 template <typename T> inline
2341 {
2342  return GenericRectangle<T>( r1.x0+d2, r1.y0+d2, r1.x1+d2, r1.y1+d2 );
2343 }
2344 
2354 template <typename T> inline
2356 {
2357  return GenericRectangle<T>( d1+r2.x0, d1+r2.y0, d1+r2.x1, d1+r2.y1 );
2358 }
2359 
2375 template <typename T1, typename T2> inline
2377 {
2378  return GenericRectangle<T1>( T1( r1.x0 - r2.x0 ), T1( r1.y0 - r2.y0 ),
2379  T1( r1.x1 - r2.x1 ), T1( r1.y1 - r2.y1 ) );
2380 }
2381 
2396 template <typename T1, typename T2> inline
2398 {
2399  return GenericRectangle<T1>( T1( r1.x0 - p2.x ), T1( r1.y0 - p2.y ),
2400  T1( r1.x1 - p2.x ), T1( r1.y1 - p2.y ) );
2401 }
2402 
2417 template <typename T1, typename T2> inline
2419 {
2420  return GenericRectangle<T2>( T2( p1.x - r2.x0 ), T2( p1.y - r2.y0 ),
2421  T2( p1.x - r2.x1 ), T2( p1.y - r2.y1 ) );
2422 }
2423 
2438 template <typename T> inline
2440 {
2441  return GenericRectangle<T>( r1.x0-d2, r1.y0-d2, r1.x1-d2, r1.y1-d2 );
2442 }
2443 
2458 template <typename T> inline
2460 {
2461  return GenericRectangle<T>( d1-r2.x0, d1-r2.y0, d1-r2.x1, d1-r2.y1 );
2462 }
2463 
2479 template <typename T1, typename T2> inline
2481 {
2482  return GenericRectangle<T1>( T1( r1.x0 * r2.x0 ), T1( r1.y0 * r2.y0 ),
2483  T1( r1.x1 * r2.x1 ), T1( r1.y1 * r2.y1 ) );
2484 }
2485 
2500 template <typename T1, typename T2> inline
2502 {
2503  return GenericRectangle<T1>( T1( r1.x0 * p2.x ), T1( r1.y0 * p2.y ),
2504  T1( r1.x1 * p2.x ), T1( r1.y1 * p2.y ) );
2505 }
2506 
2516 template <typename T1, typename T2> inline
2518 {
2519  return GenericRectangle<T2>( T2( p1.x * r2.x0 ), T2( p1.y * r2.y0 ),
2520  T2( p1.x * r2.x1 ), T2( p1.y * r2.y1 ) );
2521 }
2522 
2537 template <typename T> inline
2539 {
2540  return GenericRectangle<T>( r1.x0*d2, r1.y0*d2, r1.x1*d2, r1.y1*d2 );
2541 }
2542 
2552 template <typename T> inline
2554 {
2555  return GenericRectangle<T>( d1*r2.x0, d1*r2.y0, d1*r2.x1, d1*r2.y1 );
2556 }
2557 
2573 template <typename T1, typename T2> inline
2575 {
2576  PCL_PRECONDITION( r2.x0 != T2( 0 ) && r2.y0 != T2( 0 ) &&
2577  r2.x1 != T2( 0 ) && r2.y1 != T2( 0 ) )
2578  return GenericRectangle<T1>( T1( r1.x0 / r2.x0 ), T1( r1.y0 / r2.y0 ),
2579  T1( r1.x1 / r2.x1 ), T1( r1.y1 / r2.y1 ) );
2580 }
2581 
2596 template <typename T1, typename T2> inline
2598 {
2599  PCL_PRECONDITION( p2.x != T2( 0 ) && p2.y != T2( 0 ) )
2600  return GenericRectangle<T1>( T1( r1.x0 / p2.x ), T1( r1.y0 / p2.y ),
2601  T1( r1.x1 / p2.x ), T1( r1.y1 / p2.y ) );
2602 }
2603 
2618 template <typename T1, typename T2> inline
2620 {
2621  PCL_PRECONDITION( r2.x0 != T2( 0 ) && r2.y0 != T2( 0 ) &&
2622  r2.x1 != T2( 0 ) && r2.y1 != T2( 0 ) )
2623  return GenericRectangle<T2>( T2( p1.x / r2.x0 ), T2( p1.y / r2.y0 ),
2624  T2( p1.x / r2.x1 ), T2( p1.y / r2.y1 ) );
2625 }
2626 
2641 template <typename T> inline
2643 {
2644  PCL_PRECONDITION( d2 != T( 0 ) )
2645  return GenericRectangle<T>( r1.x0/d2, r1.y0/d2, r1.x1/d2, r1.y1/d2 );
2646 }
2647 
2662 template <typename T> inline
2664 {
2665  PCL_PRECONDITION( r2.x0 != T( 0 ) && r2.y0 != T( 0 ) &&
2666  r2.x1 != T( 0 ) && r2.y1 != T( 0 ) )
2667  return GenericRectangle<T>( d1/r2.x0, d1/r2.y0, d1/r2.x1, d1/r2.y1 );
2668 }
2669 
2685 template <typename T, typename T1, typename T2> inline
2686 void Rotate( GenericRectangle<T>& r, T1 a, T2 xc, T2 yc )
2687 {
2688  T1 sa, ca; pcl::SinCos( a, sa, ca );
2689  pcl::Rotate( r.x0, r.y0, sa, ca, xc, yc );
2690  pcl::Rotate( r.x1, r.y1, sa, ca, xc, yc );
2691 }
2692 
2708 template <typename T, typename T1, typename T2> inline
2709 void Rotate( GenericRectangle<T>& r, T1 a, const GenericPoint<T2>& c )
2710 {
2711  pcl::Rotate( r, a, c.x, c.y );
2712 }
2713 
2729 template <typename T, typename T1, typename T2> inline
2730 void Rotate( GenericRectangle<T>& r, T1 sa, T1 ca, T2 xc, T2 yc )
2731 {
2732  pcl::Rotate( r.x0, r.y0, sa, ca, xc, yc );
2733  pcl::Rotate( r.x1, r.y1, sa, ca, xc, yc );
2734 }
2735 
2751 template <typename T, typename T1, typename T2> inline
2752 void Rotate( GenericRectangle<T>& r, T1 sa, T1 ca, const GenericPoint<T2>& c )
2753 {
2754  pcl::Rotate( r, sa, ca, c.x, c.y );
2755 }
2756 
2768 template <typename T> inline
2770 {
2771  pcl::Swap( r1.x0, r2.x0 ); pcl::Swap( r1.y0, r2.y0 );
2772  pcl::Swap( r1.x1, r2.x1 ); pcl::Swap( r1.y1, r2.y1 );
2773 }
2774 
2775 // ----------------------------------------------------------------------------
2776 
2777 #ifndef __PCL_NO_RECT_INSTANTIATE
2778 
2791 
2800 typedef I32Rect Rect;
2801 
2810 
2819 typedef F32Rect FRect;
2820 
2829 
2838 typedef F64Rect DRect;
2839 
2840 #endif
2841 
2842 // ----------------------------------------------------------------------------
2843 
2844 } // pcl
2845 
2846 #endif // __PCL_Rectangle_h
2847 
2848 // ----------------------------------------------------------------------------
2849 // EOF pcl/Rectangle.h - Released 2019-09-29T12:27:26Z
GenericRectangle< int > RoundedToInt() const
Definition: Rectangle.h:1703
bool IncludesFast(T1 x, T1 y) const
Definition: Rectangle.h:900
bool IsVerticalLine(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:176
void MoveBy(T1 dx, T1 dy)
Definition: Rectangle.h:1229
bool Intersect(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:1081
void Unite(const GenericRectangle< T1 > &r)
Definition: Rectangle.h:994
component Area() const
Definition: Rectangle.h:672
void MoveTo(const pcl::GenericPoint< T1 > &p)
Definition: Rectangle.h:1156
GenericRectangle Union(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:1022
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:539
A generic point in the two-dimensional space.
Definition: Point.h:99
component Right() const
Definition: Rectangle.h:507
point BottomLeft() const
Definition: Rectangle.h:567
void MoveBy(T1 dxy)
Definition: Rectangle.h:1247
point BottomRight() const
Definition: Rectangle.h:584
double CenterX() const
Definition: Rectangle.h:681
void MoveTo(T1 x, T1 y)
Definition: Rectangle.h:1169
Complex< T1 > operator+(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:455
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2)
Definition: Point.h:1402
int RoundInt(T x)
Definition: Math.h:1374
bool IsLine(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:142
point TopLeft() const
Definition: Rectangle.h:533
component ManhattanDistance() const
Definition: Rectangle.h:663
void SetHeight(T1 h)
Definition: Rectangle.h:1393
PCL root namespace.
Definition: AbstractImage.h:76
GenericRectangle ResizedTo(T1 w, T1 h) const
Definition: Rectangle.h:1321
point LeftBottom() const
Definition: Rectangle.h:559
void ResizeBy(T1 dw, T1 dh)
Definition: Rectangle.h:1340
32-bit floating-point rectangle in the R^2 space.
bool IsPoint(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:124
bool IntersectsFast(const pcl::GenericRectangle< T1 > &r) const
Definition: Rectangle.h:984
A type-safe collection of enumerated flags.
Definition: Flags.h:84
GenericRectangle< int > TruncatedToInt() const
Definition: Rectangle.h:1740
GenericRectangle MovedTo(T1 x, T1 y) const
Definition: Rectangle.h:1206
GenericRectangle Rotated(T1 sa, T1 ca, const GenericPoint< T2 > &center) const
Definition: Rectangle.h:1644
Complex< T > Sqrt(const Complex< T > &c)
Definition: Complex.h:665
GenericRectangle Rotated(T1 angle, const GenericPoint< T2 > &center) const
Definition: Rectangle.h:1616
bool IsRect() const
Definition: Rectangle.h:760
bool IsVerticalLine() const
Definition: Rectangle.h:743
GenericRectangle Truncated() const
Definition: Rectangle.h:1728
Complex< T > Round(const Complex< T > &c)
Definition: Complex.h:929
void InflateBy(T1 d)
Definition: Rectangle.h:1425
component Perimeter() const
Definition: Rectangle.h:651
bool Includes(const pcl::GenericPoint< T1 > &p) const
Definition: Rectangle.h:865
bool Intersect(const GenericRectangle< T1 > &r)
Definition: Rectangle.h:1065
constexpr GenericRectangle(component d)
Definition: Rectangle.h:451
bool IsNormal() const
Definition: Rectangle.h:768
component x1
Horizontal coordinate of the lower right corner.
Definition: Rectangle.h:334
void Rotate(T1 angle, const GenericPoint< T2 > &center)
Definition: Rectangle.h:1569
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:313
double Hypot() const
Definition: Rectangle.h:701
bool IsLine() const
Definition: Rectangle.h:727
component Top() const
Definition: Rectangle.h:498
bool IsOrderedRect(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:243
64-bit floating-point rectangle in the R^2 space.
component Bottom() const
Definition: Rectangle.h:516
bool IsRect(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:210
void Rotate(T1 sa, T1 ca, T2 xc, T2 yc)
Definition: Rectangle.h:1580
T Abs(const Complex< T > &c)
Definition: Complex.h:420
void Set(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:1140
double CenterY() const
Definition: Rectangle.h:690
void ResizeTo(T1 w, T1 h)
Definition: Rectangle.h:1301
constexpr const T & Max(const T &a, const T &b)
Definition: Utility.h:119
GenericRectangle Rotated(T1 angle, T2 xc, T2 yc) const
Definition: Rectangle.h:1603
GenericRectangle WidthSetTo(T1 w) const
Definition: Rectangle.h:1530
component x
Abscissa (horizontal, or X-axis coordinate).
Definition: Point.h:111
GenericRectangle MovedTo(const pcl::GenericPoint< T1 > &p) const
Definition: Rectangle.h:1192
void Rotate(T1 angle, T2 xc, T2 yc)
Definition: Rectangle.h:1557
int TruncInt(T x)
Definition: Math.h:1012
GenericRectangle InflatedBy(T1 d) const
Definition: Rectangle.h:1455
constexpr const T & Min(const T &a, const T &b)
Definition: Utility.h:90
void Rotate(T &x, T &y, T1 sa, T1 ca, T2 xc, T2 yc)
Definition: Math.h:1823
point RightBottom() const
Definition: Rectangle.h:576
void DeflateBy(T1 d)
Definition: Rectangle.h:1486
bool IsPointOrLine() const
Definition: Rectangle.h:751
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:495
point CenterRight() const
Definition: Rectangle.h:624
GenericRectangle InflatedBy(T1 dx, T1 dy) const
Definition: Rectangle.h:1443
component Width() const
Definition: Rectangle.h:633
GenericRectangle MovedBy(T1 dx, T1 dy) const
Definition: Rectangle.h:1283
GenericRectangle Ordered() const
Definition: Rectangle.h:792
32-bit floating-point rectangle in the R^2 space.
GenericRectangle(std::initializer_list< T1 > l)
Definition: Rectangle.h:390
GenericRectangle ResizedBy(T1 dw, T1 dh) const
Definition: Rectangle.h:1360
point CenterBottom() const
Definition: Rectangle.h:608
bool IsHorizontalLine() const
Definition: Rectangle.h:735
void MoveBy(const pcl::GenericPoint< T1 > &d)
Definition: Rectangle.h:1218
point CenterTop() const
Definition: Rectangle.h:600
bool Intersects(T1 left, T1 top, T1 right, T1 bottom) const
Definition: Rectangle.h:929
constexpr GenericRectangle()
Definition: Rectangle.h:341
GenericRectangle(const GenericRectangle< T1 > &r)
Definition: Rectangle.h:462
bool IsHorizontalLine(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:159
void Rotate(T1 sa, T1 ca, const GenericPoint< T2 > &center)
Definition: Rectangle.h:1592
bool IsPoint() const
Definition: Rectangle.h:719
point CenterLeft() const
Definition: Rectangle.h:616
bool IsOrdered() const
Definition: Rectangle.h:776
GenericRectangle(const pcl::GenericPoint< T1 > &leftTop, const pcl::GenericPoint< T1 > &rightBottom)
Definition: Rectangle.h:423
void OrderRect(T &x0, T &y0, T &x1, T &y1)
Definition: Rectangle.h:260
GenericRectangle Rounded(int n) const
Definition: Rectangle.h:1692
bool Intersects(const pcl::GenericRectangle< T1 > &r) const
Definition: Rectangle.h:940
component x0
Horizontal coordinate of the upper left corner.
Definition: Rectangle.h:332
GenericRectangle Rounded() const
Definition: Rectangle.h:1682
GenericRectangle DeflatedBy(T1 dx, T1 dy) const
Definition: Rectangle.h:1504
point Center() const
Definition: Rectangle.h:592
bool IsNormalRect(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:226
GenericRectangle Rotated(T1 sa, T1 ca, T2 xc, T2 yc) const
Definition: Rectangle.h:1630
constexpr GenericRectangle(component width, component height)
Definition: Rectangle.h:438
GenericRectangle DeflatedBy(T1 d) const
Definition: Rectangle.h:1516
point RightTop() const
Definition: Rectangle.h:542
void SinCos(T x, T &sx, T &cx)
Definition: Math.h:915
double Diagonal() const
Definition: Rectangle.h:711
bool Includes(T1 x, T1 y) const
Definition: Rectangle.h:855
bool IsPointOrLine(T x0, T y0, T x1, T y1)
Definition: Rectangle.h:193
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2)
Definition: Array.h:2075
Complex< T1 > operator/(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:583
ClipFlags ClipCode(T1 x, T1 y) const
Definition: Rectangle.h:808
64-bit floating-point rectangle in the R^2 space.
bool IntersectsFast(T1 left, T1 top, T1 right, T1 bottom) const
Definition: Rectangle.h:972
32-bit integer rectangle on the plane.
void Unite(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:1010
component y0
Vertical coordinate of the upper left corner.
Definition: Rectangle.h:333
void DeflateBy(T1 dx, T1 dy)
Definition: Rectangle.h:1468
component y
Ordinate (vertical, or Y-axis coordinate).
Definition: Point.h:112
bool IncludesFast(const pcl::GenericPoint< T1 > &p) const
Definition: Rectangle.h:913
Flags< Clip::mask_type > ClipFlags
Definition: Rectangle.h:104
GenericPoint< component > point
Definition: Rectangle.h:325
GenericRectangle MovedBy(const pcl::GenericPoint< T1 > &d) const
Definition: Rectangle.h:1269
GenericRectangle HeightSetTo(T1 h) const
Definition: Rectangle.h:1544
GenericRectangle Intersection(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:1095
T Trunc(T x)
Definition: Math.h:980
32-bit integer rectangle on the plane.
constexpr GenericRectangle(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:357
point LeftTop() const
Definition: Rectangle.h:525
component Left() const
Definition: Rectangle.h:489
ClipFlags ClipCode(const pcl::GenericPoint< T1 > &p) const
Definition: Rectangle.h:845
component y1
Vertical coordinate of the lower right corner.
Definition: Rectangle.h:335
bool Includes(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:874
void InflateBy(T1 dx, T1 dy)
Definition: Rectangle.h:1407
point TopRight() const
Definition: Rectangle.h:550
component Height() const
Definition: Rectangle.h:642