KiCad PCB EDA Suite
shape_poly_set.cpp File Reference
#include <vector>
#include <cstdio>
#include <set>
#include <list>
#include <algorithm>
#include <common.h>
#include <geometry/shape.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_poly_set.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

#define SEG_CNT_MAX   64

Referenced by SHAPE_POLY_SET::Inflate().

Typedef Documentation

typedef std::vector<FractureEdge*> FractureEdgeSet

Definition at line 679 of file shape_poly_set.cpp.

Function Documentation

static int processEdge ( FractureEdgeSet edges,
FractureEdge edge 
)
static

Definition at line 682 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().

683 {
684  int x = edge->m_p1.x;
685  int y = edge->m_p1.y;
686  int min_dist = std::numeric_limits<int>::max();
687  int x_nearest = 0;
688 
689  FractureEdge* e_nearest = NULL;
690 
691  for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i )
692  {
693  if( !(*i)->matches( y ) )
694  continue;
695 
696  int x_intersect;
697 
698  if( (*i)->m_p1.y == (*i)->m_p2.y ) // horizontal edge
699  x_intersect = std::max ( (*i)->m_p1.x, (*i)->m_p2.x );
700  else
701  x_intersect = (*i)->m_p1.x + rescale((*i)->m_p2.x - (*i)->m_p1.x, y - (*i)->m_p1.y, (*i)->m_p2.y - (*i)->m_p1.y );
702 
703  int dist = ( x - x_intersect );
704 
705  if( dist >= 0 && dist < min_dist && (*i)->m_connected )
706  {
707  min_dist = dist;
708  x_nearest = x_intersect;
709  e_nearest = (*i);
710  }
711  }
712 
713  if( e_nearest && e_nearest->m_connected )
714  {
715  int count = 0;
716 
717  FractureEdge* lead1 = new FractureEdge( true, VECTOR2I( x_nearest, y ), VECTOR2I( x, y ) );
718  FractureEdge* lead2 = new FractureEdge( true, VECTOR2I( x, y ), VECTOR2I( x_nearest, y ) );
719  FractureEdge* split_2 = new FractureEdge( true, VECTOR2I( x_nearest, y ), e_nearest->m_p2 );
720 
721  edges.push_back( split_2 );
722  edges.push_back( lead1 );
723  edges.push_back( lead2 );
724 
725  FractureEdge* link = e_nearest->m_next;
726 
727  e_nearest->m_p2 = VECTOR2I( x_nearest, y );
728  e_nearest->m_next = lead1;
729  lead1->m_next = edge;
730 
731  FractureEdge*last;
732  for( last = edge; last->m_next != edge; last = last->m_next )
733  {
734  last->m_connected = true;
735  count++;
736  }
737 
738  last->m_connected = true;
739  last->m_next = lead2;
740  lead2->m_next = split_2;
741  split_2->m_next = link;
742 
743  return count + 1;
744  }
745 
746  return 0;
747 }
static const int dist[10][10]
Definition: dist.cpp:57
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
int rescale(int aNumerator, int aValue, int aDenominator)
Definition: math_util.cpp:32
#define max(a, b)
Definition: auxiliary.h:86
FractureEdge * m_next