KiCad PCB EDA Suite
clean.cpp File Reference

functions to clean tracks: remove null length and redundant segments More...

#include <fctsys.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <pcbnew.h>
#include <class_board.h>
#include <class_track.h>
#include <dialog_cleaning_options.h>
#include <board_commit.h>
#include <connectivity.h>
#include <connectivity_algo.h>

Go to the source code of this file.

Classes

class  TRACKS_CLEANER
 

Functions

static bool parallelismTest (int dx1, int dy1, int dx2, int dy2)
 
static void updateConn (TRACK *track, std::shared_ptr< CONNECTIVITY_DATA > connectivity)
 Function used by cleanupSegments. More...
 

Detailed Description

functions to clean tracks: remove null length and redundant segments

Definition in file clean.cpp.

Function Documentation

static bool parallelismTest ( int  dx1,
int  dy1,
int  dx2,
int  dy2 
)
static

Definition at line 574 of file clean.cpp.

Referenced by TRACKS_CLEANER::mergeCollinearSegmentIfPossible().

575 {
576  /* The following condition list is ugly and repetitive, but I have
577  * not a better way to express clearly the trivial cases. Hope the
578  * compiler optimize it better than always doing the product
579  * below... */
580 
581  // test for vertical alignment (easy to handle)
582  if( dx1 == 0 )
583  return dx2 == 0;
584 
585  if( dx2 == 0 )
586  return dx1 == 0;
587 
588  // test for horizontal alignment (easy to handle)
589  if( dy1 == 0 )
590  return dy2 == 0;
591 
592  if( dy2 == 0 )
593  return dy1 == 0;
594 
595  /* test for alignment in other cases: Do the usual cross product test
596  * (the same as testing the slope, but without a division) */
597  return ((double)dy1 * dx2 == (double)dx1 * dy2);
598 }
static void updateConn ( TRACK track,
std::shared_ptr< CONNECTIVITY_DATA connectivity 
)
static

Function used by cleanupSegments.

Test if aTrackRef and aCandidate (which must have a common end) are collinear. and see if the common point is not on a pad (i.e. if this common point can be removed). the ending point of aTrackRef is the start point (aEndType == START) or the end point (aEndType != START) flags START_ON_PAD and END_ON_PAD must be set before calling this function if the common point can be deleted, this function change the common point coordinate of the aTrackRef segm (and therefore connect the 2 other ending points) and return aCandidate (which can be deleted). else return NULL

Definition at line 614 of file clean.cpp.

References END_ON_PAD, TRACK::GetEnd(), TRACK::GetStart(), EDA_ITEM::SetState(), and START_ON_PAD.

Referenced by TRACKS_CLEANER::mergeCollinearSegmentIfPossible().

615 {
616  for( auto pad : connectivity->GetConnectedPads( track ) )
617  {
618  if( pad->HitTest( track->GetStart() ) )
619  {
620  track->SetState( START_ON_PAD, true );
621  }
622 
623  if( pad->HitTest( track->GetEnd() ) )
624  {
625  track->SetState( END_ON_PAD, true );
626  }
627  }
628 }
#define END_ON_PAD
#define START_ON_PAD
const wxPoint & GetEnd() const
Definition: class_track.h:118
const wxPoint & GetStart() const
Definition: class_track.h:121
void SetState(int type, int state)
Definition: base_struct.h:256