KiCad PCB EDA Suite
shape_poly_set.cpp File Reference
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <istream>
#include <limits>
#include <memory>
#include <set>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <vector>
#include <clipper.hpp>
#include <geometry/geometry_utils.h>
#include <geometry/polygon_triangulation.h>
#include <geometry/seg.h>
#include <geometry/shape.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_poly_set.h>
#include <math/box2.h>
#include <math/util.h>
#include <math/vector2d.h>
#include <md5_hash.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 668 of file shape_poly_set.cpp.

Function Documentation

◆ processEdge()

static int processEdge ( FractureEdgeSet edges,
FractureEdge edge 
)
static

Definition at line 671 of file shape_poly_set.cpp.

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

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

Referenced by SHAPE_POLY_SET::fractureSingle().