KiCad PCB EDA Suite
PNS::MEANDER_SHAPE Class Reference

Class MEANDER_SETTINGS. More...

#include <pns_meander.h>

Public Member Functions

 MEANDER_SHAPE (MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
 Constructor. More...
 
void SetType (MEANDER_TYPE aType)
 Function SetType() More...
 
MEANDER_TYPE Type () const
 Function Type() More...
 
void SetBaseIndex (int aIndex)
 Function SetBaseIndex() More...
 
int BaseIndex () const
 Function BaseIndex() More...
 
int Amplitude () const
 Function Amplitude() More...
 
void MakeCorner (VECTOR2I aP1, VECTOR2I aP2=VECTOR2I(0, 0))
 Function MakeCorner() More...
 
void Resize (int aAmpl)
 Function Resize() More...
 
void Recalculate ()
 Function Recalculate() More...
 
bool IsDual () const
 Function IsDual() More...
 
bool Side () const
 Function Side() More...
 
VECTOR2I End () const
 Function End() More...
 
const SHAPE_LINE_CHAINCLine (int aShape) const
 Function CLine() More...
 
void MakeEmpty ()
 Function MakeEmpty() More...
 
bool Fit (MEANDER_TYPE aType, const SEG &aSeg, const VECTOR2I &aP, bool aSide)
 Function Fit() More...
 
const SEGBaseSegment () const
 Function BaseSegment() More...
 
int BaselineLength () const
 Function BaselineLength() More...
 
int MaxTunableLength () const
 Function MaxTunableLength() More...
 
const MEANDER_SETTINGSSettings () const
 Function Settings() More...
 
int Width () const
 Function Width() More...
 
void SetBaselineOffset (int aOffset)
 Function SetBaselineOffset() More...
 

Private Member Functions

void start (SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
 

starts turtle drawing

More...
 
void forward (int aLength)
 

moves turtle forward by aLength

More...
 
void turn (int aAngle)
 

turns the turtle by aAngle

More...
 
void miter (int aRadius, bool aSide)
 

tells the turtle to draw a mitered corner of given radius and turn direction

More...
 
void uShape (int aSides, int aCorner, int aTop)
 

tells the turtle to draw an U-like shape

More...
 
SHAPE_LINE_CHAIN makeMiterShape (VECTOR2D aP, VECTOR2D aDir, bool aSide)
 

generates a 90-degree circular arc

More...
 
VECTOR2I reflect (VECTOR2I aP, const SEG &aLine)
 

reflects a point onto other side of a given segment

More...
 
SHAPE_LINE_CHAIN genMeanderShape (VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
 

produces a meander shape of given type

More...
 
void updateBaseSegment ()
 

recalculates the clipped baseline after the parameters of the meander have been changed.

More...
 
int cornerRadius () const
 

returns sanitized corner radius value

More...
 
int spacing () const
 

returns sanitized spacing value

More...
 

Private Attributes

MEANDER_TYPE m_type
 

the type

More...
 
MEANDER_PLACER_BASEm_placer
 

the placer that placed this meander

More...
 
bool m_dual
 

dual or single line

More...
 
int m_width
 

width of the line

More...
 
int m_amplitude
 

amplitude of the meander

More...
 
int m_baselineOffset
 

offset wrs the base segment (dual only)

More...
 
int m_meanCornerRadius
 

average radius of meander corners (for correction of DP meanders)

More...
 
VECTOR2I m_p0
 

first point of the meandered line

More...
 
SEG m_baseSeg
 

base segment (unclipped)

More...
 
SEG m_clippedBaseSeg
 

base segment (clipped)

More...
 
bool m_side
 

side (true = right)

More...
 
SHAPE_LINE_CHAIN m_shapes [2]
 

the actual shapes (0 used for single, both for dual)

More...
 
int m_baseIndex
 

index of the meandered segment in the base line

More...
 
VECTOR2D m_currentDir
 

current turtle direction

More...
 
VECTOR2D m_currentPos
 

current turtle position

More...
 
SHAPE_LINE_CHAINm_currentTarget
 

the line the turtle is drawing on

More...
 

Friends

class MEANDERED_LINE
 

Detailed Description

Class MEANDER_SETTINGS.

Holds the geometry of a single meander.

Definition at line 104 of file pns_meander.h.

Constructor & Destructor Documentation

PNS::MEANDER_SHAPE::MEANDER_SHAPE ( MEANDER_PLACER_BASE aPlacer,
int  aWidth,
bool  aIsDual = false 
)
inline

Constructor.

Parameters
aPlacerthe meander placer instance
aWidthwidth of the meandered line
aIsDualwhen true, the shape contains two meandered lines at a given offset (diff pairs)

Definition at line 115 of file pns_meander.h.

References m_amplitude, m_baseIndex, m_currentTarget, m_meanCornerRadius, m_side, m_type, and PNS::MT_SINGLE.

115  :
116  m_placer( aPlacer ),
117  m_dual( aIsDual ),
118  m_width( aWidth ),
119  m_baselineOffset( 0 )
120  {
121  // Do not leave unitialized members, and keep static analyser quiet:
122  m_type = MT_SINGLE;
123  m_amplitude = 0;
124  m_side = false;
125  m_baseIndex = 0;
126  m_currentTarget = NULL;
127  m_meanCornerRadius = 0;
128  }
bool m_side
side (true = right)
Definition: pns_meander.h:376
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:386
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:380
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:356
int m_meanCornerRadius
average radius of meander corners (for correction of DP meanders)
Definition: pns_meander.h:368
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:358
int m_width
width of the line
Definition: pns_meander.h:362
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:364
bool m_dual
dual or single line
Definition: pns_meander.h:360

Member Function Documentation

int PNS::MEANDER_SHAPE::Amplitude ( ) const
inline

Function Amplitude()

Returns
the amplitude of the meander shape.

Definition at line 175 of file pns_meander.h.

References m_amplitude.

Referenced by Fit().

176  {
177  return m_amplitude;
178  }
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:364
int PNS::MEANDER_SHAPE::BaseIndex ( ) const
inline

Function BaseIndex()

Returns
auxillary index of the segment being meandered in its original LINE.

Definition at line 165 of file pns_meander.h.

References m_baseIndex.

166  {
167  return m_baseIndex;
168  }
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:380
int PNS::MEANDER_SHAPE::BaselineLength ( ) const

Function BaselineLength()

Returns
length of the base segment for the meander (i.e. the minimum tuned length.

Definition at line 614 of file pns_meander.cpp.

References SEG::Length(), and m_clippedBaseSeg.

615 {
616  return m_clippedBaseSeg.Length();
617 }
int Length() const
Function Length()
Definition: seg.h:325
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
const SEG& PNS::MEANDER_SHAPE::BaseSegment ( ) const
inline

Function BaseSegment()

Returns the base segment the meadner was fitted to.

Returns
the base segment.

Definition at line 273 of file pns_meander.h.

References m_clippedBaseSeg.

Referenced by PNS::MEANDERED_LINE::AddMeander(), and PNS::MEANDERED_LINE::CheckSelfIntersections().

274  {
275  return m_clippedBaseSeg;
276  }
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
const SHAPE_LINE_CHAIN& PNS::MEANDER_SHAPE::CLine ( int  aShape) const
inline

Function CLine()

Returns
the line chain representing the shape of the meander.

Definition at line 241 of file pns_meander.h.

References m_shapes.

Referenced by PNS::MEANDER_PLACER::CheckFit(), PNS::DP_MEANDER_PLACER::CheckFit(), PNS::MEANDERED_LINE::CheckSelfIntersections(), MaxTunableLength(), and updateBaseSegment().

242  {
243  return m_shapes[aShape];
244  }
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:378
int PNS::MEANDER_SHAPE::cornerRadius ( ) const
private

returns sanitized corner radius value

Definition at line 168 of file pns_meander.cpp.

References PNS::MEANDER_SETTINGS::m_cornerRadiusPercentage, Settings(), and spacing().

Referenced by genMeanderShape(), and PNS::MEANDERED_LINE::MeanderSegment().

169 {
170  return (int64_t) spacing() * Settings().m_cornerRadiusPercentage / 200;
171 }
int spacing() const
returns sanitized spacing value
int m_cornerRadiusPercentage
rounding percentage (0 - 100)
Definition: pns_meander.h:88
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
VECTOR2I PNS::MEANDER_SHAPE::End ( ) const
inline

Function End()

Returns
end vertex of the base segment of the meander shape.

Definition at line 231 of file pns_meander.h.

References SEG::B, and m_clippedBaseSeg.

Referenced by Fit().

232  {
233  return m_clippedBaseSeg.B;
234  }
VECTOR2I & B
Definition: seg.h:52
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
bool PNS::MEANDER_SHAPE::Fit ( MEANDER_TYPE  aType,
const SEG aSeg,
const VECTOR2I aP,
bool  aSide 
)

Function Fit()

Attempts to fit a meander of a given type onto a segment, avoiding collisions with other board features.

Parameters
aTypetype of meander shape
aSegbase segment for meandering
aPstart point of the meander
aSideside of aSeg to put the meander on (true = right)
Returns
true on success.

Definition at line 446 of file pns_meander.cpp.

References SEG::A, abs, Amplitude(), SEG::B, PNS::MEANDER_PLACER_BASE::CheckFit(), End(), Fit(), genMeanderShape(), m_amplitude, m_baseIndex, m_baselineOffset, m_baseSeg, m_dual, PNS::MEANDER_SETTINGS::m_maxAmplitude, PNS::MEANDER_SETTINGS::m_minAmplitude, m_p0, m_placer, m_shapes, m_side, PNS::MEANDER_SETTINGS::m_step, m_type, m_width, max, PNS::MT_CHECK_FINISH, PNS::MT_CHECK_START, PNS::MT_FINISH, PNS::MT_START, PNS::MT_TURN, SetBaselineOffset(), Settings(), and updateBaseSegment().

Referenced by Fit(), and PNS::MEANDERED_LINE::MeanderSegment().

447 {
448  const MEANDER_SETTINGS& st = Settings();
449 
450  bool checkMode = false;
451  MEANDER_TYPE prim1, prim2;
452 
453  if( aType == MT_CHECK_START )
454  {
455  prim1 = MT_START;
456  prim2 = MT_TURN;
457  checkMode = true;
458  }
459  else if( aType == MT_CHECK_FINISH )
460  {
461  prim1 = MT_TURN;
462  prim2 = MT_FINISH;
463  checkMode = true;
464  }
465 
466  if( checkMode )
467  {
470 
471  m1.SetBaselineOffset( m_baselineOffset );
472  m2.SetBaselineOffset( m_baselineOffset );
473 
474  bool c1 = m1.Fit( prim1, aSeg, aP, aSide );
475  bool c2 = false;
476 
477  if( c1 )
478  c2 = m2.Fit( prim2, aSeg, m1.End(), !aSide );
479 
480  if( c1 && c2 )
481  {
482  m_type = prim1;
483  m_shapes[0] = m1.m_shapes[0];
484  m_shapes[1] = m1.m_shapes[1];
485  m_baseSeg =aSeg;
486  m_p0 = aP;
487  m_side = aSide;
488  m_amplitude = m1.Amplitude();
489  m_dual = m1.m_dual;
490  m_baseSeg = m1.m_baseSeg;
491  m_baseIndex = m1.m_baseIndex;
493  m_baselineOffset = m1.m_baselineOffset;
494  return true;
495  } else
496  return false;
497  }
498 
499  int minAmpl = st.m_minAmplitude;
500  int maxAmpl = st.m_maxAmplitude;
501 
502  if( m_dual )
503  {
504  minAmpl = std::max( minAmpl, 2 * std::abs( m_baselineOffset ) );
505  maxAmpl = std::max( maxAmpl, 2 * std::abs( m_baselineOffset ) );
506  }
507 
508  for( int ampl = maxAmpl; ampl >= minAmpl; ampl -= st.m_step )
509  {
510  if( m_dual )
511  {
512  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, m_baselineOffset );
513  m_shapes[1] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, -m_baselineOffset );
514  }
515  else
516  {
517  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, 0 );
518  }
519 
520  m_type = aType;
521  m_baseSeg = aSeg;
522  m_p0 = aP;
523  m_side = aSide;
524  m_amplitude = ampl;
525 
527 
528  if( m_placer->CheckFit( this ) )
529  return true;
530  }
531 
532  return false;
533 }
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
produces a meander shape of given type
VECTOR2I & B
Definition: seg.h:52
bool m_side
side (true = right)
Definition: pns_meander.h:376
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:35
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:370
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:380
virtual bool CheckFit(MEANDER_SHAPE *aShape)
Function CheckFit()
#define abs(a)
Definition: auxiliary.h:84
VECTOR2I & A
Definition: seg.h:51
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:356
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:358
int m_width
width of the line
Definition: pns_meander.h:362
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:378
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:364
#define max(a, b)
Definition: auxiliary.h:86
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:372
void updateBaseSegment()
recalculates the clipped baseline after the parameters of the meander have been changed.
bool m_dual
dual or single line
Definition: pns_meander.h:360
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:115
void PNS::MEANDER_SHAPE::forward ( int  aLength)
private

moves turtle forward by aLength

Definition at line 286 of file pns_meander.cpp.

References SHAPE_LINE_CHAIN::Append(), m_currentDir, m_currentPos, m_currentTarget, and VECTOR2< T >::Resize().

Referenced by genMeanderShape(), and uShape().

287 {
288  m_currentPos += m_currentDir.Resize( aLength );
290 }
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:388
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:386
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
VECTOR2D m_currentPos
current turtle position
Definition: pns_meander.h:384
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:382
SHAPE_LINE_CHAIN PNS::MEANDER_SHAPE::genMeanderShape ( VECTOR2D  aP,
VECTOR2D  aDir,
bool  aSide,
MEANDER_TYPE  aType,
int  aAmpl,
int  aBaselineOffset = 0 
)
private

produces a meander shape of given type

Definition at line 327 of file pns_meander.cpp.

References abs, SHAPE_LINE_CHAIN::Append(), cornerRadius(), SHAPE_LINE_CHAIN::CPoint(), forward(), m_meanCornerRadius, PNS::MEANDER_SETTINGS::m_spacing, min, miter(), PNS::MT_EMPTY, PNS::MT_FINISH, PNS::MT_SINGLE, PNS::MT_START, PNS::MT_TURN, SHAPE_LINE_CHAIN::Point(), SHAPE_LINE_CHAIN::PointCount(), reflect(), VECTOR2< T >::Resize(), Settings(), spacing(), start(), turn(), and uShape().

Referenced by Fit(), MakeEmpty(), and Recalculate().

329 {
330  const MEANDER_SETTINGS& st = Settings();
331  int cr = cornerRadius();
332  int offset = aBaselineOffset;
333  int spc = spacing();
334 
335  if( aSide )
336  offset *= -1;
337 
338  VECTOR2D dir_u_b( aDir.Resize( offset ) );
339  VECTOR2D dir_v_b( dir_u_b.Perpendicular() );
340 
341  if( 2 * cr > aAmpl )
342  {
343  cr = aAmpl / 2;
344  }
345 
346  if( 2 * cr > spc )
347  {
348  cr = spc / 2;
349  }
350 
351  m_meanCornerRadius = cr;
352 
353  SHAPE_LINE_CHAIN lc;
354 
355  start( &lc, aP + dir_v_b, aDir );
356 
357  switch( aType )
358  {
359  case MT_EMPTY:
360  {
361  lc.Append( aP + dir_v_b + aDir );
362  break;
363  }
364  case MT_START:
365  {
366  miter( cr - offset, false );
367  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
368  forward( std::min( cr - offset, cr + offset ) );
369  forward( std::abs( offset ) );
370 
371  break;
372  }
373 
374  case MT_FINISH:
375  {
376  start( &lc, aP - dir_u_b, aDir );
377  turn( 90 );
378  forward( std::min( cr - offset, cr + offset ) );
379  forward( std::abs( offset ) );
380  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
381  miter( cr - offset, false );
382  break;
383  }
384 
385  case MT_TURN:
386  {
387  start( &lc, aP - dir_u_b, aDir );
388  turn( 90 );
389  forward( std::abs( offset ) );
390  uShape( aAmpl - cr, cr + offset, spc - 2 * cr );
391  forward( std::abs( offset ) );
392  break;
393  }
394 
395  case MT_SINGLE:
396  {
397  miter( cr - offset, false );
398  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
399  miter( cr - offset, false );
400  lc.Append( aP + dir_v_b + aDir.Resize( 2 * st.m_spacing ) );
401  break;
402  }
403 
404  default:
405  break;
406  }
407 
408  if( aSide )
409  {
410  SEG axis( aP, aP + aDir );
411 
412  for( int i = 0; i < lc.PointCount(); i++ )
413  lc.Point( i ) = reflect( lc.CPoint( i ), axis );
414  }
415 
416  return lc;
417 }
int spacing() const
returns sanitized spacing value
void uShape(int aSides, int aCorner, int aTop)
tells the turtle to draw an U-like shape
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:388
int PointCount() const
Function PointCount()
#define abs(a)
Definition: auxiliary.h:84
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void miter(int aRadius, bool aSide)
tells the turtle to draw a mitered corner of given radius and turn direction
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
starts turtle drawing
int m_meanCornerRadius
average radius of meander corners (for correction of DP meanders)
Definition: pns_meander.h:368
void turn(int aAngle)
turns the turtle by aAngle
int cornerRadius() const
returns sanitized corner radius value
void forward(int aLength)
moves turtle forward by aLength
Definition: seg.h:37
Class SHAPE_LINE_CHAIN.
VECTOR2I reflect(VECTOR2I aP, const SEG &aLine)
reflects a point onto other side of a given segment
VECTOR2I & Point(int aIndex)
Function Point()
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
#define min(a, b)
Definition: auxiliary.h:85
bool PNS::MEANDER_SHAPE::IsDual ( ) const
inline

Function IsDual()

Returns
true if the shape represents 2 parallel lines (diff pair).

Definition at line 211 of file pns_meander.h.

References m_dual.

212  {
213  return m_dual;
214  }
bool m_dual
dual or single line
Definition: pns_meander.h:360
void PNS::MEANDER_SHAPE::MakeCorner ( VECTOR2I  aP1,
VECTOR2I  aP2 = VECTOR2I( 0, 0 ) 
)

Function MakeCorner()

Creates a dummy meander shape representing a line corner. Used to define the starts/ends of meandered segments.

Parameters
aP1corner point of the 1st line
aP2corner point of the 2nd line (if m_dual == true)

Definition at line 584 of file pns_meander.cpp.

References SEG::A, SHAPE_LINE_CHAIN::Append(), SEG::B, SHAPE_LINE_CHAIN::Clear(), m_clippedBaseSeg, m_shapes, PNS::MT_CORNER, and SetType().

Referenced by PNS::MEANDERED_LINE::AddCorner().

585 {
586  SetType( MT_CORNER );
587  m_shapes[0].Clear();
588  m_shapes[1].Clear();
589  m_shapes[0].Append( aP1 );
590  m_shapes[1].Append( aP2 );
591  m_clippedBaseSeg.A = aP1;
592  m_clippedBaseSeg.B = aP1;
593 }
VECTOR2I & B
Definition: seg.h:52
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
VECTOR2I & A
Definition: seg.h:51
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:378
void Clear()
Function Clear() Removes all points from the line chain.
void SetType(MEANDER_TYPE aType)
Function SetType()
Definition: pns_meander.h:135
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
void PNS::MEANDER_SHAPE::MakeEmpty ( )

Function MakeEmpty()

Replaces the meander with straight bypass line(s), effectively clearing it.

Definition at line 558 of file pns_meander.cpp.

References SEG::A, SEG::B, genMeanderShape(), m_baselineOffset, m_clippedBaseSeg, m_dual, m_p0, m_shapes, m_side, m_type, PNS::MT_EMPTY, and updateBaseSegment().

559 {
561 
563 
564  m_type = MT_EMPTY;
565 
567 
568  if( m_dual )
570 }
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
produces a meander shape of given type
VECTOR2I & B
Definition: seg.h:52
bool m_side
side (true = right)
Definition: pns_meander.h:376
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:370
VECTOR2I & A
Definition: seg.h:51
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:356
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:378
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
void updateBaseSegment()
recalculates the clipped baseline after the parameters of the meander have been changed.
bool m_dual
dual or single line
Definition: pns_meander.h:360
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
SHAPE_LINE_CHAIN PNS::MEANDER_SHAPE::makeMiterShape ( VECTOR2D  aP,
VECTOR2D  aDir,
bool  aSide 
)
private

generates a 90-degree circular arc

Definition at line 186 of file pns_meander.cpp.

References abs, SHAPE_LINE_CHAIN::Append(), VECTOR2< T >::EuclideanNorm(), m_baselineOffset, PNS::MEANDER_SETTINGS::m_cornerArcSegments, PNS::MEANDER_SETTINGS::m_cornerStyle, m_dual, m_meanCornerRadius, m_placer, PNS::MEANDER_STYLE_CHAMFER, PNS::MEANDER_STYLE_ROUND, PNS::MEANDER_PLACER_BASE::MeanderSettings(), VECTOR2< T >::Perpendicular(), VECTOR2< T >::Resize(), and Settings().

Referenced by miter().

187 {
188  SHAPE_LINE_CHAIN lc;
189 
190  if( aDir.EuclideanNorm( ) == 0.0f )
191  {
192  lc.Append( aP );
193  return lc;
194  }
195 
196  VECTOR2D dir_u( aDir );
197  VECTOR2D dir_v( aDir.Perpendicular( ) );
198  VECTOR2D p = aP;
199  lc.Append( ( int ) p.x, ( int ) p.y );
200 
201 
202  // fixme: refactor
204  {
205  case MEANDER_STYLE_ROUND:
206  {
207  const int ArcSegments = Settings().m_cornerArcSegments;
208 
209  double radius = (double) aDir.EuclideanNorm();
210  double angleStep = M_PI / 2.0 / (double) ArcSegments;
211 
212  double correction = 12.0 * radius * ( 1.0 - cos( angleStep / 2.0 ) );
213 
214  if( !m_dual )
215  correction = 0.0;
216  else if( radius < m_meanCornerRadius )
217  correction = 0.0;
218 
219  VECTOR2D dir_uu = dir_u.Resize( radius - correction );
220  VECTOR2D dir_vv = dir_v.Resize( radius - correction );
221 
222  VECTOR2D shift = dir_u.Resize( correction );
223 
224  for( int i = ArcSegments - 1; i >= 0; i-- )
225  {
226  double alpha = (double) i / (double) ( ArcSegments - 1 ) * M_PI / 2.0;
227  p = aP + shift + dir_uu * cos( alpha ) + dir_vv * ( aSide ? -1.0 : 1.0 ) * ( 1.0 - sin( alpha ) );
228  lc.Append( ( int ) p.x, ( int ) p.y );
229  }
230  }
231  break;
233  {
234  double radius = (double) aDir.EuclideanNorm();
235  double correction = 0;
236  if( m_dual && radius > m_meanCornerRadius )
237  correction = (double)(-2 * abs(m_baselineOffset)) * tan( 22.5 * M_PI / 180.0 );
238 
239  VECTOR2D dir_cu = dir_u.Resize( correction );
240  VECTOR2D dir_cv = dir_v.Resize( correction );
241 
242  p = aP - dir_cu;
243  lc.Append( ( int ) p.x, ( int ) p.y );
244  p = aP + dir_u + (dir_v + dir_cv) * ( aSide ? -1.0 : 1.0 );
245  lc.Append( ( int ) p.x, ( int ) p.y );
246  break;
247  }
248  }
249 
250  p = aP + dir_u + dir_v * ( aSide ? -1.0 : 1.0 );
251  lc.Append( ( int ) p.x, ( int ) p.y );
252 
253  return lc;
254 }
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:388
MEANDER_STYLE m_cornerStyle
type of corners for the meandered line
Definition: pns_meander.h:86
#define abs(a)
Definition: auxiliary.h:84
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:295
int m_meanCornerRadius
average radius of meander corners (for correction of DP meanders)
Definition: pns_meander.h:368
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:358
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
int m_cornerArcSegments
number of line segments for arc approximation
Definition: pns_meander.h:92
Class SHAPE_LINE_CHAIN.
VECTOR2< T > Perpendicular() const
Function Perpendicular computes the perpendicular vector.
Definition: vector2d.h:316
virtual const MEANDER_SETTINGS & MeanderSettings() const
Function MeanderSettings()
bool m_dual
dual or single line
Definition: pns_meander.h:360
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
int PNS::MEANDER_SHAPE::MaxTunableLength ( ) const

Function MaxTunableLength()

Returns
the length of the fitted line chain.

Definition at line 620 of file pns_meander.cpp.

References CLine(), and SHAPE_LINE_CHAIN::Length().

621 {
622  return CLine( 0 ).Length();
623 }
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Function CLine()
Definition: pns_meander.h:241
int Length() const
Function Length()
void PNS::MEANDER_SHAPE::miter ( int  aRadius,
bool  aSide 
)
private

tells the turtle to draw a mitered corner of given radius and turn direction

Definition at line 299 of file pns_meander.cpp.

References SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::CPoint(), m_currentDir, m_currentPos, m_currentTarget, makeMiterShape(), VECTOR2< T >::Resize(), VECTOR2< T >::Rotate(), and turn().

Referenced by genMeanderShape(), and uShape().

300 {
301  if( aRadius <= 0 )
302  {
303  turn( aSide ? -90 : 90 );
304  return;
305  }
306 
307  VECTOR2D dir = m_currentDir.Resize( (double) aRadius );
308  SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
309 
310  m_currentPos = lc.CPoint( -1 );
311  m_currentDir = dir.Rotate( aSide ? -M_PI / 2.0 : M_PI / 2.0 );
312 
313  m_currentTarget->Append( lc );
314 }
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:388
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:386
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN makeMiterShape(VECTOR2D aP, VECTOR2D aDir, bool aSide)
generates a 90-degree circular arc
void turn(int aAngle)
turns the turtle by aAngle
Class SHAPE_LINE_CHAIN.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
VECTOR2D m_currentPos
current turtle position
Definition: pns_meander.h:384
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:382
void PNS::MEANDER_SHAPE::Recalculate ( )

Function Recalculate()

Recalculates the line chain representing the meanders's shape.

Definition at line 536 of file pns_meander.cpp.

References SEG::A, SEG::B, genMeanderShape(), m_amplitude, m_baselineOffset, m_baseSeg, m_dual, m_p0, m_shapes, m_side, m_type, and updateBaseSegment().

Referenced by Resize().

537 {
539 
540  if( m_dual )
542 
544 }
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
produces a meander shape of given type
VECTOR2I & B
Definition: seg.h:52
bool m_side
side (true = right)
Definition: pns_meander.h:376
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:370
VECTOR2I & A
Definition: seg.h:51
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:356
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:378
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:364
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:372
void updateBaseSegment()
recalculates the clipped baseline after the parameters of the meander have been changed.
bool m_dual
dual or single line
Definition: pns_meander.h:360
VECTOR2I PNS::MEANDER_SHAPE::reflect ( VECTOR2I  aP,
const SEG aLine 
)
private

reflects a point onto other side of a given segment

Definition at line 257 of file pns_meander.cpp.

References SEG::A, SEG::B, VECTOR2< T >::Dot(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by genMeanderShape().

258 {
259  typedef int64_t ecoord;
260  VECTOR2I d = line.B - line.A;
261  ecoord l_squared = d.Dot( d );
262  ecoord t = d.Dot( p - line.A );
263  VECTOR2I c, rv;
264 
265  if( !l_squared )
266  c = p;
267  else {
268  c.x = line.A.x + rescale( t, (ecoord) d.x, l_squared );
269  c.y = line.A.y + rescale( t, (ecoord) d.y, l_squared );
270  }
271 
272  return 2 * c - p;
273 }
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:488
VECTOR2I::extended_type ecoord
int rescale(int aNumerator, int aValue, int aDenominator)
Definition: math_util.cpp:32
void PNS::MEANDER_SHAPE::Resize ( int  aAmpl)

Function Resize()

Changes the amplitude of the meander shape to aAmpl and recalculates the resulting line chain.

Parameters
aAmplnew amplitude.

Definition at line 547 of file pns_meander.cpp.

References m_amplitude, and Recalculate().

548 {
549  if( aAmpl < 0 )
550  return;
551 
552  m_amplitude = aAmpl;
553 
554  Recalculate();
555 }
void Recalculate()
Function Recalculate()
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:364
void PNS::MEANDER_SHAPE::SetBaseIndex ( int  aIndex)
inline

Function SetBaseIndex()

Sets an auxillary index of the segment being meandered in its original LINE.

Definition at line 155 of file pns_meander.h.

References m_baseIndex.

Referenced by PNS::MEANDERED_LINE::MeanderSegment().

156  {
157  m_baseIndex = aIndex;
158  }
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:380
void PNS::MEANDER_SHAPE::SetBaselineOffset ( int  aOffset)
inline

Function SetBaselineOffset()

Sets the parallel offset between the base segment and the meandered line. Used for dual menaders (diff pair) only.

Parameters
aOffsetthe offset

Definition at line 317 of file pns_meander.h.

References m_baselineOffset.

Referenced by Fit(), and PNS::MEANDERED_LINE::MeanderSegment().

318  {
319  m_baselineOffset = aOffset;
320  }
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
const MEANDER_SETTINGS & PNS::MEANDER_SHAPE::Settings ( ) const

Function Settings()

Returns
the current meandering settings.

Definition at line 34 of file pns_meander.cpp.

References m_placer, and PNS::MEANDER_PLACER_BASE::MeanderSettings().

Referenced by cornerRadius(), Fit(), genMeanderShape(), makeMiterShape(), and spacing().

35 {
36  return m_placer->MeanderSettings();
37 }
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:358
virtual const MEANDER_SETTINGS & MeanderSettings() const
Function MeanderSettings()
void PNS::MEANDER_SHAPE::SetType ( MEANDER_TYPE  aType)
inline

Function SetType()

Sets the type of the meander.

Definition at line 135 of file pns_meander.h.

References m_type.

Referenced by MakeCorner().

136  {
137  m_type = aType;
138  }
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:356
bool PNS::MEANDER_SHAPE::Side ( ) const
inline

Function Side()

Returns
true if the meander is to the right of its base segment.

Definition at line 221 of file pns_meander.h.

References m_side.

222  {
223  return m_side;
224  }
bool m_side
side (true = right)
Definition: pns_meander.h:376
int PNS::MEANDER_SHAPE::spacing ( ) const
private

returns sanitized spacing value

Definition at line 174 of file pns_meander.cpp.

References abs, m_baselineOffset, m_dual, m_width, max, and Settings().

Referenced by cornerRadius(), genMeanderShape(), and PNS::MEANDERED_LINE::MeanderSegment().

175 {
176  if( !m_dual )
177  return std::max( 2 * m_width, Settings().m_spacing );
178  else
179  {
180  int sp = 2 * ( m_width + std::abs( m_baselineOffset ) );
181  return std::max( sp, Settings().m_spacing );
182  }
183 }
#define abs(a)
Definition: auxiliary.h:84
int m_width
width of the line
Definition: pns_meander.h:362
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
#define max(a, b)
Definition: auxiliary.h:86
bool m_dual
dual or single line
Definition: pns_meander.h:360
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
void PNS::MEANDER_SHAPE::start ( SHAPE_LINE_CHAIN aTarget,
const VECTOR2D aWhere,
const VECTOR2D aDir 
)
private

starts turtle drawing

Definition at line 276 of file pns_meander.cpp.

References SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::Clear(), m_currentDir, m_currentPos, and m_currentTarget.

Referenced by genMeanderShape().

277 {
278  m_currentTarget = aTarget;
280  m_currentTarget->Append( aWhere );
281  m_currentDir = aDir;
282  m_currentPos = aWhere;
283 }
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:386
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void Clear()
Function Clear() Removes all points from the line chain.
VECTOR2D m_currentPos
current turtle position
Definition: pns_meander.h:384
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:382
void PNS::MEANDER_SHAPE::turn ( int  aAngle)
private

turns the turtle by aAngle

Definition at line 293 of file pns_meander.cpp.

References m_currentDir, and VECTOR2< T >::Rotate().

Referenced by genMeanderShape(), and miter().

294 {
295  m_currentDir = m_currentDir.Rotate( (double) aAngle * M_PI / 180.0 );
296 }
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:382
MEANDER_TYPE PNS::MEANDER_SHAPE::Type ( ) const
inline

Function Type()

Returns
the type of the meander.

Definition at line 145 of file pns_meander.h.

References m_type.

Referenced by PNS::MEANDERED_LINE::CheckSelfIntersections().

146  {
147  return m_type;
148  }
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:356
void PNS::MEANDER_SHAPE::updateBaseSegment ( )
private

recalculates the clipped baseline after the parameters of the meander have been changed.

Definition at line 626 of file pns_meander.cpp.

References SEG::A, SEG::B, CLine(), SHAPE_LINE_CHAIN::CPoint(), SEG::LineProject(), m_baseSeg, m_clippedBaseSeg, and m_dual.

Referenced by Fit(), MakeEmpty(), and Recalculate().

627 {
628  if( m_dual )
629  {
630  VECTOR2I midpA = ( CLine( 0 ).CPoint( 0 ) + CLine( 1 ).CPoint( 0 ) ) / 2;
631  VECTOR2I midpB = ( CLine( 0 ).CPoint( -1 ) + CLine( 1 ).CPoint( -1 ) ) / 2;
632 
635  }
636  else
637  {
638  m_clippedBaseSeg.A = m_baseSeg.LineProject( CLine( 0 ).CPoint( 0 ) );
639  m_clippedBaseSeg.B = m_baseSeg.LineProject( CLine( 0 ).CPoint( -1 ) );
640  }
641 }
VECTOR2I & B
Definition: seg.h:52
VECTOR2I LineProject(const VECTOR2I &aP) const
Function LineProject()
Definition: seg.h:364
VECTOR2I & A
Definition: seg.h:51
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:372
bool m_dual
dual or single line
Definition: pns_meander.h:360
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Function CLine()
Definition: pns_meander.h:241
void PNS::MEANDER_SHAPE::uShape ( int  aSides,
int  aCorner,
int  aTop 
)
private

tells the turtle to draw an U-like shape

Definition at line 317 of file pns_meander.cpp.

References forward(), and miter().

Referenced by genMeanderShape().

318 {
319  forward( aSides );
320  miter( aCorner, true );
321  forward( aTop );
322  miter( aCorner, true );
323  forward( aSides );
324 }
void miter(int aRadius, bool aSide)
tells the turtle to draw a mitered corner of given radius and turn direction
void forward(int aLength)
moves turtle forward by aLength
int PNS::MEANDER_SHAPE::Width ( ) const
inline

Function Width()

Returns
width of the meandered line.

Definition at line 305 of file pns_meander.h.

References m_width.

Referenced by PNS::MEANDER_PLACER::CheckFit(), and PNS::DP_MEANDER_PLACER::CheckFit().

306  {
307  return m_width;
308  }
int m_width
width of the line
Definition: pns_meander.h:362

Friends And Related Function Documentation

friend class MEANDERED_LINE
friend

Definition at line 323 of file pns_meander.h.

Member Data Documentation

int PNS::MEANDER_SHAPE::m_amplitude
private

amplitude of the meander

Definition at line 364 of file pns_meander.h.

Referenced by Amplitude(), Fit(), MEANDER_SHAPE(), Recalculate(), and Resize().

int PNS::MEANDER_SHAPE::m_baseIndex
private

index of the meandered segment in the base line

Definition at line 380 of file pns_meander.h.

Referenced by BaseIndex(), Fit(), MEANDER_SHAPE(), and SetBaseIndex().

int PNS::MEANDER_SHAPE::m_baselineOffset
private

offset wrs the base segment (dual only)

Definition at line 366 of file pns_meander.h.

Referenced by Fit(), MakeEmpty(), makeMiterShape(), Recalculate(), SetBaselineOffset(), and spacing().

SEG PNS::MEANDER_SHAPE::m_baseSeg
private

base segment (unclipped)

Definition at line 372 of file pns_meander.h.

Referenced by Fit(), Recalculate(), and updateBaseSegment().

SEG PNS::MEANDER_SHAPE::m_clippedBaseSeg
private

base segment (clipped)

Definition at line 374 of file pns_meander.h.

Referenced by BaselineLength(), BaseSegment(), End(), MakeCorner(), MakeEmpty(), and updateBaseSegment().

VECTOR2D PNS::MEANDER_SHAPE::m_currentDir
private

current turtle direction

Definition at line 382 of file pns_meander.h.

Referenced by forward(), miter(), start(), and turn().

VECTOR2D PNS::MEANDER_SHAPE::m_currentPos
private

current turtle position

Definition at line 384 of file pns_meander.h.

Referenced by forward(), miter(), and start().

SHAPE_LINE_CHAIN* PNS::MEANDER_SHAPE::m_currentTarget
private

the line the turtle is drawing on

Definition at line 386 of file pns_meander.h.

Referenced by forward(), MEANDER_SHAPE(), miter(), and start().

bool PNS::MEANDER_SHAPE::m_dual
private

dual or single line

Definition at line 360 of file pns_meander.h.

Referenced by Fit(), IsDual(), MakeEmpty(), makeMiterShape(), Recalculate(), spacing(), and updateBaseSegment().

int PNS::MEANDER_SHAPE::m_meanCornerRadius
private

average radius of meander corners (for correction of DP meanders)

Definition at line 368 of file pns_meander.h.

Referenced by genMeanderShape(), makeMiterShape(), and MEANDER_SHAPE().

VECTOR2I PNS::MEANDER_SHAPE::m_p0
private

first point of the meandered line

Definition at line 370 of file pns_meander.h.

Referenced by Fit(), MakeEmpty(), and Recalculate().

MEANDER_PLACER_BASE* PNS::MEANDER_SHAPE::m_placer
private

the placer that placed this meander

Definition at line 358 of file pns_meander.h.

Referenced by Fit(), makeMiterShape(), and Settings().

SHAPE_LINE_CHAIN PNS::MEANDER_SHAPE::m_shapes[2]
private

the actual shapes (0 used for single, both for dual)

Definition at line 378 of file pns_meander.h.

Referenced by CLine(), Fit(), MakeCorner(), MakeEmpty(), and Recalculate().

bool PNS::MEANDER_SHAPE::m_side
private

side (true = right)

Definition at line 376 of file pns_meander.h.

Referenced by Fit(), MakeEmpty(), MEANDER_SHAPE(), Recalculate(), and Side().

MEANDER_TYPE PNS::MEANDER_SHAPE::m_type
private

the type

Definition at line 356 of file pns_meander.h.

Referenced by Fit(), MakeEmpty(), MEANDER_SHAPE(), Recalculate(), SetType(), and Type().

int PNS::MEANDER_SHAPE::m_width
private

width of the line

Definition at line 362 of file pns_meander.h.

Referenced by Fit(), spacing(), and Width().


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