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 1039 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 1109 of file shape_line_chain.cpp.

1110 {
1111  if( !m_count )
1112  {
1113  m_lastPoint = aPolyline.CPoint(0);
1114  m_firstPoint = aPolyline.CPoint(0);
1115  }
1116 
1117  m_count += aPolyline.PointCount();
1118 
1119  for (int i = 1; i < aPolyline.PointCount(); i++ )
1120  {
1121  auto p = aPolyline.CPoint( i );
1122  if( !processVertex( m_lastPoint, p ))
1123  return;
1124 
1125  m_lastPoint = p;
1126  }
1127 
1128 }
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::checkBumpDirection().

◆ IsInside()

bool SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::IsInside ( )

Definition at line 1131 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 1048 of file shape_line_chain.cpp.

1050 {
1051  if( ipNext.y == m_point.y )
1052  {
1053  if( ( ipNext.x == m_point.x )
1054  || ( ip.y == m_point.y && ( ( ipNext.x > m_point.x ) == ( ip.x < m_point.x ) ) ) )
1055  {
1056  m_finished = true;
1057  m_state = -1;
1058  return false;
1059  }
1060  }
1061 
1062  if( ( ip.y < m_point.y ) != ( ipNext.y < m_point.y ) )
1063  {
1064  if( ip.x >= m_point.x )
1065  {
1066  if( ipNext.x > m_point.x )
1067  {
1068  m_state = 1 - m_state;
1069  }
1070  else
1071  {
1072  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1073  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1074 
1075  if( !d )
1076  {
1077  m_finished = true;
1078  m_state = -1;
1079  return false;
1080  }
1081 
1082  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1083  m_state = 1 - m_state;
1084  }
1085  }
1086  else
1087  {
1088  if( ipNext.x > m_point.x )
1089  {
1090  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1091  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1092 
1093  if( !d )
1094  {
1095  m_finished = true;
1096  m_state = -1;
1097  return false;
1098  }
1099 
1100  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1101  m_state = 1 - m_state;
1102  }
1103  }
1104  }
1105  return true;
1106 }

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: