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
7999 {
8000  std::vector<Point2d_<FPT>> v_pts;
8001  for( const auto& elem: v_coord )
8002  {
8003  auto id_x = elem.first;
8004  auto id_y = elem.second;
8005  assert( id_x<4 && id_y<4 );
8006 
8007  auto pt = Point2d_<FPT>( v_x[id_x]._value, v_y[id_y]._value );
8008  if( v_pts.empty() )
8009  v_pts.push_back( pt );
8010  else // add to vector only if not same as previous
8011  { // and not same as first
8012  if( v_pts.back() != pt && v_pts.front() != pt )
8013  v_pts.push_back( pt );
8014  }
8015  }
8016 // printVector( v_pts, "polyline" );
8017  return CPolyline_<FPT>( v_pts );//, IsClosed::Yes );
8018 }
Point2d pt
Definition: homog2d_test.cpp:4052
Here is the caller graph for this function:

◆ moveToNextCell()

void h2d::priv::runion::moveToNextCell ( uint8_t &  row,
uint8_t &  col,
const Direction dir 
)
inline
7917 {
7918  switch( dir )
7919  {
7920  case Direction::N: row--; break;
7921  case Direction::S: row++; break;
7922  case Direction::E: col++; break;
7923  case Direction::W: col--; break;
7924  }
7925 }
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
7934 {
7935  bool firstTime = true;
7936  bool done = false;
7937  uint8_t row = 0;
7938  uint8_t col = 0;
7939  Direction dir = Direction::E;
7940  std::vector<PCoord> out;
7941  do
7942  {
7943  if( table[row][col]._isCorner )
7944  {
7945  auto new_pair = std::make_pair(row,col);
7946  if( out.size() > 0 )
7947  if( new_pair == out.front() && out.size() > 2 )
7948  done = true;
7949  if( !done )
7950  out.push_back( new_pair );
7951  if( firstTime )
7952  firstTime = false;
7953  else
7954  dir = turn( dir, Turn::Right );
7955  }
7956  else
7957  {
7958  if( ( row==2 || row==1 ) && ( col==2 || col==1 ) )
7959  {
7960  out.push_back( std::make_pair(row,col) );
7961  dir = turn( dir, Turn::Left );
7962  }
7963  }
7964  moveToNextCell( row, col, dir );
7965  }
7966  while( !done );
7967  return out;
7968 }
Direction turn(Direction dir, Turn turn)
Definition: homog2d.hpp:7898
void moveToNextCell(uint8_t &row, uint8_t &col, const Direction &dir)
Definition: homog2d.hpp:7916
Direction
Definition: homog2d.hpp:7879
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
7899 {
7900  switch( dir )
7901  {
7902  case Direction::W:
7903  return turn == Turn::Left ? Direction::S : Direction::N;
7904  case Direction::S:
7905  return turn == Turn::Left ? Direction::E : Direction::W;
7906  case Direction::E:
7907  return turn == Turn::Left ? Direction::N : Direction::S;
7908  case Direction::N:
7909  return turn == Turn::Left ? Direction::W : Direction::E;
7910  }
7911  return Direction::N; // to avoid a warning
7912 }
Direction turn(Direction dir, Turn turn)
Definition: homog2d.hpp:7898
Here is the caller graph for this function: