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

Go to the source code of this file.

Classes

struct  FractureEdge
 

Macros

#define SEG_CNT_MAX   64
 

Typedefs

typedef std::vector< FractureEdge * > FractureEdgeSet
 

Functions

static int processEdge (FractureEdgeSet &edges, FractureEdge *edge)
 

Macro Definition Documentation

◆ SEG_CNT_MAX

#define SEG_CNT_MAX   64

Typedef Documentation

◆ FractureEdgeSet

typedef std::vector<FractureEdge*> FractureEdgeSet

Definition at line 657 of file shape_poly_set.cpp.

Function Documentation

◆ processEdge()

static int processEdge ( FractureEdgeSet edges,
FractureEdge edge 
)
static

Definition at line 660 of file shape_poly_set.cpp.

661 {
662  int x = edge->m_p1.x;
663  int y = edge->m_p1.y;
664  int min_dist = std::numeric_limits<int>::max();
665  int x_nearest = 0;
666 
667  FractureEdge* e_nearest = NULL;
668 
669  for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i )
670  {
671  if( !(*i)->matches( y ) )
672  continue;
673 
674  int x_intersect;
675 
676  if( (*i)->m_p1.y == (*i)->m_p2.y ) // horizontal edge
677  x_intersect = std::max( (*i)->m_p1.x, (*i)->m_p2.x );
678  else
679  x_intersect = (*i)->m_p1.x + rescale( (*i)->m_p2.x - (*i)->m_p1.x, y - (*i)->m_p1.y,
680  (*i)->m_p2.y - (*i)->m_p1.y );
681 
682  int dist = ( x - x_intersect );
683 
684  if( dist >= 0 && dist < min_dist && (*i)->m_connected )
685  {
686  min_dist = dist;
687  x_nearest = x_intersect;
688  e_nearest = (*i);
689  }
690  }
691 
692  if( e_nearest && e_nearest->m_connected )
693  {
694  int count = 0;
695 
696  FractureEdge* lead1 =
697  new FractureEdge( true, VECTOR2I( x_nearest, y ), VECTOR2I( x, y ) );
698  FractureEdge* lead2 =
699  new FractureEdge( true, VECTOR2I( x, y ), VECTOR2I( x_nearest, y ) );
700  FractureEdge* split_2 =
701  new FractureEdge( true, VECTOR2I( x_nearest, y ), e_nearest->m_p2 );
702 
703  edges.push_back( split_2 );
704  edges.push_back( lead1 );
705  edges.push_back( lead2 );
706 
707  FractureEdge* link = e_nearest->m_next;
708 
709  e_nearest->m_p2 = VECTOR2I( x_nearest, y );
710  e_nearest->m_next = lead1;
711  lead1->m_next = edge;
712 
713  FractureEdge* last;
714 
715  for( last = edge; last->m_next != edge; last = last->m_next )
716  {
717  last->m_connected = true;
718  count++;
719  }
720 
721  last->m_connected = true;
722  last->m_next = lead2;
723  lead2->m_next = split_2;
724  split_2->m_next = link;
725 
726  return count + 1;
727  }
728 
729  return 0;
730 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
#define max(a, b)
Definition: auxiliary.h:86
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
FractureEdge * m_next
size_t i
Definition: json11.cpp:597

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

Referenced by SHAPE_POLY_SET::fractureSingle().