KiCad PCB EDA Suite
SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER Class Reference

Class POINT_INSIDE_TRACKER. More...

#include <shape_line_chain.h>

Public Member Functions

 POINT_INSIDE_TRACKER (const VECTOR2I &aPoint)
 
void AddPolyline (const SHAPE_LINE_CHAIN &aPolyline)
 
bool IsInside ()
 

Private Member Functions

bool processVertex (const VECTOR2I &ip, const VECTOR2I &ipNext)
 

Private Attributes

VECTOR2I m_point
 
VECTOR2I m_lastPoint
 
VECTOR2I m_firstPoint
 
bool m_finished
 
int m_state
 
int m_count
 

Detailed Description

Class POINT_INSIDE_TRACKER.

A dynamic state checking if a point lies within polygon with a dynamically built outline ( with each piece of the outline added by AddPolyline ()

Definition at line 75 of file shape_line_chain.h.

Constructor & Destructor Documentation

◆ POINT_INSIDE_TRACKER()

SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::POINT_INSIDE_TRACKER ( const VECTOR2I aPoint)

Definition at line 1291 of file shape_line_chain.cpp.

Member Function Documentation

◆ AddPolyline()

void SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::AddPolyline ( const SHAPE_LINE_CHAIN aPolyline)

Definition at line 1361 of file shape_line_chain.cpp.

1362 {
1363  if( !m_count )
1364  {
1365  m_lastPoint = aPolyline.CPoint( 0 );
1366  m_firstPoint = aPolyline.CPoint( 0 );
1367  }
1368 
1369  m_count += aPolyline.PointCount();
1370 
1371  for( int i = 1; i < aPolyline.PointCount(); i++ )
1372  {
1373  auto p = aPolyline.CPoint( i );
1374 
1375  if( !processVertex( m_lastPoint, p ) )
1376  return;
1377 
1378  m_lastPoint = p;
1379  }
1380 
1381 }
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
bool processVertex(const VECTOR2I &ip, const VECTOR2I &ipNext)

References SHAPE_LINE_CHAIN::CPoint(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by PNS::SHOVE::checkShoveDirection().

◆ IsInside()

bool SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::IsInside ( )

Definition at line 1384 of file shape_line_chain.cpp.

◆ processVertex()

bool SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::processVertex ( const VECTOR2I ip,
const VECTOR2I ipNext 
)
private

Definition at line 1300 of file shape_line_chain.cpp.

1302 {
1303  if( ipNext.y == m_point.y )
1304  {
1305  if( ( ipNext.x == m_point.x )
1306  || ( ip.y == m_point.y && ( ( ipNext.x > m_point.x ) == ( ip.x < m_point.x ) ) ) )
1307  {
1308  m_finished = true;
1309  m_state = -1;
1310  return false;
1311  }
1312  }
1313 
1314  if( ( ip.y < m_point.y ) != ( ipNext.y < m_point.y ) )
1315  {
1316  if( ip.x >= m_point.x )
1317  {
1318  if( ipNext.x > m_point.x )
1319  {
1320  m_state = 1 - m_state;
1321  }
1322  else
1323  {
1324  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1325  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1326 
1327  if( !d )
1328  {
1329  m_finished = true;
1330  m_state = -1;
1331  return false;
1332  }
1333 
1334  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1335  m_state = 1 - m_state;
1336  }
1337  }
1338  else
1339  {
1340  if( ipNext.x > m_point.x )
1341  {
1342  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1343  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1344 
1345  if( !d )
1346  {
1347  m_finished = true;
1348  m_state = -1;
1349  return false;
1350  }
1351 
1352  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1353  m_state = 1 - m_state;
1354  }
1355  }
1356  }
1357  return true;
1358 }

References VECTOR2< T >::x, and VECTOR2< T >::y.

Member Data Documentation

◆ m_count

int SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_count
private

Definition at line 92 of file shape_line_chain.h.

◆ m_finished

bool SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_finished
private

Definition at line 90 of file shape_line_chain.h.

◆ m_firstPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_firstPoint
private

Definition at line 89 of file shape_line_chain.h.

◆ m_lastPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_lastPoint
private

Definition at line 88 of file shape_line_chain.h.

◆ m_point

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_point
private

Definition at line 87 of file shape_line_chain.h.

◆ m_state

int SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_state
private

Definition at line 91 of file shape_line_chain.h.


The documentation for this class was generated from the following files: