KiCad PCB EDA Suite
shape_poly_set.cpp File Reference
#include <vector>
#include <cstdio>
#include <set>
#include <list>
#include <algorithm>
#include <unordered_set>
#include <common.h>
#include <md5_hash.h>
#include <map>
#include <geometry/shape.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_poly_set.h>
#include "poly2tri/poly2tri.h"

Go to the source code of this file.

Classes

struct  FractureEdge
 
class  SHAPE_POLY_SET::TRIANGULATION_CONTEXT
 
class  SHAPE_POLY_SET::TRIANGULATION_CONTEXT::comparePoints
 

Macros

#define SEG_CNT_MAX   64
 

Typedefs

typedef std::vector< FractureEdge * > FractureEdgeSet
 

Functions

static int processEdge (FractureEdgeSet &edges, FractureEdge *edge)
 
static int totalVertexCount (const SHAPE_POLY_SET::POLYGON &aPoly)
 

Macro Definition Documentation

#define SEG_CNT_MAX   64

Referenced by SHAPE_POLY_SET::Inflate().

Typedef Documentation

typedef std::vector<FractureEdge*> FractureEdgeSet

Definition at line 699 of file shape_poly_set.cpp.

Function Documentation

static int processEdge ( FractureEdgeSet edges,
FractureEdge edge 
)
static

Definition at line 702 of file shape_poly_set.cpp.

References dist, FractureEdge::m_connected, FractureEdge::m_next, FractureEdge::m_p1, FractureEdge::m_p2, max, rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SHAPE_POLY_SET::fractureSingle().

703 {
704  int x = edge->m_p1.x;
705  int y = edge->m_p1.y;
706  int min_dist = std::numeric_limits<int>::max();
707  int x_nearest = 0;
708 
709  FractureEdge* e_nearest = NULL;
710 
711  for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i )
712  {
713  if( !(*i)->matches( y ) )
714  continue;
715 
716  int x_intersect;
717 
718  if( (*i)->m_p1.y == (*i)->m_p2.y ) // horizontal edge
719  x_intersect = std::max( (*i)->m_p1.x, (*i)->m_p2.x );
720  else
721  x_intersect = (*i)->m_p1.x + rescale( (*i)->m_p2.x - (*i)->m_p1.x, y - (*i)->m_p1.y,
722  (*i)->m_p2.y - (*i)->m_p1.y );
723 
724  int dist = ( x - x_intersect );
725 
726  if( dist >= 0 && dist < min_dist && (*i)->m_connected )
727  {
728  min_dist = dist;
729  x_nearest = x_intersect;
730  e_nearest = (*i);
731  }
732  }
733 
734  if( e_nearest && e_nearest->m_connected )
735  {
736  int count = 0;
737 
738  FractureEdge* lead1 =
739  new FractureEdge( true, VECTOR2I( x_nearest, y ), VECTOR2I( x, y ) );
740  FractureEdge* lead2 =
741  new FractureEdge( true, VECTOR2I( x, y ), VECTOR2I( x_nearest, y ) );
742  FractureEdge* split_2 =
743  new FractureEdge( true, VECTOR2I( x_nearest, y ), e_nearest->m_p2 );
744 
745  edges.push_back( split_2 );
746  edges.push_back( lead1 );
747  edges.push_back( lead2 );
748 
749  FractureEdge* link = e_nearest->m_next;
750 
751  e_nearest->m_p2 = VECTOR2I( x_nearest, y );
752  e_nearest->m_next = lead1;
753  lead1->m_next = edge;
754 
755  FractureEdge* last;
756 
757  for( last = edge; last->m_next != edge; last = last->m_next )
758  {
759  last->m_connected = true;
760  count++;
761  }
762 
763  last->m_connected = true;
764  last->m_next = lead2;
765  lead2->m_next = split_2;
766  split_2->m_next = link;
767 
768  return count + 1;
769  }
770 
771  return 0;
772 }
static const int dist[10][10]
Definition: dist.cpp:57
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
int rescale(int aNumerator, int aValue, int aDenominator)
Definition: math_util.cpp:32
#define max(a, b)
Definition: auxiliary.h:86
FractureEdge * m_next
static int totalVertexCount ( const SHAPE_POLY_SET::POLYGON aPoly)
static

Definition at line 2025 of file shape_poly_set.cpp.

Referenced by SHAPE_POLY_SET::triangulateSingle().

2026 {
2027  int cnt = 0;
2028 
2029  for( const auto& outl : aPoly )
2030  {
2031  cnt += outl.PointCount();
2032  }
2033 
2034  return cnt;
2035 }