KiCad PCB EDA Suite
tracks_cleaner.cpp File Reference

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

#include <fctsys.h>
#include <class_drawpanel.h>
#include <pcb_edit_frame.h>
#include <pcbnew.h>
#include <class_board.h>
#include <class_track.h>
#include <dialog_cleaning_options.h>
#include <board_commit.h>
#include <connectivity/connectivity_algo.h>
#include <connectivity/connectivity_data.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.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, const 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 tracks_cleaner.cpp.

Function Documentation

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

Definition at line 584 of file tracks_cleaner.cpp.

Referenced by TRACKS_CLEANER::mergeCollinearSegmentIfPossible().

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

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

Referenced by TRACKS_CLEANER::mergeCollinearSegmentIfPossible().

625 {
626  for( auto pad : connectivity->GetConnectedPads( track ) )
627  {
628  if( pad->HitTest( track->GetStart() ) )
629  {
630  track->SetState( START_ON_PAD, true );
631  }
632 
633  if( pad->HitTest( track->GetEnd() ) )
634  {
635  track->SetState( END_ON_PAD, true );
636  }
637  }
638 }
const wxPoint & GetEnd() const
Definition: class_track.h:119
#define START_ON_PAD
Definition: netinfo.h:590
const wxPoint & GetStart() const
Definition: class_track.h:122
#define END_ON_PAD
Definition: netinfo.h:591
void SetState(int type, int state)
Definition: base_struct.h:245