KiCad PCB EDA Suite
PNS::MEANDER_SHAPE Class Reference

The geometry of a single meander. More...

#include <pns_meander.h>

Public Member Functions

 MEANDER_SHAPE (MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
 
void SetType (MEANDER_TYPE aType)
 Set the type of the meander. More...
 
MEANDER_TYPE Type () const
 
void SetBaseIndex (int aIndex)
 Set an auxiliary index of the segment being meandered in its original LINE. More...
 
int BaseIndex () const
 
int Amplitude () const
 
void MakeCorner (VECTOR2I aP1, VECTOR2I aP2=VECTOR2I(0, 0))
 Create a dummy meander shape representing a line corner. More...
 
void Resize (int aAmpl)
 Change the amplitude of the meander shape to aAmpl and recalculates the resulting line chain. More...
 
void Recalculate ()
 Recalculate the line chain representing the meander's shape. More...
 
bool IsDual () const
 
bool Side () const
 
VECTOR2I End () const
 
const SHAPE_LINE_CHAINCLine (int aShape) const
 
void MakeEmpty ()
 Replace the meander with straight bypass line(s), effectively clearing it. More...
 
bool Fit (MEANDER_TYPE aType, const SEG &aSeg, const VECTOR2I &aP, bool aSide)
 Attempt to fit a meander of a given type onto a segment, avoiding collisions with other board features. More...
 
const SEGBaseSegment () const
 Return the base segment the meander was fitted to. More...
 
int BaselineLength () const
 
int MaxTunableLength () const
 
const MEANDER_SETTINGSSettings () const
 
int Width () const
 
void SetBaselineOffset (int aOffset)
 Set the parallel offset between the base segment and the meandered line. More...
 

Private Member Functions

void start (SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
 Move turtle forward by aLength. More...
 
void forward (int aLength)
 Turn the turtle by aAngle. More...
 
void turn (int aAngle)
 Tell the turtle to draw a mitered corner of given radius and turn direction. More...
 
void miter (int aRadius, bool aSide)
 Tell the turtle to draw an U-like shape. More...
 
void uShape (int aSides, int aCorner, int aTop)
 Generate a 90-degree circular arc. More...
 
SHAPE_LINE_CHAIN makeMiterShape (VECTOR2D aP, VECTOR2D aDir, bool aSide)
 Produce a meander shape of given type. More...
 
SHAPE_LINE_CHAIN genMeanderShape (VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
 Recalculate the clipped baseline after the parameters of the meander have been changed. More...
 
void updateBaseSegment ()
 Return sanitized corner radius value. More...
 
int cornerRadius () const
 Return sanitized spacing value. More...
 
int spacing () const
 The type of meander. More...
 

Private Attributes

MEANDER_TYPE m_type
 The placer that placed this meander. More...
 
MEANDER_PLACER_BASEm_placer
 Dual or single line. More...
 
bool m_dual
 Width of the line. More...
 
int m_width
 Amplitude of the meander. More...
 
int m_amplitude
 Offset wrs the base segment (dual only). More...
 
int m_baselineOffset
 Average radius of meander corners (for correction of DP meanders). More...
 
int m_meanCornerRadius
 First point of the meandered line. More...
 
VECTOR2I m_p0
 Base segment (unclipped). More...
 
SEG m_baseSeg
 Base segment (clipped). More...
 
SEG m_clippedBaseSeg
 Side (true = right). More...
 
bool m_side
 The actual shapes (0 used for single, both for dual). More...
 
SHAPE_LINE_CHAIN m_shapes [2]
 Index of the meandered segment in the base line. More...
 
int m_baseIndex
 The current turtle direction. More...
 
VECTOR2D m_currentDir
 The current turtle position. More...
 
VECTOR2D m_currentPos
 The line the turtle is drawing on. More...
 
SHAPE_LINE_CHAINm_currentTarget
 

Friends

class MEANDERED_LINE
 Start turtle drawing. More...
 

Detailed Description

The geometry of a single meander.

Definition at line 109 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
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 uninitialized members, and keep static analyzer quiet:
125  m_type = MT_SINGLE;
126  m_amplitude = 0;
127  m_side = false;
128  m_baseIndex = 0;
129  m_currentTarget = nullptr;
130  m_meanCornerRadius = 0;
131  }
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:353
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:368
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:359
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:323
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:341
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:326
int m_width
Amplitude of the meander.
Definition: pns_meander.h:332
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:335
bool m_dual
Width of the line.
Definition: pns_meander.h:329

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

Member Function Documentation

◆ Amplitude()

int PNS::MEANDER_SHAPE::Amplitude ( ) const
inline
Returns
the amplitude of the meander shape.

Definition at line 168 of file pns_meander.h.

169  {
170  return m_amplitude;
171  }
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:335

References m_amplitude.

Referenced by Fit().

◆ BaseIndex()

int PNS::MEANDER_SHAPE::BaseIndex ( ) const
inline
Returns
auxiliary index of the segment being meandered in its original LINE.

Definition at line 160 of file pns_meander.h.

161  {
162  return m_baseIndex;
163  }
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:359

References m_baseIndex.

◆ BaselineLength()

int PNS::MEANDER_SHAPE::BaselineLength ( ) const
Returns
length of the base segment for the meander (i.e.the minimum tuned length).

Definition at line 578 of file pns_meander.cpp.

579 {
580  return m_clippedBaseSeg.Length();
581 }
int Length() const
Return the length (this).
Definition: seg.h:350
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:350

References SEG::Length(), and m_clippedBaseSeg.

◆ BaseSegment()

const SEG& PNS::MEANDER_SHAPE::BaseSegment ( ) const
inline

Return the base segment the meander was fitted to.

Returns
the base segment.

Definition at line 249 of file pns_meander.h.

250  {
251  return m_clippedBaseSeg;
252  }
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:350

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
Returns
the line chain representing the shape of the meander.

Definition at line 222 of file pns_meander.h.

223  {
224  return m_shapes[aShape];
225  }
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:356

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

Return sanitized spacing value.

Definition at line 167 of file pns_meander.cpp.

168 {
169  // TODO: fix diff-pair meandering so we can use non-100% radii
170  int rPercent = m_dual ? 100 : Settings().m_cornerRadiusPercentage;
171 
172  return (int64_t) spacing() * rPercent / 200;
173 }
int m_cornerRadiusPercentage
Allowable tuning error.
Definition: pns_meander.h:97
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
bool m_dual
Width of the line.
Definition: pns_meander.h:329
int spacing() const
The type of meander.

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
Returns
end vertex of the base segment of the meander shape.

Definition at line 214 of file pns_meander.h.

215  {
216  return m_clippedBaseSeg.B;
217  }
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:350
VECTOR2I B
Definition: seg.h:49

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 
)

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

411 {
412  const MEANDER_SETTINGS& st = Settings();
413 
414  bool checkMode = false;
415  MEANDER_TYPE prim1, prim2;
416 
417  if( aType == MT_CHECK_START )
418  {
419  prim1 = MT_START;
420  prim2 = MT_TURN;
421  checkMode = true;
422  }
423  else if( aType == MT_CHECK_FINISH )
424  {
425  prim1 = MT_TURN;
426  prim2 = MT_FINISH;
427  checkMode = true;
428  }
429 
430  if( checkMode )
431  {
434 
435  m1.SetBaselineOffset( m_baselineOffset );
436  m2.SetBaselineOffset( m_baselineOffset );
437 
438  bool c1 = m1.Fit( prim1, aSeg, aP, aSide );
439  bool c2 = false;
440 
441  if( c1 )
442  c2 = m2.Fit( prim2, aSeg, m1.End(), !aSide );
443 
444  if( c1 && c2 )
445  {
446  m_type = prim1;
447  m_shapes[0] = m1.m_shapes[0];
448  m_shapes[1] = m1.m_shapes[1];
449  m_baseSeg =aSeg;
450  m_p0 = aP;
451  m_side = aSide;
452  m_amplitude = m1.Amplitude();
453  m_dual = m1.m_dual;
454  m_baseSeg = m1.m_baseSeg;
455  m_baseIndex = m1.m_baseIndex;
457  m_baselineOffset = m1.m_baselineOffset;
458  return true;
459  } else
460  return false;
461  }
462 
463  int minAmpl = st.m_minAmplitude;
464  int maxAmpl = st.m_maxAmplitude;
465 
466  if( m_dual )
467  {
468  minAmpl = std::max( minAmpl, 2 * std::abs( m_baselineOffset ) );
469  maxAmpl = std::max( maxAmpl, 2 * std::abs( m_baselineOffset ) );
470  }
471 
472  for( int ampl = maxAmpl; ampl >= minAmpl; ampl -= st.m_step )
473  {
474  if( m_dual )
475  {
476  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, m_baselineOffset );
477  m_shapes[1] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, -m_baselineOffset );
478  }
479  else
480  {
481  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, 0 );
482  }
483 
484  m_type = aType;
485  m_baseSeg = aSeg;
486  m_p0 = aP;
487  m_side = aSide;
488  m_amplitude = ampl;
489 
491 
492  if( m_placer->CheckFit( this ) )
493  return true;
494  }
495 
496  return false;
497 }
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
Recalculate the clipped baseline after the parameters of the meander have been changed.
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:353
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:37
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:344
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:359
virtual bool CheckFit(MEANDER_SHAPE *aShape)
Checks if it's OK to place the shape aShape (i.e.
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:323
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:326
int m_width
Amplitude of the meander.
Definition: pns_meander.h:332
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:356
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:335
std::vector< std::pair< ssize_t, 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:48
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:347
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:329
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:118
VECTOR2I B
Definition: seg.h:49

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

Turn the turtle by aAngle.

Definition at line 252 of file pns_meander.cpp.

253 {
254  m_currentPos += m_currentDir.Resize( aLength );
256 }
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:368
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:365
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:362

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

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

Definition at line 293 of file pns_meander.cpp.

295 {
296  int cr = cornerRadius();
297  int offset = aBaselineOffset;
298  int spc = spacing();
299 
300  if( aSide )
301  offset *= -1;
302 
303  VECTOR2D dir_u_b( aDir.Resize( offset ) );
304  VECTOR2D dir_v_b( dir_u_b.Perpendicular() );
305 
306  if( 2 * cr > aAmpl )
307  {
308  cr = aAmpl / 2;
309  }
310 
311  if( 2 * cr > spc )
312  {
313  cr = spc / 2;
314  }
315 
316  m_meanCornerRadius = cr;
317 
318  SHAPE_LINE_CHAIN lc;
319 
320  start( &lc, aP + dir_v_b, aDir );
321 
322  switch( aType )
323  {
324  case MT_EMPTY:
325  {
326  lc.Append( aP + dir_v_b + aDir );
327  break;
328  }
329  case MT_START:
330  {
331  miter( cr - offset, false );
332  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
333  forward( std::min( cr - offset, cr + offset ) );
334  forward( std::abs( offset ) );
335 
336  break;
337  }
338 
339  case MT_FINISH:
340  {
341  start( &lc, aP - dir_u_b, aDir );
342  turn( 90 );
343  forward( std::min( cr - offset, cr + offset ) );
344  forward( std::abs( offset ) );
345  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
346  miter( cr - offset, false );
347  break;
348  }
349 
350  case MT_TURN:
351  {
352  start( &lc, aP - dir_u_b, aDir );
353  turn( 90 );
354  forward( std::abs( offset ) );
355  uShape( aAmpl - cr, cr + offset, spc - 2 * cr );
356  forward( std::abs( offset ) );
357  break;
358  }
359 
360  case MT_SINGLE:
361  {
362  miter( cr - offset, false );
363  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
364  miter( cr - offset, false );
365  lc.Append( aP + dir_v_b + aDir.Resize( 2 * spc ) );
366  break;
367  }
368 
369  default:
370  break;
371  }
372 
373  if( aSide )
374  {
375  SEG axis( aP, aP + aDir );
376 
377  lc.Mirror( axis );
378  }
379 
380  return lc;
381 }
void uShape(int aSides, int aCorner, int aTop)
Generate a 90-degree circular arc.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
void miter(int aRadius, bool aSide)
Tell the turtle to draw an U-like shape.
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
Move turtle forward by aLength.
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:341
void turn(int aAngle)
Tell the turtle to draw a mitered corner of given radius and turn direction.
void forward(int aLength)
Turn the turtle by aAngle.
Definition: seg.h:40
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404
Represent a polyline (an zero-thickness chain of connected line segments).
int cornerRadius() const
Return sanitized spacing value.
int spacing() const
The type of meander.
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both).

References SHAPE_LINE_CHAIN::Append(), cornerRadius(), forward(), m_meanCornerRadius, SHAPE_LINE_CHAIN::Mirror(), miter(), PNS::MT_EMPTY, PNS::MT_FINISH, PNS::MT_SINGLE, PNS::MT_START, PNS::MT_TURN, VECTOR2< T >::Resize(), spacing(), start(), turn(), and uShape().

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

◆ IsDual()

bool PNS::MEANDER_SHAPE::IsDual ( ) const
inline
Returns
true if the shape represents 2 parallel lines (diff pair).

Definition at line 198 of file pns_meander.h.

199  {
200  return m_dual;
201  }
bool m_dual
Width of the line.
Definition: pns_meander.h:329

References m_dual.

◆ MakeCorner()

void PNS::MEANDER_SHAPE::MakeCorner ( VECTOR2I  aP1,
VECTOR2I  aP2 = VECTOR2I( 0, 0 ) 
)

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

549 {
550  SetType( MT_CORNER );
551  m_shapes[0].Clear();
552  m_shapes[1].Clear();
553  m_shapes[0].Append( aP1 );
554  m_shapes[1].Append( aP2 );
555  m_clippedBaseSeg.A = aP1;
556  m_clippedBaseSeg.B = aP1;
557 }
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:356
VECTOR2I A
Definition: seg.h:48
void Clear()
Remove all points from the line chain.
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:136
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:350
VECTOR2I B
Definition: seg.h:49

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

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

Definition at line 522 of file pns_meander.cpp.

523 {
525 
527 
528  m_type = MT_EMPTY;
529 
531 
532  if( m_dual )
534 }
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
Recalculate the clipped baseline after the parameters of the meander have been changed.
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:353
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:344
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:323
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:356
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338
VECTOR2I A
Definition: seg.h:48
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:329
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:350
VECTOR2I B
Definition: seg.h:49

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

Produce a meander shape of given type.

Definition at line 190 of file pns_meander.cpp.

191 {
192  SHAPE_LINE_CHAIN lc;
193 
194  if( aDir.EuclideanNorm( ) == 0.0f )
195  {
196  lc.Append( aP );
197  return lc;
198  }
199 
200  VECTOR2D dir_u( aDir );
201  VECTOR2D dir_v( aDir.Perpendicular( ) );
202  VECTOR2D p = aP;
203  lc.Append( ( int ) p.x, ( int ) p.y );
204 
205 
206  // fixme: refactor
208  {
209  case MEANDER_STYLE_ROUND:
210  {
211  VECTOR2D center = aP + dir_v * ( aSide ? -1.0 : 1.0 );
212 
213  lc.Append( SHAPE_ARC( center, aP, ( aSide ? -90 : 90 ) ) );
214  }
215  break;
216 
218  {
219  double radius = (double) aDir.EuclideanNorm();
220  double correction = 0;
221  if( m_dual && radius > m_meanCornerRadius )
222  correction = (double)( -2 * abs(m_baselineOffset) ) * tan( 22.5 * M_PI / 180.0 );
223 
224  VECTOR2D dir_cu = dir_u.Resize( correction );
225  VECTOR2D dir_cv = dir_v.Resize( correction );
226 
227  p = aP - dir_cu;
228  lc.Append( ( int ) p.x, ( int ) p.y );
229  p = aP + dir_u + (dir_v + dir_cv) * ( aSide ? -1.0 : 1.0 );
230  lc.Append( ( int ) p.x, ( int ) p.y );
231  }
232  break;
233  }
234 
235  p = aP + dir_u + dir_v * ( aSide ? -1.0 : 1.0 );
236  lc.Append( ( int ) p.x, ( int ) p.y );
237 
238  return lc;
239 }
VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition: vector2d.h:314
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:94
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:341
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:326
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404
Represent a polyline (an zero-thickness chain of connected line segments).
bool m_dual
Width of the line.
Definition: pns_meander.h:329
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
virtual const MEANDER_SETTINGS & MeanderSettings() const
Return the current meandering configuration.

References SHAPE_LINE_CHAIN::Append(), VECTOR2< T >::EuclideanNorm(), m_baselineOffset, 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(), and VECTOR2< T >::Resize().

Referenced by miter().

◆ MaxTunableLength()

int PNS::MEANDER_SHAPE::MaxTunableLength ( ) const
Returns
the length of the fitted line chain.

Definition at line 584 of file pns_meander.cpp.

585 {
586  return CLine( 0 ).Length();
587 }
long long int Length() const
Return length of the line chain in Euclidean metric.
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:222

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

◆ miter()

void PNS::MEANDER_SHAPE::miter ( int  aRadius,
bool  aSide 
)
private

Tell the turtle to draw an U-like shape.

Definition at line 265 of file pns_meander.cpp.

266 {
267  if( aRadius <= 0 )
268  {
269  turn( aSide ? -90 : 90 );
270  return;
271  }
272 
273  VECTOR2D dir = m_currentDir.Resize( (double) aRadius );
274  SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
275 
276  m_currentPos = lc.CPoint( -1 );
277  m_currentDir = dir.Rotate( aSide ? -M_PI / 2.0 : M_PI / 2.0 );
278 
279  m_currentTarget->Append( lc );
280 }
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:368
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
SHAPE_LINE_CHAIN makeMiterShape(VECTOR2D aP, VECTOR2D aDir, bool aSide)
Produce a meander shape of given type.
void turn(int aAngle)
Tell the turtle to draw a mitered corner of given radius and turn direction.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
Represent a polyline (an zero-thickness chain of connected line segments).
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:365
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:362

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

Recalculate the line chain representing the meander's shape.

Definition at line 500 of file pns_meander.cpp.

501 {
503 
504  if( m_dual )
506 
508 }
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
Recalculate the clipped baseline after the parameters of the meander have been changed.
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:353
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:344
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:323
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:356
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:335
VECTOR2I A
Definition: seg.h:48
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:347
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:329
VECTOR2I B
Definition: seg.h:49

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

◆ Resize()

void PNS::MEANDER_SHAPE::Resize ( int  aAmpl)

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

Parameters
aAmplnew amplitude.

Definition at line 511 of file pns_meander.cpp.

512 {
513  if( aAmpl < 0 )
514  return;
515 
516  m_amplitude = aAmpl;
517 
518  Recalculate();
519 }
void Recalculate()
Recalculate the line chain representing the meander's shape.
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:335

References m_amplitude, and Recalculate().

◆ SetBaseIndex()

void PNS::MEANDER_SHAPE::SetBaseIndex ( int  aIndex)
inline

Set an auxiliary index of the segment being meandered in its original LINE.

Definition at line 152 of file pns_meander.h.

153  {
154  m_baseIndex = aIndex;
155  }
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:359

References m_baseIndex.

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

◆ SetBaselineOffset()

void PNS::MEANDER_SHAPE::SetBaselineOffset ( int  aOffset)
inline

Set the parallel offset between the base segment and the meandered line.

Used for dual meanders (diff pair) only.

Parameters
aOffsetthe offset.

Definition at line 283 of file pns_meander.h.

284  {
285  m_baselineOffset = aOffset;
286  }
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338

References m_baselineOffset.

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

◆ Settings()

const MEANDER_SETTINGS & PNS::MEANDER_SHAPE::Settings ( ) const
Returns
the current meandering settings.

Definition at line 33 of file pns_meander.cpp.

34 {
35  return m_placer->MeanderSettings();
36 }
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:326
virtual const MEANDER_SETTINGS & MeanderSettings() const
Return the current meandering configuration.

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

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

◆ SetType()

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

Set the type of the meander.

Definition at line 136 of file pns_meander.h.

137  {
138  m_type = aType;
139  }
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:323

References m_type.

Referenced by MakeCorner().

◆ Side()

bool PNS::MEANDER_SHAPE::Side ( ) const
inline
Returns
true if the meander is to the right of its base segment.

Definition at line 206 of file pns_meander.h.

207  {
208  return m_side;
209  }
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:353

References m_side.

◆ spacing()

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

The type of meander.

Definition at line 176 of file pns_meander.cpp.

177 {
178  if( !m_dual )
179  {
180  return std::max( m_width + m_placer->Clearance(), Settings().m_spacing );
181  }
182  else
183  {
184  int sp = m_width + m_placer->Clearance() + ( 2 * std::abs( m_baselineOffset ) );
185  return std::max( sp, Settings().m_spacing );
186  }
187 }
virtual int Clearance()
Return the clearance of the track(s) being length tuned.
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:326
int m_width
Amplitude of the meander.
Definition: pns_meander.h:332
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
bool m_dual
Width of the line.
Definition: pns_meander.h:329
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:82

References PNS::MEANDER_PLACER_BASE::Clearance(), m_baselineOffset, m_dual, m_placer, PNS::MEANDER_SETTINGS::m_spacing, 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

Move turtle forward by aLength.

Definition at line 242 of file pns_meander.cpp.

243 {
244  m_currentTarget = aTarget;
246  m_currentTarget->Append( aWhere );
247  m_currentDir = aDir;
248  m_currentPos = aWhere;
249 }
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:368
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
void Clear()
Remove all points from the line chain.
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:365
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:362

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

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

Definition at line 259 of file pns_meander.cpp.

260 {
261  m_currentDir = m_currentDir.Rotate( (double) aAngle * M_PI / 180.0 );
262 }
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:362

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

Referenced by genMeanderShape(), and miter().

◆ Type()

MEANDER_TYPE PNS::MEANDER_SHAPE::Type ( ) const
inline
Returns
the type of the meander.

Definition at line 144 of file pns_meander.h.

145  {
146  return m_type;
147  }
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:323

References m_type.

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

◆ updateBaseSegment()

void PNS::MEANDER_SHAPE::updateBaseSegment ( )
private

Return sanitized corner radius value.

Definition at line 590 of file pns_meander.cpp.

591 {
592  if( m_dual )
593  {
594  VECTOR2I midpA = ( CLine( 0 ).CPoint( 0 ) + CLine( 1 ).CPoint( 0 ) ) / 2;
595  VECTOR2I midpB = ( CLine( 0 ).CPoint( -1 ) + CLine( 1 ).CPoint( -1 ) ) / 2;
596 
599  }
600  else
601  {
602  m_clippedBaseSeg.A = m_baseSeg.LineProject( CLine( 0 ).CPoint( 0 ) );
603  m_clippedBaseSeg.B = m_baseSeg.LineProject( CLine( 0 ).CPoint( -1 ) );
604  }
605 }
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
Definition: seg.cpp:268
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:222
VECTOR2I A
Definition: seg.h:48
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:347
bool m_dual
Width of the line.
Definition: pns_meander.h:329
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:350
VECTOR2I B
Definition: seg.h:49

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

Generate a 90-degree circular arc.

Definition at line 283 of file pns_meander.cpp.

284 {
285  forward( aSides );
286  miter( aCorner, true );
287  forward( aTop );
288  miter( aCorner, true );
289  forward( aSides );
290 }
void miter(int aRadius, bool aSide)
Tell the turtle to draw an U-like shape.
void forward(int aLength)
Turn the turtle by aAngle.

References forward(), and miter().

Referenced by genMeanderShape().

◆ Width()

int PNS::MEANDER_SHAPE::Width ( ) const
inline
Returns
width of the meandered line.

Definition at line 272 of file pns_meander.h.

273  {
274  return m_width;
275  }
int m_width
Amplitude of the meander.
Definition: pns_meander.h:332

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

Start turtle drawing.

Definition at line 289 of file pns_meander.h.

Member Data Documentation

◆ m_amplitude

int PNS::MEANDER_SHAPE::m_amplitude
private

Offset wrs the base segment (dual only).

Definition at line 335 of file pns_meander.h.

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

◆ m_baseIndex

int PNS::MEANDER_SHAPE::m_baseIndex
private

The current turtle direction.

Definition at line 359 of file pns_meander.h.

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

◆ m_baselineOffset

int PNS::MEANDER_SHAPE::m_baselineOffset
private

Average radius of meander corners (for correction of DP meanders).

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

Definition at line 347 of file pns_meander.h.

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

◆ m_clippedBaseSeg

SEG PNS::MEANDER_SHAPE::m_clippedBaseSeg
private

Side (true = right).

Definition at line 350 of file pns_meander.h.

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

◆ m_currentDir

VECTOR2D PNS::MEANDER_SHAPE::m_currentDir
private

The current turtle position.

Definition at line 362 of file pns_meander.h.

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

◆ m_currentPos

VECTOR2D PNS::MEANDER_SHAPE::m_currentPos
private

The line the turtle is drawing on.

Definition at line 365 of file pns_meander.h.

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

◆ m_currentTarget

SHAPE_LINE_CHAIN* PNS::MEANDER_SHAPE::m_currentTarget
private

Definition at line 368 of file pns_meander.h.

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

◆ m_dual

bool PNS::MEANDER_SHAPE::m_dual
private

Width of the line.

Definition at line 329 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

First point of the meandered line.

Definition at line 341 of file pns_meander.h.

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

◆ m_p0

VECTOR2I PNS::MEANDER_SHAPE::m_p0
private

Base segment (unclipped).

Definition at line 344 of file pns_meander.h.

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

◆ m_placer

MEANDER_PLACER_BASE* PNS::MEANDER_SHAPE::m_placer
private

Dual or single line.

Definition at line 326 of file pns_meander.h.

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

◆ m_shapes

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

Index of the meandered segment in the base line.

Definition at line 356 of file pns_meander.h.

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

◆ m_side

bool PNS::MEANDER_SHAPE::m_side
private

The actual shapes (0 used for single, both for dual).

Definition at line 353 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 placer that placed this meander.

Definition at line 323 of file pns_meander.h.

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

◆ m_width

int PNS::MEANDER_SHAPE::m_width
private

Amplitude of the meander.

Definition at line 332 of file pns_meander.h.

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


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