|
void | draw (img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const |
| Draw FRect (Opencv implementation) More...
|
|
void | draw (img::Image< img::SvgImage > &, img::DrawParams dp=img::DrawParams()) const |
| Draw FRect (SVG implementation) More...
|
|
std::array< Point2d_< FPT >, 4 > | get4Pts () const |
| Returns the 4 points of the rectangle, starting from "smallest" one, and in clockwise order. More...
|
|
std::pair< Segment_< FPT >, Segment_< FPT > > | getDiagonals () const |
|
FRect_< FPT > | getExtended () const |
|
std::array< Segment_< FPT >, 4 > | getSegs () const |
| Returns the 4 segments of the rectangle, starting with the first vertical one. More...
|
|
template<typename FPT1 , typename FPT2 > |
void | set (const Point2d_< FPT1 > &pa, const Point2d_< FPT2 > &pb) |
| Assigns points pa and pb to rectangle. More...
|
|
template<typename T > |
void | set (T x1, T y1, T x2, T y2) |
| Assigns points (x1,y1) and (x2,y2) to rectangle. More...
|
|
Type | type () const |
|
|
| FRect_ () |
| Default constructor, initialize rectangle to (0,0)-(1,1) More...
|
|
template<typename FPT2 > |
| FRect_ (const Point2d_< FPT2 > &pa, const Point2d_< FPT2 > &pb) |
| Constructor from 2 points. More...
|
|
template<typename FPT2 > |
| FRect_ (const PointPair_< FPT2 > &ppts) |
| Constructor from pair of points. More...
|
|
template<typename FPT2 , typename T1 , typename T2 > |
| FRect_ (const Point2d_< FPT2 > &p0, T1 w, T2 h) |
| Constructor from center point, width and height. More...
|
|
template<typename T1 , typename T2 , typename T3 , typename T4 > |
| FRect_ (T1 x1, T2 y1, T3 x2, T4 y2) |
| Constructor from x1, y1, x2, y2. More...
|
|
template<typename FPT2 > |
| FRect_ (const FRect_< FPT2 > &other) |
| Copy-Constructor. More...
|
|
|
HOMOG2D_INUMTYPE | height () const |
|
HOMOG2D_INUMTYPE | width () const |
|
HOMOG2D_INUMTYPE | area () const |
|
HOMOG2D_INUMTYPE | length () const |
|
constexpr size_t | size () const |
|
FRect_< FPT > | getBB () const |
| get BB of rectangle. Needed for getBB( pair of objects ) More...
|
|
PointPair_< FPT > | getPts () const |
| Returns the 2 major points of the rectangle. More...
|
|
Point2d_< FPT > | getCenter () const |
| Returns center of rectangle. More...
|
|
Circle_< FPT > | getBoundingCircle () const |
| Return circle passing through 4 points of flat rectangle. More...
|
|
Circle_< FPT > | getInscribedCircle () const |
| Return circle inscribed in rectangle. More...
|
|
|
template<typename TX , typename TY > |
void | translate (TX dx, TY dy) |
| Translate FRect. More...
|
|
template<typename T1 , typename T2 > |
void | translate (const std::pair< T1, T2 > &pa) |
| Translate FRect. More...
|
|
template<typename TX , typename TY > |
void | moveTo (TX x, TY y) |
| Move FRect to other location. More...
|
|
template<typename T1 > |
void | moveTo (const Point2d_< T1 > &pt) |
| Move FRect to other location, given by pt . More...
|
|
template<typename FPT2 > |
void | rotate (Rotate, const Point2d_< FPT2 > &) |
| Rotates the rectangle by either 90°, 180°, 270° (-90°) at point refpt . More...
|
|
void | rotate (Rotate) |
| Rotates the rectangle by either 90°, 180°, 270° (-90°) at point (0,0) More...
|
|
|
template<typename FPT2 > |
CPolyline_< FPT > | unionArea (const FRect_< FPT2 > &other) const |
| Computes the CPolyline of the union of two rectangles. More...
|
|
template<typename FPT2 > |
detail::RectArea< FPT > | intersectArea (const FRect_< FPT2 > &other) const |
| Returns Rectangle of the intersection area of two rectangles. More...
|
|
template<typename FPT2 > |
CPolyline_< FPT > | operator| (const FRect_< FPT2 > &other) const |
|
template<typename FPT2 > |
detail::RectArea< FPT > | operator& (const FRect_< FPT2 > &other) const |
|
|
template<typename T > |
bool | isInside (const T &shape) const |
| Returns true if rectangle is inside shape (Circle_ or FRect_ or base::Polyline) More...
|
|
template<typename FPT2 > |
constexpr bool | isInside (const OPolyline_< FPT2 > &) const |
| A FRect is never inside an open polyline. More...
|
|
template<typename FPT2 > |
bool | isInside (const CPolyline_< FPT2 > &poly) const |
| For a rectangle to be inside a closed Polyline, two conditions are necessary: More...
|
|
|
template<typename FPT2 > |
detail::IntersectM< FPT > | intersects (const Line2d_< FPT2 > &line) const |
| FRect/Line intersection. More...
|
|
template<typename FPT2 > |
detail::IntersectM< FPT > | intersects (const Segment_< FPT2 > &seg) const |
| FRect/Segment intersection. More...
|
|
template<typename FPT2 > |
detail::IntersectM< FPT > | intersects (const Circle_< FPT2 > &circle) const |
| FRect/Circle intersection. More...
|
|
template<typename PLT2 , typename FPT2 > |
detail::IntersectM< FPT > | intersects (const base::PolylineBase< PLT2, FPT2 > &pl) const |
| FRect/Polyline intersection. More...
|
|
template<typename FPT2 > |
detail::IntersectM< FPT > | intersects (const FRect_< FPT2 > &rect) const |
| FRect/FRect intersection. More...
|
|
|
template<typename FPT2 > |
bool | operator== (const FRect_< FPT2 > &other) const |
|
template<typename FPT2 > |
bool | operator!= (const FRect_< FPT2 > &other) const |
|
std::pair< int, int > | dsize () const |
| Get data size expressed as number of bits for, respectively, mantissa and exponent. More...
|
|
Dtype | dtype () const |
| Get numerical data type as a Dtype value, can be stringified with h2d::getString(Dtype) More...
|
|
template<typename T > |
constexpr bool | isInside (const Common< T > &) const |
| This function is a fallback for all sub-classes that do not provide such a method. More...
|
|
size_t | size () const |
|
virtual | ~Root () |
|
template<typename FPT>
class h2d::FRect_< FPT >
A Flat Rectangle, modeled by its two opposite points.
template<typename FPT >
template<typename FPT2 >
Computes the CPolyline of the union of two rectangles.
Algorithm:
- build vectors of x and y coordinates (4 elements)
- build table x-y (4x4), with corners tagged
- parse the table by turning right at each corner, and left if position is not one the outside row/col
- convert back indexes to real coordinates, to build the final CPolyline object
Two examples:
9 +----+ +-------+
| | | |
8 +---+----+---+ +---+---+ |
| | | | | | | |
7 +---+----+---+ +---+---+ |
| | | |
6 +----+ +-------+
1 2 3 4 1 2 3 4
Step 1 will build (for both situations above):
Step 2 will build a table showing where the corners are:
| 0 1 2 3 | 0 1 2 3
--|---------| --|---------|
0 | . F F . | 0| . F . F
1 | F F F F | 1| F F . .
2 | F F F F | 2| F F . .
3 | . F F . | 3| . F . F
Step 3: parse that table and turn on each corner:
- left if "inner" corner (row and col = 1 or = 2)
- right if "outer" corner (row and col = 0 or = 3)
Final step: convert indexes to real coordinates
Special note: if the rectangles have an identical coordinate, as in this example:
9 +----+
| |
8 +---+----+
| | |
7 +---+----+
| |
6 +----+
1 2 3
Then the vectors are:
(notice the duped coordinate)
This will produce a Polyline_ with 2 extra points:
(1,7)-(1,8)-(2,8)-(2,9)-(3,9)-(3,8)-(3,7)-(3,6)-(2,6)-(2,7)
instead of:
(1,7)-(1,8)-(2,8)-(2,9)-(3,9)-(3,6)-(2,6)-(2,7)
We solve this by proceeding an extra Polyline minimization, see PolylineBase::minimize()
8087 using namespace priv::runion;
8089 if( *
this == other )
8090 return CPolyline_<FPT>( other );
8095 return CPolyline_<FPT>(other);
8096 if( other.isInside( *
this ) )
8097 return CPolyline_<FPT>(*
this);
8098 return CPolyline_<FPT>();
8112 const auto* pr1 =
this;
8113 const auto* pr2 = &other;
8114 if( pr1->getPts().first.getX() < pr2->getPts().first.getX() )
8115 std::swap( pr1, pr2 );
8116 const auto& r1 = *pr1;
8117 const auto& r2 = *pr2;
8120 std::array<Index<FPT>,4> vx, vy;
8122 vx[i++] = Index<FPT>( r1.getPts().first.getX(), 1 );
8123 vx[i++] = Index<FPT>( r1.getPts().second.getX(), 1 );
8124 vx[i++] = Index<FPT>( r2.getPts().first.getX(), 2 );
8125 vx[i++] = Index<FPT>( r2.getPts().second.getX(), 2 );
8128 vy[i++] = Index<FPT>( r1.getPts().first.getY(), 1 );
8129 vy[i++] = Index<FPT>( r1.getPts().second.getY(), 1 );
8130 vy[i++] = Index<FPT>( r2.getPts().first.getY(), 2 );
8131 vy[i++] = Index<FPT>( r2.getPts().second.getY(), 2 );
8133 std::sort( vx.begin(), vx.end() );
8134 std::sort( vy.begin(), vy.end() );
8139 for( uint8_t r=0;r<4; r++ )
8140 for( uint8_t c=0;c<4; c++ )
8141 table[r][c] = Cell( vx[r], vy[c] );
std::vector< PCoord > parseTable(Table &table)
Helper function for FRect_<FPT>::unionArea()
Definition: homog2d.hpp:7929
std::array< std::array< Cell, 4 >, 4 > Table
Definition: homog2d.hpp:7872
detail::IntersectM< FPT > intersects(const Line2d_< FPT2 > &line) const
FRect/Line intersection.
Definition: homog2d.hpp:3012
bool isInside(const T &shape) const
Returns true if rectangle is inside shape (Circle_ or FRect_ or base::Polyline)
Definition: homog2d.hpp:2972
CPolyline_< FPT > convertToCoord(const std::vector< PCoord > &v_coord, const std::array< Index< FPT >, 4 > &v_x, const std::array< Index< FPT >, 4 > &v_y)
Helper function, used in FRect_<FPT>::unionArea()
Definition: homog2d.hpp:7990