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 PNS::MT_SINGLE.

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

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.

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.

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 617 of file pns_meander.cpp.

References SEG::Length(), and m_clippedBaseSeg.

618 {
619  return m_clippedBaseSeg.Length();
620 }
int Length() const
Function Length()
Definition: seg.h:292
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.

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.

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, m_dual, Settings(), and spacing().

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

169 {
170  // TODO: fix diff-pair meandering so we can use non-100% radii
171  int rPercent = m_dual ? 100 : Settings().m_cornerRadiusPercentage;
172 
173  return (int64_t) spacing() * rPercent / 200;
174 }
int spacing() const
returns sanitized spacing value
int m_cornerRadiusPercentage
rounding percentage (0 - 100)
Definition: pns_meander.h:88
bool m_dual
dual or single line
Definition: pns_meander.h:360
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.

Referenced by Fit().

232  {
233  return m_clippedBaseSeg.B;
234  }
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
VECTOR2I B
Definition: seg.h:47
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 449 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().

450 {
451  const MEANDER_SETTINGS& st = Settings();
452 
453  bool checkMode = false;
454  MEANDER_TYPE prim1, prim2;
455 
456  if( aType == MT_CHECK_START )
457  {
458  prim1 = MT_START;
459  prim2 = MT_TURN;
460  checkMode = true;
461  }
462  else if( aType == MT_CHECK_FINISH )
463  {
464  prim1 = MT_TURN;
465  prim2 = MT_FINISH;
466  checkMode = true;
467  }
468 
469  if( checkMode )
470  {
473 
474  m1.SetBaselineOffset( m_baselineOffset );
475  m2.SetBaselineOffset( m_baselineOffset );
476 
477  bool c1 = m1.Fit( prim1, aSeg, aP, aSide );
478  bool c2 = false;
479 
480  if( c1 )
481  c2 = m2.Fit( prim2, aSeg, m1.End(), !aSide );
482 
483  if( c1 && c2 )
484  {
485  m_type = prim1;
486  m_shapes[0] = m1.m_shapes[0];
487  m_shapes[1] = m1.m_shapes[1];
488  m_baseSeg =aSeg;
489  m_p0 = aP;
490  m_side = aSide;
491  m_amplitude = m1.Amplitude();
492  m_dual = m1.m_dual;
493  m_baseSeg = m1.m_baseSeg;
494  m_baseIndex = m1.m_baseIndex;
496  m_baselineOffset = m1.m_baselineOffset;
497  return true;
498  } else
499  return false;
500  }
501 
502  int minAmpl = st.m_minAmplitude;
503  int maxAmpl = st.m_maxAmplitude;
504 
505  if( m_dual )
506  {
507  minAmpl = std::max( minAmpl, 2 * std::abs( m_baselineOffset ) );
508  maxAmpl = std::max( maxAmpl, 2 * std::abs( m_baselineOffset ) );
509  }
510 
511  for( int ampl = maxAmpl; ampl >= minAmpl; ampl -= st.m_step )
512  {
513  if( m_dual )
514  {
515  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, m_baselineOffset );
516  m_shapes[1] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, -m_baselineOffset );
517  }
518  else
519  {
520  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, 0 );
521  }
522 
523  m_type = aType;
524  m_baseSeg = aSeg;
525  m_p0 = aP;
526  m_side = aSide;
527  m_amplitude = ampl;
528 
530 
531  if( m_placer->CheckFit( this ) )
532  return true;
533  }
534 
535  return false;
536 }
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
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
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
VECTOR2I A
Definition: seg.h:46
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
VECTOR2I B
Definition: seg.h:47
void PNS::MEANDER_SHAPE::forward ( int  aLength)
private

moves turtle forward by aLength

Definition at line 289 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().

290 {
291  m_currentPos += m_currentDir.Resize( aLength );
293 }
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:387
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 330 of file pns_meander.cpp.

References abs, SHAPE_LINE_CHAIN::Append(), cornerRadius(), SHAPE_LINE_CHAIN::CPoint(), forward(), i, 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().

332 {
333  const MEANDER_SETTINGS& st = Settings();
334  int cr = cornerRadius();
335  int offset = aBaselineOffset;
336  int spc = spacing();
337 
338  if( aSide )
339  offset *= -1;
340 
341  VECTOR2D dir_u_b( aDir.Resize( offset ) );
342  VECTOR2D dir_v_b( dir_u_b.Perpendicular() );
343 
344  if( 2 * cr > aAmpl )
345  {
346  cr = aAmpl / 2;
347  }
348 
349  if( 2 * cr > spc )
350  {
351  cr = spc / 2;
352  }
353 
354  m_meanCornerRadius = cr;
355 
356  SHAPE_LINE_CHAIN lc;
357 
358  start( &lc, aP + dir_v_b, aDir );
359 
360  switch( aType )
361  {
362  case MT_EMPTY:
363  {
364  lc.Append( aP + dir_v_b + aDir );
365  break;
366  }
367  case MT_START:
368  {
369  miter( cr - offset, false );
370  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
371  forward( std::min( cr - offset, cr + offset ) );
372  forward( std::abs( offset ) );
373 
374  break;
375  }
376 
377  case MT_FINISH:
378  {
379  start( &lc, aP - dir_u_b, aDir );
380  turn( 90 );
381  forward( std::min( cr - offset, cr + offset ) );
382  forward( std::abs( offset ) );
383  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
384  miter( cr - offset, false );
385  break;
386  }
387 
388  case MT_TURN:
389  {
390  start( &lc, aP - dir_u_b, aDir );
391  turn( 90 );
392  forward( std::abs( offset ) );
393  uShape( aAmpl - cr, cr + offset, spc - 2 * cr );
394  forward( std::abs( offset ) );
395  break;
396  }
397 
398  case MT_SINGLE:
399  {
400  miter( cr - offset, false );
401  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
402  miter( cr - offset, false );
403  lc.Append( aP + dir_v_b + aDir.Resize( 2 * st.m_spacing ) );
404  break;
405  }
406 
407  default:
408  break;
409  }
410 
411  if( aSide )
412  {
413  SEG axis( aP, aP + aDir );
414 
415  for( int i = 0; i < lc.PointCount(); i++ )
416  lc.Point( i ) = reflect( lc.CPoint( i ), axis );
417  }
418 
419  return lc;
420 }
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:387
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:36
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597
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.

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

588 {
589  SetType( MT_CORNER );
590  m_shapes[0].Clear();
591  m_shapes[1].Clear();
592  m_shapes[0].Append( aP1 );
593  m_shapes[1].Append( aP2 );
594  m_clippedBaseSeg.A = aP1;
595  m_clippedBaseSeg.B = aP1;
596 }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:378
VECTOR2I A
Definition: seg.h:46
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
VECTOR2I B
Definition: seg.h:47
void PNS::MEANDER_SHAPE::MakeEmpty ( )

Function MakeEmpty()

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

Definition at line 561 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().

562 {
564 
566 
567  m_type = MT_EMPTY;
568 
570 
571  if( m_dual )
573 }
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
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
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
VECTOR2I A
Definition: seg.h:46
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
VECTOR2I B
Definition: seg.h:47
SHAPE_LINE_CHAIN PNS::MEANDER_SHAPE::makeMiterShape ( VECTOR2D  aP,
VECTOR2D  aDir,
bool  aSide 
)
private

generates a 90-degree circular arc

Definition at line 189 of file pns_meander.cpp.

References abs, SHAPE_LINE_CHAIN::Append(), VECTOR2< T >::EuclideanNorm(), i, 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().

190 {
191  SHAPE_LINE_CHAIN lc;
192 
193  if( aDir.EuclideanNorm( ) == 0.0f )
194  {
195  lc.Append( aP );
196  return lc;
197  }
198 
199  VECTOR2D dir_u( aDir );
200  VECTOR2D dir_v( aDir.Perpendicular( ) );
201  VECTOR2D p = aP;
202  lc.Append( ( int ) p.x, ( int ) p.y );
203 
204 
205  // fixme: refactor
207  {
208  case MEANDER_STYLE_ROUND:
209  {
210  const int ArcSegments = Settings().m_cornerArcSegments;
211 
212  double radius = (double) aDir.EuclideanNorm();
213  double angleStep = M_PI / 2.0 / (double) ArcSegments;
214 
215  double correction = 12.0 * radius * ( 1.0 - cos( angleStep / 2.0 ) );
216 
217  if( !m_dual )
218  correction = 0.0;
219  else if( radius < m_meanCornerRadius )
220  correction = 0.0;
221 
222  VECTOR2D dir_uu = dir_u.Resize( radius - correction );
223  VECTOR2D dir_vv = dir_v.Resize( radius - correction );
224 
225  VECTOR2D shift = dir_u.Resize( correction );
226 
227  for( int i = ArcSegments - 1; i >= 0; i-- )
228  {
229  double alpha = (double) i / (double) ( ArcSegments - 1 ) * M_PI / 2.0;
230  p = aP + shift + dir_uu * cos( alpha ) + dir_vv * ( aSide ? -1.0 : 1.0 ) * ( 1.0 - sin( alpha ) );
231  lc.Append( ( int ) p.x, ( int ) p.y );
232  }
233  }
234  break;
236  {
237  double radius = (double) aDir.EuclideanNorm();
238  double correction = 0;
239  if( m_dual && radius > m_meanCornerRadius )
240  correction = (double)(-2 * abs(m_baselineOffset)) * tan( 22.5 * M_PI / 180.0 );
241 
242  VECTOR2D dir_cu = dir_u.Resize( correction );
243  VECTOR2D dir_cv = dir_v.Resize( correction );
244 
245  p = aP - dir_cu;
246  lc.Append( ( int ) p.x, ( int ) p.y );
247  p = aP + dir_u + (dir_v + dir_cv) * ( aSide ? -1.0 : 1.0 );
248  lc.Append( ( int ) p.x, ( int ) p.y );
249  break;
250  }
251  }
252 
253  p = aP + dir_u + dir_v * ( aSide ? -1.0 : 1.0 );
254  lc.Append( ( int ) p.x, ( int ) p.y );
255 
256  return lc;
257 }
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:387
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:294
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.
size_t i
Definition: json11.cpp:597
VECTOR2< T > Perpendicular() const
Function Perpendicular computes the perpendicular vector.
Definition: vector2d.h:315
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 623 of file pns_meander.cpp.

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

624 {
625  return CLine( 0 ).Length();
626 }
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 302 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().

303 {
304  if( aRadius <= 0 )
305  {
306  turn( aSide ? -90 : 90 );
307  return;
308  }
309 
310  VECTOR2D dir = m_currentDir.Resize( (double) aRadius );
311  SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
312 
313  m_currentPos = lc.CPoint( -1 );
314  m_currentDir = dir.Rotate( aSide ? -M_PI / 2.0 : M_PI / 2.0 );
315 
316  m_currentTarget->Append( lc );
317 }
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:387
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:372
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 539 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().

540 {
542 
543  if( m_dual )
545 
547 }
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
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
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
VECTOR2I A
Definition: seg.h:46
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 B
Definition: seg.h:47
VECTOR2I PNS::MEANDER_SHAPE::reflect ( VECTOR2I  aP,
const SEG aLine 
)
private

reflects a point onto other side of a given segment

Definition at line 260 of file pns_meander.cpp.

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

Referenced by genMeanderShape().

261 {
262  typedef int64_t ecoord;
263  VECTOR2I d = line.B - line.A;
264  ecoord l_squared = d.Dot( d );
265  ecoord t = d.Dot( p - line.A );
266  VECTOR2I c, rv;
267 
268  if( !l_squared )
269  c = p;
270  else {
271  c.x = line.A.x + rescale( t, (ecoord) d.x, l_squared );
272  c.y = line.A.y + rescale( t, (ecoord) d.y, l_squared );
273  }
274 
275  return 2 * c - p;
276 }
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:487
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 550 of file pns_meander.cpp.

References m_amplitude, and Recalculate().

551 {
552  if( aAmpl < 0 )
553  return;
554 
555  m_amplitude = aAmpl;
556 
557  Recalculate();
558 }
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.

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.

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(), PNS::MEANDERED_LINE::MeanderSegment(), 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.

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.

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

178 {
179  if( !m_dual )
180  return std::max( 2 * m_width, Settings().m_spacing );
181  else
182  {
183  int sp = 2 * ( m_width + std::abs( m_baselineOffset ) );
184  return std::max( sp, Settings().m_spacing );
185  }
186 }
#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 279 of file pns_meander.cpp.

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

Referenced by genMeanderShape().

280 {
281  m_currentTarget = aTarget;
283  m_currentTarget->Append( aWhere );
284  m_currentDir = aDir;
285  m_currentPos = aWhere;
286 }
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 296 of file pns_meander.cpp.

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

Referenced by genMeanderShape(), and miter().

297 {
298  m_currentDir = m_currentDir.Rotate( (double) aAngle * M_PI / 180.0 );
299 }
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:372
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.

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

630 {
631  if( m_dual )
632  {
633  VECTOR2I midpA = ( CLine( 0 ).CPoint( 0 ) + CLine( 1 ).CPoint( 0 ) ) / 2;
634  VECTOR2I midpB = ( CLine( 0 ).CPoint( -1 ) + CLine( 1 ).CPoint( -1 ) ) / 2;
635 
638  }
639  else
640  {
641  m_clippedBaseSeg.A = m_baseSeg.LineProject( CLine( 0 ).CPoint( 0 ) );
642  m_clippedBaseSeg.B = m_baseSeg.LineProject( CLine( 0 ).CPoint( -1 ) );
643  }
644 }
VECTOR2I LineProject(const VECTOR2I &aP) const
Function LineProject()
Definition: seg.h:337
VECTOR2I A
Definition: seg.h:46
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
VECTOR2I B
Definition: seg.h:47
void PNS::MEANDER_SHAPE::uShape ( int  aSides,
int  aCorner,
int  aTop 
)
private

tells the turtle to draw an U-like shape

Definition at line 320 of file pns_meander.cpp.

References forward(), and miter().

Referenced by genMeanderShape().

321 {
322  forward( aSides );
323  miter( aCorner, true );
324  forward( aTop );
325  miter( aCorner, true );
326  forward( aSides );
327 }
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.

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

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(), PNS::MEANDERED_LINE::MeanderSegment(), Recalculate(), 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(), 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(), miter(), and start().

bool PNS::MEANDER_SHAPE::m_dual
private
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(), and makeMiterShape().

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
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 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(), and Recalculate().

MEANDER_TYPE PNS::MEANDER_SHAPE::m_type
private

the type

Definition at line 356 of file pns_meander.h.

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

int PNS::MEANDER_SHAPE::m_width
private

width of the line

Definition at line 362 of file pns_meander.h.

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


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