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 83 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 1374 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 1444 of file shape_line_chain.cpp.

1445 {
1446  if( !m_count )
1447  {
1448  m_lastPoint = aPolyline.CPoint( 0 );
1449  m_firstPoint = aPolyline.CPoint( 0 );
1450  }
1451 
1452  m_count += aPolyline.PointCount();
1453 
1454  for( int i = 1; i < aPolyline.PointCount(); i++ )
1455  {
1456  auto p = aPolyline.CPoint( i );
1457 
1458  if( !processVertex( m_lastPoint, p ) )
1459  return;
1460 
1461  m_lastPoint = p;
1462  }
1463 
1464 }
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 1467 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 1383 of file shape_line_chain.cpp.

1385 {
1386  if( ipNext.y == m_point.y )
1387  {
1388  if( ( ipNext.x == m_point.x )
1389  || ( ip.y == m_point.y && ( ( ipNext.x > m_point.x ) == ( ip.x < m_point.x ) ) ) )
1390  {
1391  m_finished = true;
1392  m_state = -1;
1393  return false;
1394  }
1395  }
1396 
1397  if( ( ip.y < m_point.y ) != ( ipNext.y < m_point.y ) )
1398  {
1399  if( ip.x >= m_point.x )
1400  {
1401  if( ipNext.x > m_point.x )
1402  {
1403  m_state = 1 - m_state;
1404  }
1405  else
1406  {
1407  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1408  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1409 
1410  if( !d )
1411  {
1412  m_finished = true;
1413  m_state = -1;
1414  return false;
1415  }
1416 
1417  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1418  m_state = 1 - m_state;
1419  }
1420  }
1421  else
1422  {
1423  if( ipNext.x > m_point.x )
1424  {
1425  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1426  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1427 
1428  if( !d )
1429  {
1430  m_finished = true;
1431  m_state = -1;
1432  return false;
1433  }
1434 
1435  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1436  m_state = 1 - m_state;
1437  }
1438  }
1439  }
1440  return true;
1441 }

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 100 of file shape_line_chain.h.

◆ m_finished

bool SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_finished
private

Definition at line 98 of file shape_line_chain.h.

◆ m_firstPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_firstPoint
private

Definition at line 97 of file shape_line_chain.h.

◆ m_lastPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_lastPoint
private

Definition at line 96 of file shape_line_chain.h.

◆ m_point

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_point
private

Definition at line 95 of file shape_line_chain.h.

◆ m_state

int SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_state
private

Definition at line 99 of file shape_line_chain.h.


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