KiCad PCB EDA Suite
PNS::COST_ESTIMATOR Class Reference

Class COST_ESTIMATOR. More...

#include <pns_optimizer.h>

Public Member Functions

 COST_ESTIMATOR ()
 
 COST_ESTIMATOR (const COST_ESTIMATOR &aB)
 
 ~COST_ESTIMATOR ()
 
void Add (LINE &aLine)
 
void Remove (LINE &aLine)
 
void Replace (LINE &aOldLine, LINE &aNewLine)
 
bool IsBetter (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)
 Cost Estimator Methods. More...
 
static int CornerCost (const SHAPE_LINE_CHAIN &aLine)
 
static int CornerCost (const LINE &aLine)
 

Private Attributes

double m_lengthCost
 
int m_cornerCost
 

Detailed Description

Class COST_ESTIMATOR.

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

Definition at line 45 of file pns_optimizer.h.

Constructor & Destructor Documentation

PNS::COST_ESTIMATOR::COST_ESTIMATOR ( )
inline

Definition at line 48 of file pns_optimizer.h.

48  :
49  m_lengthCost( 0 ),
50  m_cornerCost( 0 )
51  {}
PNS::COST_ESTIMATOR::COST_ESTIMATOR ( const COST_ESTIMATOR aB)
inline

Definition at line 53 of file pns_optimizer.h.

53  :
54  m_lengthCost( aB.m_lengthCost ),
55  m_cornerCost( aB.m_cornerCost )
56  {}
PNS::COST_ESTIMATOR::~COST_ESTIMATOR ( )
inline

Definition at line 58 of file pns_optimizer.h.

58 {};

Member Function Documentation

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

Definition at line 85 of file pns_optimizer.cpp.

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

86 {
87  m_lengthCost += aLine.CLine().Length();
88  m_cornerCost += CornerCost( aLine );
89 }
static int CornerCost(const SEG &aA, const SEG &aB)
Cost Estimator Methods.
int PNS::COST_ESTIMATOR::CornerCost ( const SEG aA,
const SEG aB 
)
static

Cost Estimator Methods.

Definition at line 41 of file pns_optimizer.cpp.

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().

42 {
43  DIRECTION_45 dir_a( aA ), dir_b( aB );
44 
45  switch( dir_a.Angle( dir_b ) )
46  {
48  return 1;
49 
51  return 0;
52 
54  return 50;
55 
57  return 30;
58 
60  return 60;
61 
62  default:
63  return 100;
64  }
65 }
Class DIRECTION_45.
Definition: direction45.h:33
int PNS::COST_ESTIMATOR::CornerCost ( const SHAPE_LINE_CHAIN aLine)
static

Definition at line 68 of file pns_optimizer.cpp.

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

69 {
70  int total = 0;
71 
72  for( int i = 0; i < aLine.SegmentCount() - 1; ++i )
73  total += CornerCost( aLine.CSegment( i ), aLine.CSegment( i + 1 ) );
74 
75  return total;
76 }
const SEG CSegment(int aIndex) const
Function CSegment()
static int CornerCost(const SEG &aA, const SEG &aB)
Cost Estimator Methods.
int SegmentCount() const
Function SegmentCount()
int PNS::COST_ESTIMATOR::CornerCost ( const LINE aLine)
static

Definition at line 79 of file pns_optimizer.cpp.

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

80 {
81  return CornerCost( aLine.CLine() );
82 }
static int CornerCost(const SEG &aA, const SEG &aB)
Cost Estimator Methods.
double PNS::COST_ESTIMATOR::GetCornerCost ( ) const
inline

Definition at line 72 of file pns_optimizer.h.

References m_cornerCost.

72 { return m_cornerCost; }
double PNS::COST_ESTIMATOR::GetLengthCost ( ) const
inline

Definition at line 71 of file pns_optimizer.h.

References m_lengthCost.

71 { return m_lengthCost; }
bool PNS::COST_ESTIMATOR::IsBetter ( COST_ESTIMATOR aOther,
double  aLengthTolerance,
double  aCornerTollerace 
) const

Definition at line 108 of file pns_optimizer.cpp.

References m_cornerCost, and m_lengthCost.

111 {
112  if( aOther.m_cornerCost < m_cornerCost && aOther.m_lengthCost < m_lengthCost )
113  return true;
114 
115  else if( aOther.m_cornerCost < m_cornerCost * aCornerTolerance &&
116  aOther.m_lengthCost < m_lengthCost * aLengthTolerance )
117  return true;
118 
119  return false;
120 }
void PNS::COST_ESTIMATOR::Remove ( LINE aLine)

Definition at line 92 of file pns_optimizer.cpp.

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

93 {
94  m_lengthCost -= aLine.CLine().Length();
95  m_cornerCost -= CornerCost( aLine );
96 }
static int CornerCost(const SEG &aA, const SEG &aB)
Cost Estimator Methods.
void PNS::COST_ESTIMATOR::Replace ( LINE aOldLine,
LINE aNewLine 
)

Definition at line 99 of file pns_optimizer.cpp.

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

100 {
101  m_lengthCost -= aOldLine.CLine().Length();
102  m_cornerCost -= CornerCost( aOldLine );
103  m_lengthCost += aNewLine.CLine().Length();
104  m_cornerCost += CornerCost( aNewLine );
105 }
static int CornerCost(const SEG &aA, const SEG &aB)
Cost Estimator Methods.

Member Data Documentation

int PNS::COST_ESTIMATOR::m_cornerCost
private

Definition at line 76 of file pns_optimizer.h.

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

double PNS::COST_ESTIMATOR::m_lengthCost
private

Definition at line 75 of file pns_optimizer.h.

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


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