KiCad PCB EDA Suite
PNS::COST_ESTIMATOR Class Reference

Calculate the cost of a given line, taking corner angles and total length into account. More...

#include <pns_optimizer.h>

Public Member Functions

 COST_ESTIMATOR ()
 
 COST_ESTIMATOR (const COST_ESTIMATOR &aB)
 
 ~COST_ESTIMATOR ()
 
void Add (const LINE &aLine)
 
void Remove (const LINE &aLine)
 
void Replace (const LINE &aOldLine, const LINE &aNewLine)
 
bool IsBetter (const COST_ESTIMATOR &aOther, double aLengthTolerance, double aCornerTollerace) const
 
double GetLengthCost () const
 
double GetCornerCost () const
 

Static Public Member Functions

static int CornerCost (const SEG &aA, const SEG &aB)
 
static int CornerCost (const SHAPE_LINE_CHAIN &aLine)
 
static int CornerCost (const LINE &aLine)
 

Private Attributes

double m_lengthCost
 
int m_cornerCost
 

Detailed Description

Calculate the cost of a given line, taking corner angles and total length into account.

Definition at line 48 of file pns_optimizer.h.

Constructor & Destructor Documentation

◆ COST_ESTIMATOR() [1/2]

PNS::COST_ESTIMATOR::COST_ESTIMATOR ( )
inline

Definition at line 51 of file pns_optimizer.h.

51  :
52  m_lengthCost( 0 ),
53  m_cornerCost( 0 )
54  {}

◆ COST_ESTIMATOR() [2/2]

PNS::COST_ESTIMATOR::COST_ESTIMATOR ( const COST_ESTIMATOR aB)
inline

Definition at line 56 of file pns_optimizer.h.

56  :
57  m_lengthCost( aB.m_lengthCost ),
58  m_cornerCost( aB.m_cornerCost )
59  {}

◆ ~COST_ESTIMATOR()

PNS::COST_ESTIMATOR::~COST_ESTIMATOR ( )
inline

Definition at line 61 of file pns_optimizer.h.

61 {};

Member Function Documentation

◆ Add()

void PNS::COST_ESTIMATOR::Add ( const LINE aLine)

Definition at line 76 of file pns_optimizer.cpp.

77 {
78  m_lengthCost += aLine.CLine().Length();
79  m_cornerCost += CornerCost( aLine );
80 }
static int CornerCost(const SEG &aA, const SEG &aB)

References PNS::LINE::CLine(), CornerCost(), SHAPE_LINE_CHAIN::Length(), m_cornerCost, and m_lengthCost.

◆ CornerCost() [1/3]

int PNS::COST_ESTIMATOR::CornerCost ( const SEG aA,
const SEG aB 
)
static

Definition at line 43 of file pns_optimizer.cpp.

44 {
45  DIRECTION_45 dir_a( aA ), dir_b( aB );
46 
47  switch( dir_a.Angle( dir_b ) )
48  {
49  case DIRECTION_45::ANG_OBTUSE: return 10;
50  case DIRECTION_45::ANG_STRAIGHT: return 5;
51  case DIRECTION_45::ANG_ACUTE: return 50;
52  case DIRECTION_45::ANG_RIGHT: return 30;
53  case DIRECTION_45::ANG_HALF_FULL: return 60;
54  default: return 100;
55  }
56 }
Represent route directions & corner angles in a 45-degree metric.
Definition: direction45.h:36

References DIRECTION_45::ANG_ACUTE, DIRECTION_45::ANG_HALF_FULL, DIRECTION_45::ANG_OBTUSE, DIRECTION_45::ANG_RIGHT, and DIRECTION_45::ANG_STRAIGHT.

Referenced by Add(), CornerCost(), PNS::OPTIMIZER::mergeStep(), Remove(), Replace(), and PNS::OPTIMIZER::smartPadsSingle().

◆ CornerCost() [2/3]

int PNS::COST_ESTIMATOR::CornerCost ( const SHAPE_LINE_CHAIN aLine)
static

Definition at line 59 of file pns_optimizer.cpp.

60 {
61  int total = 0;
62 
63  for( int i = 0; i < aLine.SegmentCount() - 1; ++i )
64  total += CornerCost( aLine.CSegment( i ), aLine.CSegment( i + 1 ) );
65 
66  return total;
67 }
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
static int CornerCost(const SEG &aA, const SEG &aB)

References CornerCost(), SHAPE_LINE_CHAIN::CSegment(), and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by CornerCost().

◆ CornerCost() [3/3]

int PNS::COST_ESTIMATOR::CornerCost ( const LINE aLine)
static

Definition at line 70 of file pns_optimizer.cpp.

71 {
72  return CornerCost( aLine.CLine() );
73 }
static int CornerCost(const SEG &aA, const SEG &aB)

References PNS::LINE::CLine(), and CornerCost().

◆ GetCornerCost()

double PNS::COST_ESTIMATOR::GetCornerCost ( ) const
inline

Definition at line 75 of file pns_optimizer.h.

75 { return m_cornerCost; }

References m_cornerCost.

◆ GetLengthCost()

double PNS::COST_ESTIMATOR::GetLengthCost ( ) const
inline

Definition at line 74 of file pns_optimizer.h.

74 { return m_lengthCost; }

References m_lengthCost.

◆ IsBetter()

bool PNS::COST_ESTIMATOR::IsBetter ( const COST_ESTIMATOR aOther,
double  aLengthTolerance,
double  aCornerTollerace 
) const

Definition at line 99 of file pns_optimizer.cpp.

101 {
102  if( aOther.m_cornerCost < m_cornerCost && aOther.m_lengthCost < m_lengthCost )
103  return true;
104  else if( aOther.m_cornerCost < m_cornerCost * aCornerTolerance &&
105  aOther.m_lengthCost < m_lengthCost * aLengthTolerance )
106  return true;
107 
108  return false;
109 }

References m_cornerCost, and m_lengthCost.

◆ Remove()

void PNS::COST_ESTIMATOR::Remove ( const LINE aLine)

Definition at line 83 of file pns_optimizer.cpp.

84 {
85  m_lengthCost -= aLine.CLine().Length();
86  m_cornerCost -= CornerCost( aLine );
87 }
static int CornerCost(const SEG &aA, const SEG &aB)

References PNS::LINE::CLine(), CornerCost(), SHAPE_LINE_CHAIN::Length(), m_cornerCost, and m_lengthCost.

◆ Replace()

void PNS::COST_ESTIMATOR::Replace ( const LINE aOldLine,
const LINE aNewLine 
)

Definition at line 90 of file pns_optimizer.cpp.

91 {
92  m_lengthCost -= aOldLine.CLine().Length();
93  m_cornerCost -= CornerCost( aOldLine );
94  m_lengthCost += aNewLine.CLine().Length();
95  m_cornerCost += CornerCost( aNewLine );
96 }
static int CornerCost(const SEG &aA, const SEG &aB)

References PNS::LINE::CLine(), CornerCost(), SHAPE_LINE_CHAIN::Length(), m_cornerCost, and m_lengthCost.

Member Data Documentation

◆ m_cornerCost

int PNS::COST_ESTIMATOR::m_cornerCost
private

Definition at line 79 of file pns_optimizer.h.

Referenced by Add(), GetCornerCost(), IsBetter(), Remove(), and Replace().

◆ m_lengthCost

double PNS::COST_ESTIMATOR::m_lengthCost
private

Definition at line 78 of file pns_optimizer.h.

Referenced by Add(), GetLengthCost(), IsBetter(), Remove(), and Replace().


The documentation for this class was generated from the following files: