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 117 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 1719 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 1790 of file shape_line_chain.cpp.

1791 {
1792  if( !m_count )
1793  {
1794  m_lastPoint = aPolyline.CPoint( 0 );
1795  m_firstPoint = aPolyline.CPoint( 0 );
1796  }
1797 
1798  m_count += aPolyline.PointCount();
1799 
1800  for( int i = 1; i < aPolyline.PointCount(); i++ )
1801  {
1802  auto p = aPolyline.CPoint( i );
1803 
1804  if( !processVertex( m_lastPoint, p ) )
1805  return;
1806 
1807  m_lastPoint = p;
1808  }
1809 
1810 }
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 1813 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 1728 of file shape_line_chain.cpp.

1730 {
1731  if( ipNext.y == m_point.y )
1732  {
1733  if( ( ipNext.x == m_point.x )
1734  || ( ip.y == m_point.y && ( ( ipNext.x > m_point.x ) == ( ip.x < m_point.x ) ) ) )
1735  {
1736  m_finished = true;
1737  m_state = -1;
1738  return false;
1739  }
1740  }
1741 
1742  if( ( ip.y < m_point.y ) != ( ipNext.y < m_point.y ) )
1743  {
1744  if( ip.x >= m_point.x )
1745  {
1746  if( ipNext.x > m_point.x )
1747  {
1748  m_state = 1 - m_state;
1749  }
1750  else
1751  {
1752  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1753  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1754 
1755  if( !d )
1756  {
1757  m_finished = true;
1758  m_state = -1;
1759  return false;
1760  }
1761 
1762  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1763  m_state = 1 - m_state;
1764  }
1765  }
1766  else
1767  {
1768  if( ipNext.x > m_point.x )
1769  {
1770  double d = (double) ( ip.x - m_point.x ) * ( ipNext.y - m_point.y )
1771  - (double) ( ipNext.x - m_point.x ) * ( ip.y - m_point.y );
1772 
1773  if( !d )
1774  {
1775  m_finished = true;
1776  m_state = -1;
1777  return false;
1778  }
1779 
1780  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1781  m_state = 1 - m_state;
1782  }
1783  }
1784  }
1785 
1786  return true;
1787 }

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

◆ m_finished

bool SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_finished
private

Definition at line 132 of file shape_line_chain.h.

◆ m_firstPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_firstPoint
private

Definition at line 131 of file shape_line_chain.h.

◆ m_lastPoint

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_lastPoint
private

Definition at line 130 of file shape_line_chain.h.

◆ m_point

VECTOR2I SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_point
private

Definition at line 129 of file shape_line_chain.h.

◆ m_state

int SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::m_state
private

Definition at line 133 of file shape_line_chain.h.


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