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
7996 {
7997  std::vector<Point2d_<FPT>> v_pts;
7998  for( const auto& elem: v_coord )
7999  {
8000  auto id_x = elem.first;
8001  auto id_y = elem.second;
8002  assert( id_x<4 && id_y<4 );
8003 
8004  auto pt = Point2d_<FPT>( v_x[id_x]._value, v_y[id_y]._value );
8005  if( v_pts.empty() )
8006  v_pts.push_back( pt );
8007  else // add to vector only if not same as previous
8008  { // and not same as first
8009  if( v_pts.back() != pt && v_pts.front() != pt )
8010  v_pts.push_back( pt );
8011  }
8012  }
8013 // printVector( v_pts, "polyline" );
8014  return CPolyline_<FPT>( v_pts );//, IsClosed::Yes );
8015 }
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
7914 {
7915  switch( dir )
7916  {
7917  case Direction::N: row--; break;
7918  case Direction::S: row++; break;
7919  case Direction::E: col++; break;
7920  case Direction::W: col--; break;
7921  }
7922 }
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
7931 {
7932  bool firstTime = true;
7933  bool done = false;
7934  uint8_t row = 0;
7935  uint8_t col = 0;
7936  Direction dir = Direction::E;
7937  std::vector<PCoord> out;
7938  do
7939  {
7940  if( table[row][col]._isCorner )
7941  {
7942  auto new_pair = std::make_pair(row,col);
7943  if( out.size() > 0 )
7944  if( new_pair == out.front() && out.size() > 2 )
7945  done = true;
7946  if( !done )
7947  out.push_back( new_pair );
7948  if( firstTime )
7949  firstTime = false;
7950  else
7951  dir = turn( dir, Turn::Right );
7952  }
7953  else
7954  {
7955  if( ( row==2 || row==1 ) && ( col==2 || col==1 ) )
7956  {
7957  out.push_back( std::make_pair(row,col) );
7958  dir = turn( dir, Turn::Left );
7959  }
7960  }
7961  moveToNextCell( row, col, dir );
7962  }
7963  while( !done );
7964  return out;
7965 }
Direction turn(Direction dir, Turn turn)
Definition: homog2d.hpp:7895
void moveToNextCell(uint8_t &row, uint8_t &col, const Direction &dir)
Definition: homog2d.hpp:7913
Direction
Definition: homog2d.hpp:7876
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
7896 {
7897  switch( dir )
7898  {
7899  case Direction::W:
7900  return turn == Turn::Left ? Direction::S : Direction::N;
7901  case Direction::S:
7902  return turn == Turn::Left ? Direction::E : Direction::W;
7903  case Direction::E:
7904  return turn == Turn::Left ? Direction::N : Direction::S;
7905  case Direction::N:
7906  return turn == Turn::Left ? Direction::W : Direction::E;
7907  }
7908  return Direction::N; // to avoid a warning
7909 }
Direction turn(Direction dir, Turn turn)
Definition: homog2d.hpp:7895
Here is the caller graph for this function: