homog2d library
Classes | Typedefs | Enumerations | Functions
h2d::priv::runion Namespace Reference

Common stuff for FRect_ union, see FRect_::unionArea() More...

Classes

struct  Cell
 A wrapper around a bool, that gets set if that point defined by indexes ix and iy is a corner in the table. More...
 
struct  Index
 Holds x or y coordinate value of rectangle during computation of intersection area. More...
 

Typedefs

using PCoord = std::pair< uint8_t, uint8_t >
 
using Table = std::array< std::array< Cell, 4 >, 4 >
 

Enumerations

enum  Direction : uint8_t { Direction::N, Direction::E, Direction::S, Direction::W }
 
enum  Turn : uint8_t { Turn::Left, Turn::Right }
 

Functions

template<typename FPT >
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() More...
 
void moveToNextCell (uint8_t &row, uint8_t &col, const Direction &dir)
 
std::vector< PCoordparseTable (Table &table)
 Helper function for FRect_<FPT>::unionArea() More...
 
Direction turn (Direction dir, Turn turn)
 

Detailed Description

Common stuff for FRect_ union, see FRect_::unionArea()

Typedef Documentation

◆ PCoord

using h2d::priv::runion::PCoord = typedef std::pair<uint8_t,uint8_t>

◆ Table

using h2d::priv::runion::Table = typedef std::array<std::array<Cell,4>,4>

Enumeration Type Documentation

◆ Direction

enum h2d::priv::runion::Direction : uint8_t
strong

◆ Turn

enum h2d::priv::runion::Turn : uint8_t
strong
Enumerator
Left 
Right 

Function Documentation

◆ convertToCoord()

template<typename FPT >
CPolyline_<FPT> h2d::priv::runion::convertToCoord ( const std::vector< PCoord > &  v_coord,
const std::array< Index< FPT >, 4 > &  v_x,
const std::array< Index< FPT >, 4 > &  v_y 
)
inline

Helper function, used in FRect_<FPT>::unionArea()

Parameters
v_coordvector of coordinate indexes
v_xholds x-coordinates
v_yholds y-coordinates
7995 {
7996  std::vector<Point2d_<FPT>> v_pts;
7997  for( const auto& elem: v_coord )
7998  {
7999  auto id_x = elem.first;
8000  auto id_y = elem.second;
8001  assert( id_x<4 && id_y<4 );
8002 
8003  auto pt = Point2d_<FPT>( v_x[id_x]._value, v_y[id_y]._value );
8004  if( v_pts.empty() )
8005  v_pts.push_back( pt );
8006  else // add to vector only if not same as previous
8007  { // and not same as first
8008  if( v_pts.back() != pt && v_pts.front() != pt )
8009  v_pts.push_back( pt );
8010  }
8011  }
8012 // printVector( v_pts, "polyline" );
8013  return CPolyline_<FPT>( v_pts );//, IsClosed::Yes );
8014 }
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the caller graph for this function:

◆ moveToNextCell()

void h2d::priv::runion::moveToNextCell ( uint8_t &  row,
uint8_t &  col,
const Direction dir 
)
inline
7913 {
7914  switch( dir )
7915  {
7916  case Direction::N: row--; break;
7917  case Direction::S: row++; break;
7918  case Direction::E: col++; break;
7919  case Direction::W: col--; break;
7920  }
7921 }
Here is the caller graph for this function:

◆ parseTable()

std::vector<PCoord> h2d::priv::runion::parseTable ( Table table)
inline

Helper function for FRect_<FPT>::unionArea()

  • Start from 0,0, direction East
7930 {
7931  bool firstTime = true;
7932  bool done = false;
7933  uint8_t row = 0;
7934  uint8_t col = 0;
7935  Direction dir = Direction::E;
7936  std::vector<PCoord> out;
7937  do
7938  {
7939  if( table[row][col]._isCorner )
7940  {
7941  auto new_pair = std::make_pair(row,col);
7942  if( out.size() > 0 )
7943  if( new_pair == out.front() && out.size() > 2 )
7944  done = true;
7945  if( !done )
7946  out.push_back( new_pair );
7947  if( firstTime )
7948  firstTime = false;
7949  else
7950  dir = turn( dir, Turn::Right );
7951  }
7952  else
7953  {
7954  if( ( row==2 || row==1 ) && ( col==2 || col==1 ) )
7955  {
7956  out.push_back( std::make_pair(row,col) );
7957  dir = turn( dir, Turn::Left );
7958  }
7959  }
7960  moveToNextCell( row, col, dir );
7961  }
7962  while( !done );
7963  return out;
7964 }
Direction turn(Direction dir, Turn turn)
Definition: homog2d.hpp:7894
void moveToNextCell(uint8_t &row, uint8_t &col, const Direction &dir)
Definition: homog2d.hpp:7912
Direction
Definition: homog2d.hpp:7875
Here is the call graph for this function:
Here is the caller graph for this function:

◆ turn()

Direction h2d::priv::runion::turn ( Direction  dir,
Turn  turn 
)
inline
7895 {
7896  switch( dir )
7897  {
7898  case Direction::W:
7899  return turn == Turn::Left ? Direction::S : Direction::N;
7900  case Direction::S:
7901  return turn == Turn::Left ? Direction::E : Direction::W;
7902  case Direction::E:
7903  return turn == Turn::Left ? Direction::N : Direction::S;
7904  case Direction::N:
7905  return turn == Turn::Left ? Direction::W : Direction::E;
7906  }
7907  return Direction::N; // to avoid a warning
7908 }
Direction turn(Direction dir, Turn turn)
Definition: homog2d.hpp:7894
Here is the caller graph for this function: