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_data.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 580 of file clean.cpp.

Referenced by TRACKS_CLEANER::mergeCollinearSegmentIfPossible().

581 {
582  /* The following condition list is ugly and repetitive, but I have
583  * not a better way to express clearly the trivial cases. Hope the
584  * compiler optimize it better than always doing the product
585  * below... */
586 
587  // test for vertical alignment (easy to handle)
588  if( dx1 == 0 )
589  return dx2 == 0;
590 
591  if( dx2 == 0 )
592  return dx1 == 0;
593 
594  // test for horizontal alignment (easy to handle)
595  if( dy1 == 0 )
596  return dy2 == 0;
597 
598  if( dy2 == 0 )
599  return dy1 == 0;
600 
601  /* test for alignment in other cases: Do the usual cross product test
602  * (the same as testing the slope, but without a division) */
603  return ((double)dy1 * dx2 == (double)dx1 * dy2);
604 }
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 620 of file clean.cpp.

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

Referenced by TRACKS_CLEANER::mergeCollinearSegmentIfPossible().

621 {
622  for( auto pad : connectivity->GetConnectedPads( track ) )
623  {
624  if( pad->HitTest( track->GetStart() ) )
625  {
626  track->SetState( START_ON_PAD, true );
627  }
628 
629  if( pad->HitTest( track->GetEnd() ) )
630  {
631  track->SetState( END_ON_PAD, true );
632  }
633  }
634 }
#define END_ON_PAD
#define START_ON_PAD
const wxPoint & GetEnd() const
Definition: class_track.h:120
const wxPoint & GetStart() const
Definition: class_track.h:123
void SetState(int type, int state)
Definition: base_struct.h:256