52 #ifndef __PCL_Rectangle_h
53 #define __PCL_Rectangle_h
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>
123 template <
typename T>
inline
124 bool IsPoint( T x0, T y0, T x1, T y1 ) noexcept
126 return x0 == x1 && y0 == y1;
141 template <
typename T>
inline
142 bool IsLine( T x0, T y0, T x1, T y1 ) noexcept
144 return ((x0 == x1) ^ (y0 == y1)) != 0;
158 template <
typename T>
inline
161 return y0 == y1 && x0 != x1;
175 template <
typename T>
inline
178 return x0 == x1 && y0 != y1;
192 template <
typename T>
inline
195 return x0 == x1 || y0 == y1;
209 template <
typename T>
inline
210 bool IsRect( T x0, T y0, T x1, T y1 ) noexcept
212 return x0 != x1 && y0 != y1;
225 template <
typename T>
inline
228 return x0 < x1 && y0 < y1;
242 template <
typename T>
inline
245 return x0 <= x1 && y0 <= y1;
259 template <
typename T>
inline
278 #define PCL_ASSERT_RECT_SIZE() \
279 static_assert( sizeof( *this ) == 4*sizeof( T ), "Invalid sizeof( GenericRectangle<> )" )
312 template <
typename T>
343 PCL_ASSERT_RECT_SIZE();
356 template <
typename T1>
363 PCL_ASSERT_RECT_SIZE();
391 template <
typename T1>
394 PCL_ASSERT_RECT_SIZE();
424 template <
typename T1>
429 PCL_ASSERT_RECT_SIZE();
443 PCL_ASSERT_RECT_SIZE();
456 PCL_ASSERT_RECT_SIZE();
463 template <
typename T1>
468 PCL_ASSERT_RECT_SIZE();
471 #ifdef __PCL_QT_INTERFACE
474 component( r.right()+1 ), component( r.bottom()+1 ) )
476 PCL_ASSERT_RECT_SIZE();
479 GenericRectangle(
const QPoint& p0,
const QPoint& p1 )
480 : GenericRectangle( component( p0.x() ), component( p0.y() ),
481 component( p1.x() ), component( p1.y() ) )
483 PCL_ASSERT_RECT_SIZE();
588 return RightBottom();
596 return point( (x0 + x1)/2, (y0 + y1)/2 );
667 return Width() + Height();
676 return pcl::Abs( (x1 - x0)*(y1 - y0) );
685 return 0.5*(x0 + x1);
694 return 0.5*(y0 + y1);
705 double w = x1 - x0, h = y1 - y0;
809 template <
typename T1>
816 if ( x < x0 ) clip |= Clip::Left;
817 if ( x > x1 ) clip |= Clip::Right;
821 if ( x < x1 ) clip |= Clip::Left;
822 if ( x > x0 ) clip |= Clip::Right;
827 if ( y < y0 ) clip |= Clip::Top;
828 if ( y > y1 ) clip |= Clip::Bottom;
832 if ( y < y1 ) clip |= Clip::Top;
833 if ( y > y0 ) clip |= Clip::Bottom;
846 template <
typename T1>
849 return ClipCode( p.x, p.y );
856 template <
typename T1>
859 return ((x0 < x1) ? (x >= x0 && x <= x1) : (x >= x1 && x <= x0)) &&
860 ((y0 < y1) ? (y >= y0 && y <= y1) : (y >= y1 && y <= y0));
866 template <
typename T1>
869 return Includes( p.x, p.y );
875 template <
typename T1>
878 return Includes( r.x0, r.y0 ) && Includes( r.x1, r.y1 );
881 #ifdef __PCL_QT_INTERFACE
882 bool Includes(
const QPoint& p )
const noexcept
884 return Includes( p.x(), p.y() );
887 bool Includes(
const QRect& r )
const noexcept
889 return Includes( r.left(), r.top() ) && Includes( r.right()+1, r.bottom()+1 );
901 template <
typename T1>
904 return x >= x0 && y >= y0 && x <= x1 && y <= y1;
914 template <
typename T1>
917 return IncludesFast( p.x, p.y );
930 template <
typename T1>
931 bool Intersects( T1 left, T1 top, T1 right, T1 bottom )
const noexcept
934 return ((x0 < x1) ? (right >= x0 && left <= x1) : (right >= x1 && left <= x0)) &&
935 ((y0 < y1) ? (bottom >= y0 && top <= y1) : (bottom >= y1 && top <= y0));
941 template <
typename T1>
944 return Intersects( r.x0, r.y0, r.x1, r.y1 );
947 #ifdef __PCL_QT_INTERFACE
948 bool Intersects(
const QRect& r )
const noexcept
950 return Intersects( r.left(), r.top(), r.right()+1, r.bottom()+1 );
973 template <
typename T1>
976 return right >= x0 && left <= x1 && bottom >= y0 && top <= y1;
985 template <
typename T1>
988 return IntersectsFast( r.x0, r.y0, r.x1, r.y1 );
995 template <
typename T1>
998 Unite( r.x0, r.y0, r.x1, r.y1 );
1011 template <
typename T1>
1012 void Unite( T1 left, T1 top, T1 right, T1 bottom ) noexcept
1015 Swap( left, right );
1017 Swap( top, bottom );
1049 template <
typename T1>
1052 UniteFast( r.x0, r.y0, r.x1, r.y1 );
1074 template <
typename T1>
1075 void UniteFast( T1 left, T1 top, T1 right, T1 bottom ) noexcept
1086 template <
typename T1>
1100 template <
typename T1>
1112 template <
typename T1>
1119 #ifdef __PCL_QT_INTERFACE
1120 void Unite(
const QRect& r )
1122 Unite( r.left(), r.top(), r.right()+1, r.bottom()+1 );
1125 GenericRectangle Union(
const QRect& r )
const noexcept
1127 GenericRectangle r1 = *
this;
1132 GenericRectangle& operator |=(
const QRect& r ) noexcept
1147 template <
typename T1>
1150 return Intersect( r.x0, r.y0, r.x1, r.y1 );
1167 template <
typename T1>
1168 bool Intersect( T1 left, T1 top, T1 right, T1 bottom ) noexcept
1171 Swap( left, right );
1173 Swap( top, bottom );
1211 template <
typename T1>
1214 return IntersectFast( r.x0, r.y0, r.x1, r.y1 );
1240 template <
typename T1>
1254 template <
typename T1>
1269 template <
typename T1>
1281 template <
typename T1>
1288 #ifdef __PCL_QT_INTERFACE
1289 bool Intersect(
const QRect& r ) noexcept
1291 return Intersect( r.left(), r.top(), r.right()+1, r.bottom()+1 );
1294 GenericRectangle Intersection(
const QRect& r )
const noexcept
1296 GenericRectangle r1 = *
this;
1297 (void)r1.Intersect( r );
1301 GenericRectangle& operator &=(
const QRect& r ) noexcept
1314 template <
typename T1>
1315 void Set( T1 left, T1 top, T1 right, T1 bottom ) noexcept
1330 template <
typename T1>
1343 template <
typename T1>
1353 #ifdef __PCL_QT_INTERFACE
1354 void MoveTo(
const QPoint& p ) noexcept
1356 MoveTo( p.x(), p.y() );
1366 template <
typename T1>
1380 template <
typename T1>
1392 template <
typename T1>
1403 template <
typename T1>
1421 template <
typename T1>
1430 #ifdef __PCL_QT_INTERFACE
1431 void MoveBy(
const QPoint& p ) noexcept
1433 MoveBy( p.x(), p.y() );
1443 template <
typename T1>
1457 template <
typename T1>
1475 template <
typename T1>
1495 template <
typename T1>
1514 template <
typename T1>
1534 template <
typename T1>
1550 template <
typename T1>
1567 template <
typename T1>
1581 template <
typename T1>
1599 template <
typename T1>
1617 template <
typename T1>
1629 template <
typename T1>
1642 template <
typename T1>
1660 template <
typename T1>
1678 template <
typename T1>
1690 template <
typename T1>
1704 template <
typename T1>
1718 template <
typename T1>
1731 template <
typename T1,
typename T2>
1732 void Rotate( T1 angle, T2 xc, T2 yc ) noexcept
1743 template <
typename T1,
typename T2>
1746 Rotate( angle, center.x, center.y );
1754 template <
typename T1,
typename T2>
1755 void Rotate( T1 sa, T1 ca, T2 xc, T2 yc ) noexcept
1766 template <
typename T1,
typename T2>
1769 Rotate( sa, ca, center.x, center.y );
1777 template <
typename T1,
typename T2>
1781 r.
Rotate( angle, xc, yc );
1790 template <
typename T1,
typename T2>
1794 r.
Rotate( angle, center );
1804 template <
typename T1,
typename T2>
1808 r.
Rotate( sa, ca, xc, yc );
1818 template <
typename T1,
typename T2>
1822 r.
Rotate( sa, ca, center );
1844 PCL_PRECONDITION( n >= 0 )
1869 PCL_PRECONDITION( n >= 0 )
1925 template <
typename T1>
1942 template <
typename T1>
1958 x0 = y0 = x1 = y1 = d;
1962 #ifdef __PCL_QT_INTERFACE
1965 x0 = component( r.left() );
1966 y0 = component( r.top() );
1967 x1 = component( r.right()+1 );
1968 y1 = component( r.bottom()+1 );
1985 template <
typename T1>
2008 template <
typename T1>
2041 #ifdef __PCL_QT_INTERFACE
2044 component dx = component( p.x() ), dy = component( p.y() );
2065 template <
typename T1>
2088 template <
typename T1>
2121 #ifdef __PCL_QT_INTERFACE
2124 component dx = component( p.x() ), dy = component( p.y() );
2145 template <
typename T1>
2169 template <
typename T1>
2202 #ifdef __PCL_QT_INTERFACE
2205 component dx = component( p.x() ), dy = component( p.y() );
2206 x0 *= dx; y0 *= dy; x1 *= dx; y1 *= dy;
2223 template <
typename T1>
2249 template <
typename T1>
2277 x0 /= d; y0 /= d; x1 /= d; y1 /= d;
2281 #ifdef __PCL_QT_INTERFACE
2284 PCL_PRECONDITION( component( p.x() ) != component( 0 ) && component( p.y() ) != component( 0 ) )
2285 component dx = component( p.x() ), dy = component( p.y() );
2313 #ifdef __PCL_QT_INTERFACE
2314 operator QRect() const noexcept
2316 return QRect(
int( x0 ),
int( y0 ),
int( x1-x0 ),
int( y1-y0 ) );
2320 #ifdef __PCL_QT_INTERFACE
2321 # ifndef __PCL_QT_NO_RECT_DRAWING_HELPERS
2323 void Draw( QPainter& p,
const QBrush* b )
const
2325 int rx0, ry0, rx1, ry1;
2337 if ( rx1 - rx0 <= 1 )
2339 if ( ry1 - ry0 <= 1 )
2340 p.drawPoint( rx0, ry0 );
2342 p.drawLine( rx0, ry0, rx0, ry1-1 );
2344 else if ( ry1 - ry0 <= 1 )
2346 p.drawLine( rx0, ry0, rx1-1, ry0 );
2350 # if ( QT_VERSION >= 0x040000 )
2351 int w = rx1-rx0-1, h = ry1-ry0-1;
2353 int w = rx1-rx0, h = ry1-ry0;
2356 p.fillRect( rx0, ry0, w, h, *b );
2357 p.drawRect( rx0, ry0, w, h );
2361 void Draw( QPainter& p )
const
2366 void Draw( QPainter& p,
const QColor& c )
const
2372 # endif // !__PCL_QT_NO_RECT_DRAWING_HELPERS
2373 #endif // __PCL_QT_INTERFACE
2377 #undef PCL_ASSERT_RECT_SIZE
2390 template <
typename T1,
typename T2>
inline
2393 return r1.x0 == r2.x0 && r1.y0 == r2.y0 && r1.x1 == r2.x1 && r1.y1 == r2.y1;
2401 template <
typename T>
inline
2404 return r1.x0 == d2 && r1.y0 == d2 && r1.x1 == d2 && r1.y1 == d2;
2413 template <
typename T>
inline
2416 return d1 == r2.x0 && d1 == r2.y0 && d1 == r2.x1 && d1 == r2.y1;
2425 template <
typename T1,
typename T2>
inline
2428 T1 x01 =
Min( r1.x0, r1.x1 ); T1 y01 =
Min( r1.y0, r1.y1 );
2429 T1 x11 =
Max( r1.x0, r1.x1 ); T1 y11 =
Max( r1.y0, r1.y1 );
2430 T2 x02 =
Min( r2.x0, r2.x1 ); T2 y02 =
Min( r2.y0, r2.y1 );
2431 T2 x12 =
Max( r2.x0, r2.x1 ); T2 y12 =
Max( r2.y0, r2.y1 );
2456 template <
typename T1,
typename T2>
inline
2460 T1( r1.x1 + r2.x1 ), T1( r1.y1 + r2.y1 ) );
2477 template <
typename T1,
typename T2>
inline
2481 T1( r1.x1 + p2.x ), T1( r1.y1 + p2.y ) );
2493 template <
typename T1,
typename T2>
inline
2497 T2( p1.x + r2.x1 ), T2( p1.y + r2.y1 ) );
2514 template <
typename T>
inline
2529 template <
typename T>
inline
2550 template <
typename T1,
typename T2>
inline
2554 T1( r1.x1 - r2.x1 ), T1( r1.y1 - r2.y1 ) );
2571 template <
typename T1,
typename T2>
inline
2575 T1( r1.x1 - p2.x ), T1( r1.y1 - p2.y ) );
2592 template <
typename T1,
typename T2>
inline
2596 T2( p1.x - r2.x1 ), T2( p1.y - r2.y1 ) );
2613 template <
typename T>
inline
2633 template <
typename T>
inline
2654 template <
typename T1,
typename T2>
inline
2658 T1( r1.x1 * r2.x1 ), T1( r1.y1 * r2.y1 ) );
2675 template <
typename T1,
typename T2>
inline
2679 T1( r1.x1 * p2.x ), T1( r1.y1 * p2.y ) );
2691 template <
typename T1,
typename T2>
inline
2695 T2( p1.x * r2.x1 ), T2( p1.y * r2.y1 ) );
2712 template <
typename T>
inline
2727 template <
typename T>
inline
2748 template <
typename T1,
typename T2>
inline
2751 PCL_PRECONDITION( r2.x0 != T2( 0 ) && r2.y0 != T2( 0 ) &&
2752 r2.x1 != T2( 0 ) && r2.y1 != T2( 0 ) )
2754 T1( r1.x1 / r2.x1 ), T1( r1.y1 / r2.y1 ) );
2771 template <
typename T1,
typename T2>
inline
2774 PCL_PRECONDITION( p2.x != T2( 0 ) && p2.y != T2( 0 ) )
2776 T1( r1.x1 / p2.x ), T1( r1.y1 / p2.y ) );
2793 template <
typename T1,
typename T2>
inline
2796 PCL_PRECONDITION( r2.x0 != T2( 0 ) && r2.y0 != T2( 0 ) &&
2797 r2.x1 != T2( 0 ) && r2.y1 != T2( 0 ) )
2799 T2( p1.x / r2.x1 ), T2( p1.y / r2.y1 ) );
2816 template <
typename T>
inline
2819 PCL_PRECONDITION( d2 != T( 0 ) )
2837 template <
typename T>
inline
2840 PCL_PRECONDITION( r2.x0 != T( 0 ) && r2.y0 != T( 0 ) &&
2841 r2.x1 != T( 0 ) && r2.y1 != T( 0 ) )
2860 template <
typename T,
typename T1,
typename T2>
inline
2883 template <
typename T,
typename T1,
typename T2>
inline
2904 template <
typename T,
typename T1,
typename T2>
inline
2926 template <
typename T,
typename T1,
typename T2>
inline
2943 template <
typename T>
inline
2952 #ifndef __PCL_NO_RECT_INSTANTIATE
2965 using I32Rect = GenericRectangle<int32>;
2984 using F32Rect = GenericRectangle<float>;
3003 using F64Rect = GenericRectangle<double>;
3021 #endif // __PCL_Rectangle_h