PCL
Rectangle.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/Rectangle.h - Released 2019-11-07T10:59:34Z
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  if ( right < left )
1013  Swap( left, right );
1014  if ( bottom < top )
1015  Swap( top, bottom );
1016 
1017  if ( x0 <= x1 )
1018  {
1019  x0 = pcl::Min( x0, component( left ) );
1020  x1 = pcl::Max( x1, component( right ) );
1021  }
1022  else
1023  {
1024  x0 = pcl::Max( x0, component( right ) );
1025  x1 = pcl::Min( x1, component( left ) );
1026  }
1027 
1028  if ( y0 <= y1 )
1029  {
1030  y0 = pcl::Min( y0, component( top ) );
1031  y1 = pcl::Max( y1, component( bottom ) );
1032  }
1033  else
1034  {
1035  y0 = pcl::Max( y0, component( bottom ) );
1036  y1 = pcl::Min( y1, component( top ) );
1037  }
1038  }
1039 
1047  template <typename T1>
1049  {
1050  UniteFast( r.x0, r.y0, r.x1, r.y1 );
1051  }
1052 
1072  template <typename T1>
1073  void UniteFast( T1 left, T1 top, T1 right, T1 bottom )
1074  {
1075  x0 = pcl::Min( x0, component( left ) );
1076  y0 = pcl::Min( y0, component( top ) );
1077  x1 = pcl::Max( x1, component( right ) );
1078  y1 = pcl::Max( y1, component( bottom ) );
1079  }
1080 
1084  template <typename T1>
1086  {
1087  GenericRectangle r1 = *this;
1088  r1.Unite( r );
1089  return r1;
1090  }
1091 
1098  template <typename T1>
1100  {
1101  GenericRectangle r1 = *this;
1102  r1.UniteFast( r );
1103  return r1;
1104  }
1105 
1110  template <typename T1>
1111  GenericRectangle& operator |=( const GenericRectangle<T1>& r )
1112  {
1113  Unite( r );
1114  return *this;
1115  }
1116 
1117 #ifdef __PCL_QT_INTERFACE
1118  void Unite( const QRect& r )
1119  {
1120  Unite( r.left(), r.top(), r.right()+1, r.bottom()+1 );
1121  }
1122 
1123  GenericRectangle Union( const QRect& r ) const
1124  {
1125  GenericRectangle r1 = *this;
1126  r1.Unite( r );
1127  return r1;
1128  }
1129 
1130  GenericRectangle& operator |=( const QRect& r )
1131  {
1132  Unite( r );
1133  return *this;
1134  }
1135 #endif
1136 
1145  template <typename T1>
1147  {
1148  return Intersect( r.x0, r.y0, r.x1, r.y1 );
1149  }
1150 
1165  template <typename T1>
1166  bool Intersect( T1 left, T1 top, T1 right, T1 bottom )
1167  {
1168  if ( right < left )
1169  Swap( left, right );
1170  if ( bottom < top )
1171  Swap( top, bottom );
1172 
1173  if ( x0 <= x1 )
1174  {
1175  x0 = pcl::Max( x0, component( left ) );
1176  x1 = pcl::Min( x1, component( right ) );
1177  }
1178  else
1179  {
1180  x0 = pcl::Min( x0, component( right ) );
1181  x1 = pcl::Max( x1, component( left ) );
1182  }
1183 
1184  if ( y0 <= y1 )
1185  {
1186  y0 = pcl::Max( y0, component( top ) );
1187  y1 = pcl::Min( y1, component( bottom ) );
1188  }
1189  else
1190  {
1191  y0 = pcl::Min( y0, component( bottom ) );
1192  y1 = pcl::Max( y1, component( top ) );
1193  }
1194 
1195  return IsRect();
1196  }
1197 
1209  template <typename T1>
1211  {
1212  return IntersectFast( r.x0, r.y0, r.x1, r.y1 );
1213  }
1214 
1238  template <typename T1>
1239  bool IntersectFast( T1 left, T1 top, T1 right, T1 bottom )
1240  {
1241  x0 = pcl::Max( x0, component( left ) );
1242  y0 = pcl::Max( y0, component( top ) );
1243  x1 = pcl::Min( x1, component( right ) );
1244  y1 = pcl::Min( y1, component( bottom ) );
1245  return IsRect();
1246  }
1247 
1252  template <typename T1>
1254  {
1255  GenericRectangle r1 = *this;
1256  (void)r1.Intersect( r );
1257  return r1;
1258  }
1259 
1267  template <typename T1>
1269  {
1270  GenericRectangle r1 = *this;
1271  (void)r1.IntersectFast( r );
1272  return r1;
1273  }
1274 
1279  template <typename T1>
1280  GenericRectangle& operator &=( const GenericRectangle<T1>& r )
1281  {
1282  Intersect( r );
1283  return *this;
1284  }
1285 
1286 #ifdef __PCL_QT_INTERFACE
1287  bool Intersect( const QRect& r )
1288  {
1289  return Intersect( r.left(), r.top(), r.right()+1, r.bottom()+1 );
1290  }
1291 
1292  GenericRectangle Intersection( const QRect& r ) const
1293  {
1294  GenericRectangle r1 = *this;
1295  (void)r1.Intersect( r );
1296  return r1;
1297  }
1298 
1299  GenericRectangle& operator &=( const QRect& r )
1300  {
1301  Intersect( r );
1302  return *this;
1303  }
1304 #endif
1305 
1312  template <typename T1>
1313  void Set( T1 left, T1 top, T1 right, T1 bottom )
1314  {
1315  x0 = component( left );
1316  y0 = component( top );
1317  x1 = component( right );
1318  y1 = component( bottom );
1319  }
1320 
1328  template <typename T1>
1330  {
1331  MoveTo( p.x, p.y );
1332  }
1333 
1341  template <typename T1>
1342  void MoveTo( T1 x, T1 y )
1343  {
1344  component dx = x1 - x0, dy = y1 - y0;
1345  x0 = component( x );
1346  y0 = component( y );
1347  x1 = x0 + dx;
1348  y1 = y0 + dy;
1349  }
1350 
1351 #ifdef __PCL_QT_INTERFACE
1352  void MoveTo( const QPoint& p )
1353  {
1354  MoveTo( p.x(), p.y() );
1355  }
1356 #endif
1357 
1364  template <typename T1>
1366  {
1367  GenericRectangle r( *this );
1368  r.MoveTo( p );
1369  return r;
1370  }
1371 
1378  template <typename T1>
1379  GenericRectangle MovedTo( T1 x, T1 y ) const
1380  {
1381  GenericRectangle r( *this );
1382  r.MoveTo( x, y );
1383  return r;
1384  }
1385 
1390  template <typename T1>
1392  {
1393  MoveBy( d.x, d.y );
1394  }
1395 
1401  template <typename T1>
1402  void MoveBy( T1 dx, T1 dy )
1403  {
1404  x0 += component( dx );
1405  y0 += component( dy );
1406  x1 += component( dx );
1407  y1 += component( dy );
1408  }
1409 
1419  template <typename T1>
1420  void MoveBy( T1 dxy )
1421  {
1422  x0 += component( dxy );
1423  y0 += component( dxy );
1424  x1 += component( dxy );
1425  y1 += component( dxy );
1426  }
1427 
1428 #ifdef __PCL_QT_INTERFACE
1429  void MoveBy( const QPoint& p )
1430  {
1431  MoveBy( p.x(), p.y() );
1432  }
1433 #endif
1434 
1441  template <typename T1>
1443  {
1444  GenericRectangle r( *this );
1445  r.MoveBy( d );
1446  return r;
1447  }
1448 
1455  template <typename T1>
1456  GenericRectangle MovedBy( T1 dx, T1 dy ) const
1457  {
1458  GenericRectangle r( *this );
1459  r.MoveBy( dx, dy );
1460  return r;
1461  }
1462 
1473  template <typename T1>
1474  void ResizeTo( T1 w, T1 h )
1475  {
1476  if ( x0 <= x1 )
1477  x1 = x0 + component( w );
1478  else
1479  x0 = x1 + component( w );
1480 
1481  if ( y0 <= y1 )
1482  y1 = y0 + component( h );
1483  else
1484  y0 = y1 + component( h );
1485  }
1486 
1493  template <typename T1>
1494  GenericRectangle ResizedTo( T1 w, T1 h ) const
1495  {
1496  GenericRectangle r( *this );
1497  r.ResizeTo( w, h );
1498  return r;
1499  }
1500 
1512  template <typename T1>
1513  void ResizeBy( T1 dw, T1 dh )
1514  {
1515  if ( x0 <= x1 )
1516  x1 += component( dw );
1517  else
1518  x0 += component( dw );
1519 
1520  if ( y0 <= y1 )
1521  y1 += component( dh );
1522  else
1523  y0 += component( dh );
1524  }
1525 
1532  template <typename T1>
1533  GenericRectangle ResizedBy( T1 dw, T1 dh ) const
1534  {
1535  GenericRectangle r( *this );
1536  r.ResizeBy( dw, dh );
1537  return r;
1538  }
1539 
1548  template <typename T1>
1549  void SetWidth( T1 w )
1550  {
1551  if ( x0 <= x1 )
1552  x1 = x0 + component( w );
1553  else
1554  x0 = x1 + component( w );
1555  }
1556 
1565  template <typename T1>
1566  void SetHeight( T1 h )
1567  {
1568  if ( y0 <= y1 )
1569  y1 = y0 + component( h );
1570  else
1571  y0 = y1 + component( h );
1572  }
1573 
1579  template <typename T1>
1580  void InflateBy( T1 dx, T1 dy )
1581  {
1582  if ( x1 < x0 )
1583  dx = -dx;
1584  if ( y1 < y0 )
1585  dy = -dy;
1586  x0 -= dx;
1587  y0 -= dy;
1588  x1 += dx;
1589  y1 += dy;
1590  }
1591 
1597  template <typename T1>
1598  void InflateBy( T1 d )
1599  {
1600  if ( x0 <= x1 )
1601  x0 -= d, x1 += d;
1602  else
1603  x0 += d, x1 -= d;
1604 
1605  if ( y0 <= y1 )
1606  y0 -= d, y1 += d;
1607  else
1608  y0 += d, y1 -= d;
1609  }
1610 
1615  template <typename T1>
1616  GenericRectangle InflatedBy( T1 dx, T1 dy ) const
1617  {
1618  GenericRectangle r( *this );
1619  r.InflateBy( dx, dy );
1620  return r;
1621  }
1622 
1627  template <typename T1>
1629  {
1630  GenericRectangle r( *this );
1631  r.InflateBy( d );
1632  return r;
1633  }
1634 
1640  template <typename T1>
1641  void DeflateBy( T1 dx, T1 dy )
1642  {
1643  if ( x1 < x0 )
1644  dx = -dx;
1645  if ( y1 < y0 )
1646  dy = -dy;
1647  x0 += dx;
1648  y0 += dy;
1649  x1 -= dx;
1650  y1 -= dy;
1651  }
1652 
1658  template <typename T1>
1659  void DeflateBy( T1 d )
1660  {
1661  if ( x0 <= x1 )
1662  x0 += d, x1 -= d;
1663  else
1664  x0 -= d, x1 += d;
1665 
1666  if ( y0 <= y1 )
1667  y0 += d, y1 -= d;
1668  else
1669  y0 -= d, y1 += d;
1670  }
1671 
1676  template <typename T1>
1677  GenericRectangle DeflatedBy( T1 dx, T1 dy ) const
1678  {
1679  GenericRectangle r( *this );
1680  r.DeflateBy( dx, dy );
1681  return r;
1682  }
1683 
1688  template <typename T1>
1690  {
1691  GenericRectangle r( *this );
1692  r.DeflateBy( d );
1693  return r;
1694  }
1695 
1702  template <typename T1>
1704  {
1705  GenericRectangle r( *this );
1706  r.SetWidth( w );
1707  return r;
1708  }
1709 
1716  template <typename T1>
1718  {
1719  GenericRectangle r( *this );
1720  r.SetHeight( h );
1721  return r;
1722  }
1723 
1729  template <typename T1, typename T2>
1730  void Rotate( T1 angle, T2 xc, T2 yc )
1731  {
1732  T1 sa, ca; pcl::SinCos( angle, sa, ca );
1733  pcl::Rotate( x0, y0, sa, ca, xc, yc );
1734  pcl::Rotate( x1, y1, sa, ca, xc, yc );
1735  }
1736 
1741  template <typename T1, typename T2>
1742  void Rotate( T1 angle, const GenericPoint<T2>& center )
1743  {
1744  Rotate( angle, center.x, center.y );
1745  }
1746 
1752  template <typename T1, typename T2>
1753  void Rotate( T1 sa, T1 ca, T2 xc, T2 yc )
1754  {
1755  pcl::Rotate( x0, y0, sa, ca, xc, yc );
1756  pcl::Rotate( x1, y1, sa, ca, xc, yc );
1757  }
1758 
1764  template <typename T1, typename T2>
1765  void Rotate( T1 sa, T1 ca, const GenericPoint<T2>& center )
1766  {
1767  Rotate( sa, ca, center.x, center.y );
1768  }
1769 
1775  template <typename T1, typename T2>
1776  GenericRectangle Rotated( T1 angle, T2 xc, T2 yc ) const
1777  {
1778  GenericRectangle r( *this );
1779  r.Rotate( angle, xc, yc );
1780  return r;
1781  }
1782 
1788  template <typename T1, typename T2>
1789  GenericRectangle Rotated( T1 angle, const GenericPoint<T2>& center ) const
1790  {
1791  GenericRectangle r( *this );
1792  r.Rotate( angle, center );
1793  return r;
1794  }
1795 
1802  template <typename T1, typename T2>
1803  GenericRectangle Rotated( T1 sa, T1 ca, T2 xc, T2 yc ) const
1804  {
1805  GenericRectangle r( *this );
1806  r.Rotate( sa, ca, xc, yc );
1807  return r;
1808  }
1809 
1816  template <typename T1, typename T2>
1817  GenericRectangle Rotated( T1 sa, T1 ca, const GenericPoint<T2>& center ) const
1818  {
1819  GenericRectangle r( *this );
1820  r.Rotate( sa, ca, center );
1821  return r;
1822  }
1823 
1828  void Round()
1829  {
1830  x0 = component( pcl::Round( double( x0 ) ) );
1831  y0 = component( pcl::Round( double( y0 ) ) );
1832  x1 = component( pcl::Round( double( x1 ) ) );
1833  y1 = component( pcl::Round( double( y1 ) ) );
1834  }
1835 
1840  void Round( int n )
1841  {
1842  PCL_PRECONDITION( n >= 0 )
1843  if ( n < 0 )
1844  n = 0;
1845  x0 = component( pcl::Round( double( x0 ), n ) );
1846  y0 = component( pcl::Round( double( y0 ), n ) );
1847  x1 = component( pcl::Round( double( x1 ), n ) );
1848  y1 = component( pcl::Round( double( y1 ), n ) );
1849  }
1850 
1856  {
1857  return GenericRectangle( component( pcl::Round( double( x0 ) ) ), component( pcl::Round( double( y0 ) ) ),
1858  component( pcl::Round( double( x1 ) ) ), component( pcl::Round( double( y1 ) ) ) );
1859  }
1860 
1865  GenericRectangle Rounded( int n ) const
1866  {
1867  PCL_PRECONDITION( n >= 0 )
1868  return GenericRectangle( component( pcl::Round( double( x0 ), n ) ), component( pcl::Round( double( y0 ), n ) ),
1869  component( pcl::Round( double( x1 ), n ) ), component( pcl::Round( double( y1 ), n ) ) );
1870  }
1871 
1877  {
1878  return GenericRectangle<int>( pcl::RoundInt( double( x0 ) ), pcl::RoundInt( double( y0 ) ),
1879  pcl::RoundInt( double( x1 ) ), pcl::RoundInt( double( y1 ) ) );
1880  }
1881 
1887  void Truncate()
1888  {
1889  x0 = component( pcl::Trunc( double( x0 ) ) );
1890  y0 = component( pcl::Trunc( double( y0 ) ) );
1891  x1 = component( pcl::Trunc( double( x1 ) ) );
1892  y1 = component( pcl::Trunc( double( y1 ) ) );
1893  }
1894 
1902  {
1903  return GenericRectangle( component( pcl::Trunc( double( x0 ) ) ), component( pcl::Trunc( double( y0 ) ) ),
1904  component( pcl::Trunc( double( x1 ) ) ), component( pcl::Trunc( double( y1 ) ) ) );
1905  }
1906 
1914  {
1915  return GenericRectangle<int>( pcl::TruncInt( double( x0 ) ), pcl::TruncInt( double( y0 ) ),
1916  pcl::TruncInt( double( x1 ) ), pcl::TruncInt( double( y1 ) ) );
1917  }
1918 
1923  template <typename T1>
1924  GenericRectangle& operator =( const GenericRectangle<T1>& r )
1925  {
1926  x0 = component( r.x0 );
1927  y0 = component( r.y0 );
1928  x1 = component( r.x1 );
1929  y1 = component( r.y1 );
1930  return *this;
1931  }
1932 
1940  template <typename T1>
1941  GenericRectangle& operator =( const pcl::GenericPoint<T1>& p )
1942  {
1943  x0 = x1 = component( p.x );
1944  y0 = y1 = component( p.y );
1945  return *this;
1946  }
1947 
1954  GenericRectangle& operator =( component d )
1955  {
1956  x0 = y0 = x1 = y1 = d;
1957  return *this;
1958  }
1959 
1960 #ifdef __PCL_QT_INTERFACE
1961  GenericRectangle& operator =( const QRect& r )
1962  {
1963  x0 = component( r.left() );
1964  y0 = component( r.top() );
1965  x1 = component( r.right()+1 );
1966  y1 = component( r.bottom()+1 );
1967  return *this;
1968  }
1969 #endif
1970 
1983  template <typename T1>
1984  GenericRectangle& operator +=( const GenericRectangle<T1>& r )
1985  {
1986  x0 += component( r.x0 );
1987  y0 += component( r.y0 );
1988  x1 += component( r.x1 );
1989  y1 += component( r.y1 );
1990  return *this;
1991  }
1992 
2006  template <typename T1>
2007  GenericRectangle& operator +=( const pcl::GenericPoint<T1>& p )
2008  {
2009  x0 += component( p.x );
2010  y0 += component( p.y );
2011  x1 += component( p.x );
2012  y1 += component( p.y );
2013  return *this;
2014  }
2015 
2030  GenericRectangle& operator +=( component d )
2031  {
2032  x0 += d;
2033  y0 += d;
2034  x1 += d;
2035  y1 += d;
2036  return *this;
2037  }
2038 
2039 #ifdef __PCL_QT_INTERFACE
2040  GenericRectangle& operator +=( const QPoint& p )
2041  {
2042  component dx = component( p.x() ), dy = component( p.y() );
2043  x0 += dx;
2044  y0 += dy;
2045  x1 += dx;
2046  y1 += dy;
2047  return *this;
2048  }
2049 #endif
2050 
2063  template <typename T1>
2064  GenericRectangle& operator -=( const GenericRectangle<T1>& r )
2065  {
2066  x0 -= component( r.x0 );
2067  y0 -= component( r.y0 );
2068  x1 -= component( r.x1 );
2069  y1 -= component( r.y1 );
2070  return *this;
2071  }
2072 
2086  template <typename T1>
2087  GenericRectangle& operator -=( const pcl::GenericPoint<T1>& p )
2088  {
2089  x0 -= component( p.x );
2090  y0 -= component( p.y );
2091  x1 -= component( p.x );
2092  y1 -= component( p.y );
2093  return *this;
2094  }
2095 
2110  GenericRectangle& operator -=( component d )
2111  {
2112  x0 -= d;
2113  y0 -= d;
2114  x1 -= d;
2115  y1 -= d;
2116  return *this;
2117  }
2118 
2119 #ifdef __PCL_QT_INTERFACE
2120  GenericRectangle& operator -=( const QPoint& p )
2121  {
2122  component dx = component( p.x() ), dy = component( p.y() );
2123  x0 -= dx;
2124  y0 -= dy;
2125  x1 -= dx;
2126  y1 -= dy;
2127  return *this;
2128  }
2129 #endif
2130 
2143  template <typename T1>
2144  GenericRectangle& operator *=( const GenericRectangle<T1>& r )
2145  {
2146  x0 *= component( r.x0 );
2147  y0 *= component( r.y0 );
2148  x1 *= component( r.x1 );
2149  y1 *= component( r.y1 );
2150  return *this;
2151  }
2152 
2167  template <typename T1>
2168  GenericRectangle& operator *=( const pcl::GenericPoint<T1>& p )
2169  {
2170  x0 *= component( p.x );
2171  y0 *= component( p.y );
2172  x1 *= component( p.x );
2173  y1 *= component( p.y );
2174  return *this;
2175  }
2176 
2191  GenericRectangle& operator *=( component d )
2192  {
2193  x0 *= d;
2194  y0 *= d;
2195  x1 *= d;
2196  y1 *= d;
2197  return *this;
2198  }
2199 
2200 #ifdef __PCL_QT_INTERFACE
2201  GenericRectangle& operator *=( const QPoint& p )
2202  {
2203  component dx = component( p.x() ), dy = component( p.y() );
2204  x0 *= dx; y0 *= dy; x1 *= dx; y1 *= dy;
2205  return *this;
2206  }
2207 #endif
2208 
2221  template <typename T1>
2222  GenericRectangle& operator /=( const GenericRectangle<T1>& r )
2223  {
2224  PCL_PRECONDITION( component( r.x0 ) != component( 0 ) && component( r.y0 ) != component( 0 ) &&
2225  component( r.x1 ) != component( 0 ) && component( r.y1 ) != component( 0 ) )
2226  x0 /= component( r.x0 );
2227  y0 /= component( r.y0 );
2228  x1 /= component( r.x1 );
2229  y1 /= component( r.y1 );
2230  return *this;
2231  }
2232 
2247  template <typename T1>
2248  GenericRectangle& operator /=( const pcl::GenericPoint<T1>& p )
2249  {
2250  PCL_PRECONDITION( component( p.x ) != component( 0 ) && component( p.y ) != component( 0 ) )
2251  x0 /= component( p.x );
2252  y0 /= component( p.y );
2253  x1 /= component( p.x );
2254  y1 /= component( p.y );
2255  return *this;
2256  }
2257 
2272  GenericRectangle& operator /=( component d )
2273  {
2274  PCL_PRECONDITION( d != component( 0 ) )
2275  x0 /= d; y0 /= d; x1 /= d; y1 /= d;
2276  return *this;
2277  }
2278 
2279 #ifdef __PCL_QT_INTERFACE
2280  GenericRectangle& operator /=( const QPoint& p )
2281  {
2282  PCL_PRECONDITION( component( p.x() ) != component( 0 ) && component( p.y() ) != component( 0 ) )
2283  component dx = component( p.x() ), dy = component( p.y() );
2284  x0 /= dx;
2285  y0 /= dy;
2286  x1 /= dx;
2287  y1 /= dy;
2288  return *this;
2289  }
2290 #endif
2291 
2296  {
2297  return *this;
2298  }
2299 
2307  {
2308  return GenericRectangle( -x0, -y0, -x1, -y1 );
2309  }
2310 
2311 #ifdef __PCL_QT_INTERFACE
2312  operator QRect() const
2313  {
2314  return QRect( int( x0 ), int( y0 ), int( x1-x0 ), int( y1-y0 ) );
2315  }
2316 #endif
2317 
2318 #ifdef __PCL_QT_INTERFACE
2319 # ifndef __PCL_QT_NO_RECT_DRAWING_HELPERS
2320 
2321  void Draw( QPainter& p, const QBrush* b ) const
2322  {
2323  int rx0, ry0, rx1, ry1;
2324 
2325  if ( x0 <= x1 )
2326  rx0 = x0, rx1 = x1;
2327  else
2328  rx0 = x1, rx1 = x0;
2329 
2330  if ( y0 <= y1 )
2331  ry0 = y0, ry1 = y1;
2332  else
2333  ry0 = y1, ry1 = y0;
2334 
2335  if ( rx1 - rx0 <= 1 )
2336  {
2337  if ( ry1 - ry0 <= 1 )
2338  p.drawPoint( rx0, ry0 );
2339  else
2340  p.drawLine( rx0, ry0, rx0, ry1-1 );
2341  }
2342  else if ( ry1 - ry0 <= 1 )
2343  {
2344  p.drawLine( rx0, ry0, rx1-1, ry0 );
2345  }
2346  else
2347  {
2348 # if ( QT_VERSION >= 0x040000 )
2349  int w = rx1-rx0-1, h = ry1-ry0-1;
2350 # else
2351  int w = rx1-rx0, h = ry1-ry0;
2352 # endif
2353  if ( b != 0 )
2354  p.fillRect( rx0, ry0, w, h, *b );
2355  p.drawRect( rx0, ry0, w, h );
2356  }
2357  }
2358 
2359  void Draw( QPainter& p ) const
2360  {
2361  Draw( p, 0 );
2362  }
2363 
2364  void Draw( QPainter& p, const QColor& c ) const
2365  {
2366  QBrush b( c );
2367  Draw( p, &b );
2368  }
2369 
2370 # endif // !__PCL_QT_NO_RECT_DRAWING_HELPERS
2371 #endif // __PCL_QT_INTERFACE
2372 
2373 }; // GenericRectangle<T>
2374 
2375 #undef PCL_ASSERT_RECT_SIZE
2376 
2377 // ----------------------------------------------------------------------------
2378 
2388 template <typename T1, typename T2> inline
2390 {
2391  return r1.x0 == r2.x0 && r1.y0 == r2.y0 && r1.x1 == r2.x1 && r1.y1 == r2.y1;
2392 }
2393 
2399 template <typename T> inline
2400 bool operator ==( const GenericRectangle<T>& r1, T d2 )
2401 {
2402  return r1.x0 == d2 && r1.y0 == d2 && r1.x1 == d2 && r1.y1 == d2;
2403 }
2404 
2411 template <typename T> inline
2412 bool operator ==( T d1, const GenericRectangle<T>& r2 )
2413 {
2414  return d1 == r2.x0 && d1 == r2.y0 && d1 == r2.x1 && d1 == r2.y1;
2415 }
2416 
2423 template <typename T1, typename T2> inline
2424 bool operator <( const GenericRectangle<T1>& r1, const GenericRectangle<T2>& r2 )
2425 {
2426  T1 x01 = Min( r1.x0, r1.x1 ); T1 y01 = Min( r1.y0, r1.y1 );
2427  T1 x11 = Max( r1.x0, r1.x1 ); T1 y11 = Max( r1.y0, r1.y1 );
2428  T2 x02 = Min( r2.x0, r2.x1 ); T2 y02 = Min( r2.y0, r2.y1 );
2429  T2 x12 = Max( r2.x0, r2.x1 ); T2 y12 = Max( r2.y0, r2.y1 );
2430  if ( y01 != y02 )
2431  return y01 < y02;
2432  if ( x01 != x02 )
2433  return x01 < x02;
2434  if ( y11 != y12 )
2435  return y11 < y12;
2436  return x11 < x12;
2437 }
2438 
2454 template <typename T1, typename T2> inline
2456 {
2457  return GenericRectangle<T1>( T1( r1.x0 + r2.x0 ), T1( r1.y0 + r2.y0 ),
2458  T1( r1.x1 + r2.x1 ), T1( r1.y1 + r2.y1 ) );
2459 }
2460 
2475 template <typename T1, typename T2> inline
2477 {
2478  return GenericRectangle<T1>( T1( r1.x0 + p2.x ), T1( r1.y0 + p2.y ),
2479  T1( r1.x1 + p2.x ), T1( r1.y1 + p2.y ) );
2480 }
2481 
2491 template <typename T1, typename T2> inline
2493 {
2494  return GenericRectangle<T2>( T2( p1.x + r2.x0 ), T2( p1.y + r2.y0 ),
2495  T2( p1.x + r2.x1 ), T2( p1.y + r2.y1 ) );
2496 }
2497 
2512 template <typename T> inline
2514 {
2515  return GenericRectangle<T>( r1.x0+d2, r1.y0+d2, r1.x1+d2, r1.y1+d2 );
2516 }
2517 
2527 template <typename T> inline
2529 {
2530  return GenericRectangle<T>( d1+r2.x0, d1+r2.y0, d1+r2.x1, d1+r2.y1 );
2531 }
2532 
2548 template <typename T1, typename T2> inline
2550 {
2551  return GenericRectangle<T1>( T1( r1.x0 - r2.x0 ), T1( r1.y0 - r2.y0 ),
2552  T1( r1.x1 - r2.x1 ), T1( r1.y1 - r2.y1 ) );
2553 }
2554 
2569 template <typename T1, typename T2> inline
2571 {
2572  return GenericRectangle<T1>( T1( r1.x0 - p2.x ), T1( r1.y0 - p2.y ),
2573  T1( r1.x1 - p2.x ), T1( r1.y1 - p2.y ) );
2574 }
2575 
2590 template <typename T1, typename T2> inline
2592 {
2593  return GenericRectangle<T2>( T2( p1.x - r2.x0 ), T2( p1.y - r2.y0 ),
2594  T2( p1.x - r2.x1 ), T2( p1.y - r2.y1 ) );
2595 }
2596 
2611 template <typename T> inline
2613 {
2614  return GenericRectangle<T>( r1.x0-d2, r1.y0-d2, r1.x1-d2, r1.y1-d2 );
2615 }
2616 
2631 template <typename T> inline
2633 {
2634  return GenericRectangle<T>( d1-r2.x0, d1-r2.y0, d1-r2.x1, d1-r2.y1 );
2635 }
2636 
2652 template <typename T1, typename T2> inline
2654 {
2655  return GenericRectangle<T1>( T1( r1.x0 * r2.x0 ), T1( r1.y0 * r2.y0 ),
2656  T1( r1.x1 * r2.x1 ), T1( r1.y1 * r2.y1 ) );
2657 }
2658 
2673 template <typename T1, typename T2> inline
2675 {
2676  return GenericRectangle<T1>( T1( r1.x0 * p2.x ), T1( r1.y0 * p2.y ),
2677  T1( r1.x1 * p2.x ), T1( r1.y1 * p2.y ) );
2678 }
2679 
2689 template <typename T1, typename T2> inline
2691 {
2692  return GenericRectangle<T2>( T2( p1.x * r2.x0 ), T2( p1.y * r2.y0 ),
2693  T2( p1.x * r2.x1 ), T2( p1.y * r2.y1 ) );
2694 }
2695 
2710 template <typename T> inline
2712 {
2713  return GenericRectangle<T>( r1.x0*d2, r1.y0*d2, r1.x1*d2, r1.y1*d2 );
2714 }
2715 
2725 template <typename T> inline
2727 {
2728  return GenericRectangle<T>( d1*r2.x0, d1*r2.y0, d1*r2.x1, d1*r2.y1 );
2729 }
2730 
2746 template <typename T1, typename T2> inline
2748 {
2749  PCL_PRECONDITION( r2.x0 != T2( 0 ) && r2.y0 != T2( 0 ) &&
2750  r2.x1 != T2( 0 ) && r2.y1 != T2( 0 ) )
2751  return GenericRectangle<T1>( T1( r1.x0 / r2.x0 ), T1( r1.y0 / r2.y0 ),
2752  T1( r1.x1 / r2.x1 ), T1( r1.y1 / r2.y1 ) );
2753 }
2754 
2769 template <typename T1, typename T2> inline
2771 {
2772  PCL_PRECONDITION( p2.x != T2( 0 ) && p2.y != T2( 0 ) )
2773  return GenericRectangle<T1>( T1( r1.x0 / p2.x ), T1( r1.y0 / p2.y ),
2774  T1( r1.x1 / p2.x ), T1( r1.y1 / p2.y ) );
2775 }
2776 
2791 template <typename T1, typename T2> inline
2793 {
2794  PCL_PRECONDITION( r2.x0 != T2( 0 ) && r2.y0 != T2( 0 ) &&
2795  r2.x1 != T2( 0 ) && r2.y1 != T2( 0 ) )
2796  return GenericRectangle<T2>( T2( p1.x / r2.x0 ), T2( p1.y / r2.y0 ),
2797  T2( p1.x / r2.x1 ), T2( p1.y / r2.y1 ) );
2798 }
2799 
2814 template <typename T> inline
2816 {
2817  PCL_PRECONDITION( d2 != T( 0 ) )
2818  return GenericRectangle<T>( r1.x0/d2, r1.y0/d2, r1.x1/d2, r1.y1/d2 );
2819 }
2820 
2835 template <typename T> inline
2837 {
2838  PCL_PRECONDITION( r2.x0 != T( 0 ) && r2.y0 != T( 0 ) &&
2839  r2.x1 != T( 0 ) && r2.y1 != T( 0 ) )
2840  return GenericRectangle<T>( d1/r2.x0, d1/r2.y0, d1/r2.x1, d1/r2.y1 );
2841 }
2842 
2858 template <typename T, typename T1, typename T2> inline
2859 void Rotate( GenericRectangle<T>& r, T1 a, T2 xc, T2 yc )
2860 {
2861  T1 sa, ca; pcl::SinCos( a, sa, ca );
2862  pcl::Rotate( r.x0, r.y0, sa, ca, xc, yc );
2863  pcl::Rotate( r.x1, r.y1, sa, ca, xc, yc );
2864 }
2865 
2881 template <typename T, typename T1, typename T2> inline
2882 void Rotate( GenericRectangle<T>& r, T1 a, const GenericPoint<T2>& c )
2883 {
2884  pcl::Rotate( r, a, c.x, c.y );
2885 }
2886 
2902 template <typename T, typename T1, typename T2> inline
2903 void Rotate( GenericRectangle<T>& r, T1 sa, T1 ca, T2 xc, T2 yc )
2904 {
2905  pcl::Rotate( r.x0, r.y0, sa, ca, xc, yc );
2906  pcl::Rotate( r.x1, r.y1, sa, ca, xc, yc );
2907 }
2908 
2924 template <typename T, typename T1, typename T2> inline
2925 void Rotate( GenericRectangle<T>& r, T1 sa, T1 ca, const GenericPoint<T2>& c )
2926 {
2927  pcl::Rotate( r, sa, ca, c.x, c.y );
2928 }
2929 
2941 template <typename T> inline
2943 {
2944  pcl::Swap( r1.x0, r2.x0 ); pcl::Swap( r1.y0, r2.y0 );
2945  pcl::Swap( r1.x1, r2.x1 ); pcl::Swap( r1.y1, r2.y1 );
2946 }
2947 
2948 // ----------------------------------------------------------------------------
2949 
2950 #ifndef __PCL_NO_RECT_INSTANTIATE
2951 
2964 
2973 typedef I32Rect Rect;
2974 
2983 
2992 typedef F32Rect FRect;
2993 
3002 
3011 typedef F64Rect DRect;
3012 
3013 #endif
3014 
3015 // ----------------------------------------------------------------------------
3016 
3017 } // pcl
3018 
3019 #endif // __PCL_Rectangle_h
3020 
3021 // ----------------------------------------------------------------------------
3022 // EOF pcl/Rectangle.h - Released 2019-11-07T10:59:34Z
GenericRectangle< int > RoundedToInt() const
Definition: Rectangle.h:1876
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:1402
bool Intersect(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:1166
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:1329
GenericRectangle Union(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:1085
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:1420
point BottomRight() const
Definition: Rectangle.h:584
double CenterX() const
Definition: Rectangle.h:681
void MoveTo(T1 x, T1 y)
Definition: Rectangle.h:1342
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:1397
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:1566
PCL root namespace.
Definition: AbstractImage.h:76
GenericRectangle IntersectionFast(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:1268
GenericRectangle ResizedTo(T1 w, T1 h) const
Definition: Rectangle.h:1494
point LeftBottom() const
Definition: Rectangle.h:559
void ResizeBy(T1 dw, T1 dh)
Definition: Rectangle.h:1513
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:1913
GenericRectangle MovedTo(T1 x, T1 y) const
Definition: Rectangle.h:1379
GenericRectangle Rotated(T1 sa, T1 ca, const GenericPoint< T2 > &center) const
Definition: Rectangle.h:1817
Complex< T > Sqrt(const Complex< T > &c)
Definition: Complex.h:665
GenericRectangle Rotated(T1 angle, const GenericPoint< T2 > &center) const
Definition: Rectangle.h:1789
bool IsRect() const
Definition: Rectangle.h:760
bool IsVerticalLine() const
Definition: Rectangle.h:743
GenericRectangle Truncated() const
Definition: Rectangle.h:1901
Complex< T > Round(const Complex< T > &c)
Definition: Complex.h:929
void InflateBy(T1 d)
Definition: Rectangle.h:1598
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:1146
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:1742
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:1753
T Abs(const Complex< T > &c)
Definition: Complex.h:420
void Set(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:1313
double CenterY() const
Definition: Rectangle.h:690
void ResizeTo(T1 w, T1 h)
Definition: Rectangle.h:1474
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:1776
GenericRectangle WidthSetTo(T1 w) const
Definition: Rectangle.h:1703
component x
Abscissa (horizontal, or X-axis coordinate).
Definition: Point.h:111
GenericRectangle MovedTo(const pcl::GenericPoint< T1 > &p) const
Definition: Rectangle.h:1365
void Rotate(T1 angle, T2 xc, T2 yc)
Definition: Rectangle.h:1730
int TruncInt(T x)
Definition: Math.h:1035
GenericRectangle InflatedBy(T1 d) const
Definition: Rectangle.h:1628
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:1846
point RightBottom() const
Definition: Rectangle.h:576
void DeflateBy(T1 d)
Definition: Rectangle.h:1659
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:1616
component Width() const
Definition: Rectangle.h:633
GenericRectangle UnionFast(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:1099
GenericRectangle MovedBy(T1 dx, T1 dy) const
Definition: Rectangle.h:1456
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:1533
point CenterBottom() const
Definition: Rectangle.h:608
bool IsHorizontalLine() const
Definition: Rectangle.h:735
void MoveBy(const pcl::GenericPoint< T1 > &d)
Definition: Rectangle.h:1391
void UniteFast(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:1073
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:1765
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:1865
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:1855
GenericRectangle DeflatedBy(T1 dx, T1 dy) const
Definition: Rectangle.h:1677
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:1803
constexpr GenericRectangle(component width, component height)
Definition: Rectangle.h:438
GenericRectangle DeflatedBy(T1 d) const
Definition: Rectangle.h:1689
point RightTop() const
Definition: Rectangle.h:542
void SinCos(T x, T &sx, T &cx)
Definition: Math.h:938
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
bool IntersectFast(T1 left, T1 top, T1 right, T1 bottom)
Definition: Rectangle.h:1239
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:1641
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:1442
GenericRectangle HeightSetTo(T1 h) const
Definition: Rectangle.h:1717
GenericRectangle Intersection(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:1253
T Trunc(T x)
Definition: Math.h:1003
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
bool IntersectFast(const GenericRectangle< T1 > &r)
Definition: Rectangle.h:1210
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
void UniteFast(const GenericRectangle< T1 > &r)
Definition: Rectangle.h:1048
bool Includes(const GenericRectangle< T1 > &r) const
Definition: Rectangle.h:874
void InflateBy(T1 dx, T1 dy)
Definition: Rectangle.h:1580
point TopRight() const
Definition: Rectangle.h:550
component Height() const
Definition: Rectangle.h:642