KiCad PCB EDA Suite
SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER Class Reference

A dynamic state checking if a point lies within polygon with a dynamically built outline ( with each piece of the outline added by AddPolyline () 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

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 121 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 2043 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 2114 of file shape_line_chain.cpp.

2115 {
2116  if( !m_count )
2117  {
2118  m_lastPoint = aPolyline.CPoint( 0 );
2119  m_firstPoint = aPolyline.CPoint( 0 );
2120  }
2121 
2122  m_count += aPolyline.PointCount();
2123 
2124  for( int i = 1; i < aPolyline.PointCount(); i++ )
2125  {
2126  auto p = aPolyline.CPoint( i );
2127 
2128  if( !processVertex( m_lastPoint, p ) )
2129  return;
2130 
2131  m_lastPoint = p;
2132  }
2133 
2134 }
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
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 2137 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 2052 of file shape_line_chain.cpp.

2054 {
2055  if( ipNext.y == m_point.y )
2056  {
2057  if( ( ipNext.x == m_point.x )
2058  || ( ip.y == m_point.y && ( ( ipNext.x > m_point.x ) == ( ip.x < m_point.x ) ) ) )
2059  {
2060  m_finished = true;
2061  m_state = -1;
2062  return false;
2063  }
2064  }
2065 
2066  if( ( ip.y < m_point.y ) != ( ipNext.y < m_point.y ) )
2067  {
2068  if( ip.x >= m_point.x )
2069  {
2070  if( ipNext.x > m_point.x )
2071  {
2072  m_state = 1 - m_state;
2073  }
2074  else
2075  {
2076  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
2077  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
2078 
2079  if( !d )
2080  {
2081  m_finished = true;
2082  m_state = -1;
2083  return false;
2084  }
2085 
2086  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
2087  m_state = 1 - m_state;
2088  }
2089  }
2090  else
2091  {
2092  if( ipNext.x > m_point.x )
2093  {
2094  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
2095  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
2096 
2097  if( !d )
2098  {
2099  m_finished = true;
2100  m_state = -1;
2101  return false;
2102  }
2103 
2104  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
2105  m_state = 1 - m_state;
2106  }
2107  }
2108  }
2109 
2110  return true;
2111 }

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

◆ m_finished

bool SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_finished
private

Definition at line 136 of file shape_line_chain.h.

◆ m_firstPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_firstPoint
private

Definition at line 135 of file shape_line_chain.h.

◆ m_lastPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_lastPoint
private

Definition at line 134 of file shape_line_chain.h.

◆ m_point

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_point
private

Definition at line 133 of file shape_line_chain.h.

◆ m_state

int SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_state
private

Definition at line 137 of file shape_line_chain.h.


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