KiCad PCB EDA Suite
PNS::MEANDER_SHAPE Class Reference

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

MEANDER_SETTINGS.

Holds the geometry of a single meander.

Definition at line 107 of file pns_meander.h.

Constructor & Destructor Documentation

◆ MEANDER_SHAPE()

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 118 of file pns_meander.h.

118  :
119  m_placer( aPlacer ),
120  m_dual( aIsDual ),
121  m_width( aWidth ),
122  m_baselineOffset( 0 )
123  {
124  // Do not leave unitialized members, and keep static analyser quiet:
125  m_type = MT_SINGLE;
126  m_amplitude = 0;
127  m_side = false;
128  m_baseIndex = 0;
130  m_meanCornerRadius = 0;
131  }
bool m_side
side (true = right)
Definition: pns_meander.h:379
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:389
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:383
#define NULL
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:359
int m_meanCornerRadius
average radius of meander corners (for correction of DP meanders)
Definition: pns_meander.h:371
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:361
int m_width
width of the line
Definition: pns_meander.h:365
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:367
bool m_dual
dual or single line
Definition: pns_meander.h:363

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

Member Function Documentation

◆ Amplitude()

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

Function Amplitude()

Returns
the amplitude of the meander shape.

Definition at line 178 of file pns_meander.h.

179  {
180  return m_amplitude;
181  }
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:367

References m_amplitude.

Referenced by Fit().

◆ BaseIndex()

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

Function BaseIndex()

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

Definition at line 168 of file pns_meander.h.

169  {
170  return m_baseIndex;
171  }
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:383

References m_baseIndex.

◆ BaselineLength()

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.

618 {
619  return m_clippedBaseSeg.Length();
620 }
int Length() const
Function Length()
Definition: seg.h:319
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:377

References SEG::Length(), and m_clippedBaseSeg.

◆ BaseSegment()

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 276 of file pns_meander.h.

277  {
278  return m_clippedBaseSeg;
279  }
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:377

References m_clippedBaseSeg.

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

◆ CLine()

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 244 of file pns_meander.h.

245  {
246  return m_shapes[aShape];
247  }
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:381

References m_shapes.

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

◆ cornerRadius()

int PNS::MEANDER_SHAPE::cornerRadius ( ) const
private

returns sanitized corner radius value

Definition at line 168 of file pns_meander.cpp.

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 m_cornerRadiusPercentage
rounding percentage (0 - 100)
Definition: pns_meander.h:91
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
bool m_dual
dual or single line
Definition: pns_meander.h:363
int spacing() const
returns sanitized spacing value

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

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

◆ End()

VECTOR2I PNS::MEANDER_SHAPE::End ( ) const
inline

Function End()

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

Definition at line 234 of file pns_meander.h.

235  {
236  return m_clippedBaseSeg.B;
237  }
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:377
VECTOR2I B
Definition: seg.h:48

References SEG::B, and m_clippedBaseSeg.

Referenced by Fit().

◆ Fit()

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.

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:379
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:35
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:373
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:383
virtual bool CheckFit(MEANDER_SHAPE *aShape)
Function CheckFit()
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:359
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:361
int m_width
width of the line
Definition: pns_meander.h:365
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:381
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:367
std::vector< ssize_t > m_shapes
Array of indices that refer to the index of the shape if the point is part of a larger shape,...
VECTOR2I A
Definition: seg.h:47
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:375
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:363
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:118
VECTOR2I B
Definition: seg.h:48

References SEG::A, 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, 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().

◆ forward()

void PNS::MEANDER_SHAPE::forward ( int  aLength)
private

moves turtle forward by aLength

Definition at line 289 of file pns_meander.cpp.

290 {
291  m_currentPos += m_currentDir.Resize( aLength );
293 }
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:389
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392
VECTOR2D m_currentPos
current turtle position
Definition: pns_meander.h:387
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:385

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

Referenced by genMeanderShape(), and uShape().

◆ genMeanderShape()

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.

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.SetPoint( i, reflect( lc.CPoint( i ), axis ) );
417  }
418 
419  return lc;
420 }
void uShape(int aSides, int aCorner, int aTop)
tells the turtle to draw an U-like shape
void SetPoint(int aIndex, const VECTOR2I &aPos)
Accessor Function to move a point to a specific location.
int PointCount() const
Function PointCount()
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
const VECTOR2I & CPoint(int aIndex) const
Function Point()
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:371
void turn(int aAngle)
turns the turtle by aAngle
void forward(int aLength)
moves turtle forward by aLength
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
Definition: seg.h:39
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392
SHAPE_LINE_CHAIN.
int cornerRadius() const
returns sanitized corner radius value
VECTOR2I reflect(VECTOR2I aP, const SEG &aLine)
reflects a point onto other side of a given segment
int spacing() const
returns sanitized spacing value

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

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

◆ IsDual()

bool PNS::MEANDER_SHAPE::IsDual ( ) const
inline

Function IsDual()

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

Definition at line 214 of file pns_meander.h.

215  {
216  return m_dual;
217  }
bool m_dual
dual or single line
Definition: pns_meander.h:363

References m_dual.

◆ MakeCorner()

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.

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:381
VECTOR2I A
Definition: seg.h:47
void Clear()
Function Clear() Removes all points from the line chain.
void SetType(MEANDER_TYPE aType)
Function SetType()
Definition: pns_meander.h:138
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:377
VECTOR2I B
Definition: seg.h:48

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

◆ MakeEmpty()

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.

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:379
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:373
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:359
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:381
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369
VECTOR2I A
Definition: seg.h:47
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:363
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:377
VECTOR2I B
Definition: seg.h:48

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

◆ makeMiterShape()

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.

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 > Perpendicular() const
Function Perpendicular computes the perpendicular vector.
Definition: vector2d.h:320
MEANDER_STYLE m_cornerStyle
type of corners for the meandered line
Definition: pns_meander.h:89
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
int m_meanCornerRadius
average radius of meander corners (for correction of DP meanders)
Definition: pns_meander.h:371
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:361
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
int m_cornerArcSegments
number of line segments for arc approximation
Definition: pns_meander.h:95
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392
SHAPE_LINE_CHAIN.
bool m_dual
dual or single line
Definition: pns_meander.h:363
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:299
virtual const MEANDER_SETTINGS & MeanderSettings() const
Function MeanderSettings()

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

◆ MaxTunableLength()

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.

624 {
625  return CLine( 0 ).Length();
626 }
long long int Length() const
Function Length()
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Function CLine()
Definition: pns_meander.h:244

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

◆ miter()

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.

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 }
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:389
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
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
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:377
SHAPE_LINE_CHAIN.
VECTOR2D m_currentPos
current turtle position
Definition: pns_meander.h:387
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:385

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

◆ Recalculate()

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.

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:379
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:373
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:359
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:381
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:367
VECTOR2I A
Definition: seg.h:47
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:375
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:363
VECTOR2I B
Definition: seg.h:48

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

◆ reflect()

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.

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 }
VECTOR2I::extended_type ecoord
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:492
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
Definition: util.h:95

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

Referenced by genMeanderShape().

◆ Resize()

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.

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:367

References m_amplitude, and Recalculate().

◆ SetBaseIndex()

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 158 of file pns_meander.h.

159  {
160  m_baseIndex = aIndex;
161  }
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:383

References m_baseIndex.

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

◆ SetBaselineOffset()

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 320 of file pns_meander.h.

321  {
322  m_baselineOffset = aOffset;
323  }
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369

References m_baselineOffset.

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

◆ Settings()

const MEANDER_SETTINGS & PNS::MEANDER_SHAPE::Settings ( ) const

Function Settings()

Returns
the current meandering settings.

Definition at line 34 of file pns_meander.cpp.

35 {
36  return m_placer->MeanderSettings();
37 }
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:361
virtual const MEANDER_SETTINGS & MeanderSettings() const
Function MeanderSettings()

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

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

◆ SetType()

void PNS::MEANDER_SHAPE::SetType ( MEANDER_TYPE  aType)
inline

Function SetType()

Sets the type of the meander.

Definition at line 138 of file pns_meander.h.

139  {
140  m_type = aType;
141  }
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:359

References m_type.

Referenced by MakeCorner().

◆ Side()

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 224 of file pns_meander.h.

225  {
226  return m_side;
227  }
bool m_side
side (true = right)
Definition: pns_meander.h:379

References m_side.

◆ spacing()

int PNS::MEANDER_SHAPE::spacing ( ) const
private

returns sanitized spacing value

Definition at line 177 of file pns_meander.cpp.

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 }
int m_width
width of the line
Definition: pns_meander.h:365
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
bool m_dual
dual or single line
Definition: pns_meander.h:363

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

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

◆ start()

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.

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:389
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:387
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:385

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

Referenced by genMeanderShape().

◆ turn()

void PNS::MEANDER_SHAPE::turn ( int  aAngle)
private

turns the turtle by aAngle

Definition at line 296 of file pns_meander.cpp.

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:377
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:385

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

Referenced by genMeanderShape(), and miter().

◆ Type()

MEANDER_TYPE PNS::MEANDER_SHAPE::Type ( ) const
inline

Function Type()

Returns
the type of the meander.

Definition at line 148 of file pns_meander.h.

149  {
150  return m_type;
151  }
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:359

References m_type.

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

◆ updateBaseSegment()

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.

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 }
const VECTOR2I & CPoint(int aIndex) const
Function Point()
VECTOR2I LineProject(const VECTOR2I &aP) const
Function LineProject()
Definition: seg.h:362
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Function CLine()
Definition: pns_meander.h:244
VECTOR2I A
Definition: seg.h:47
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:375
bool m_dual
dual or single line
Definition: pns_meander.h:363
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:377
VECTOR2I B
Definition: seg.h:48

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

◆ uShape()

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.

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

References forward(), and miter().

Referenced by genMeanderShape().

◆ Width()

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

Function Width()

Returns
width of the meandered line.

Definition at line 308 of file pns_meander.h.

309  {
310  return m_width;
311  }
int m_width
width of the line
Definition: pns_meander.h:365

References m_width.

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

Friends And Related Function Documentation

◆ MEANDERED_LINE

friend class MEANDERED_LINE
friend

Definition at line 326 of file pns_meander.h.

Member Data Documentation

◆ m_amplitude

int PNS::MEANDER_SHAPE::m_amplitude
private

amplitude of the meander

Definition at line 367 of file pns_meander.h.

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

◆ m_baseIndex

int PNS::MEANDER_SHAPE::m_baseIndex
private

index of the meandered segment in the base line

Definition at line 383 of file pns_meander.h.

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

◆ m_baselineOffset

int PNS::MEANDER_SHAPE::m_baselineOffset
private

offset wrs the base segment (dual only)

Definition at line 369 of file pns_meander.h.

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

◆ m_baseSeg

SEG PNS::MEANDER_SHAPE::m_baseSeg
private

base segment (unclipped)

Definition at line 375 of file pns_meander.h.

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

◆ m_clippedBaseSeg

SEG PNS::MEANDER_SHAPE::m_clippedBaseSeg
private

base segment (clipped)

Definition at line 377 of file pns_meander.h.

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

◆ m_currentDir

VECTOR2D PNS::MEANDER_SHAPE::m_currentDir
private

current turtle direction

Definition at line 385 of file pns_meander.h.

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

◆ m_currentPos

VECTOR2D PNS::MEANDER_SHAPE::m_currentPos
private

current turtle position

Definition at line 387 of file pns_meander.h.

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

◆ m_currentTarget

SHAPE_LINE_CHAIN* PNS::MEANDER_SHAPE::m_currentTarget
private

the line the turtle is drawing on

Definition at line 389 of file pns_meander.h.

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

◆ m_dual

bool PNS::MEANDER_SHAPE::m_dual
private

dual or single line

Definition at line 363 of file pns_meander.h.

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

◆ m_meanCornerRadius

int PNS::MEANDER_SHAPE::m_meanCornerRadius
private

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

Definition at line 371 of file pns_meander.h.

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

◆ m_p0

VECTOR2I PNS::MEANDER_SHAPE::m_p0
private

first point of the meandered line

Definition at line 373 of file pns_meander.h.

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

◆ m_placer

MEANDER_PLACER_BASE* PNS::MEANDER_SHAPE::m_placer
private

the placer that placed this meander

Definition at line 361 of file pns_meander.h.

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

◆ m_shapes

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

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

Definition at line 381 of file pns_meander.h.

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

◆ m_side

bool PNS::MEANDER_SHAPE::m_side
private

side (true = right)

Definition at line 379 of file pns_meander.h.

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

◆ m_type

MEANDER_TYPE PNS::MEANDER_SHAPE::m_type
private

the type

Definition at line 359 of file pns_meander.h.

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

◆ m_width

int PNS::MEANDER_SHAPE::m_width
private

width of the line

Definition at line 365 of file pns_meander.h.

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


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