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

109  :
110  m_placer( aPlacer ),
111  m_dual( aIsDual ),
112  m_width( aWidth ),
113  m_baselineOffset( 0 )
114  {
115  // Do not leave uninitialized members, and keep static analyzer quiet:
116  m_type = MT_SINGLE;
117  m_amplitude = 0;
118  m_side = false;
119  m_baseIndex = 0;
121  m_meanCornerRadius = 0;
122  }
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:344
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:359
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:350
#define NULL
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:314
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:332
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:317
int m_width
Amplitude of the meander.
Definition: pns_meander.h:323
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:329
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:326
bool m_dual
Width of the line.
Definition: pns_meander.h:320

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
Returns
the amplitude of the meander shape.

Definition at line 159 of file pns_meander.h.

160  {
161  return m_amplitude;
162  }
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:326

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

152  {
153  return m_baseIndex;
154  }
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:350

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

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

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

241  {
242  return m_clippedBaseSeg;
243  }
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:341

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

214  {
215  return m_shapes[aShape];
216  }
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:347

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:90
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
bool m_dual
Width of the line.
Definition: pns_meander.h:320
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 205 of file pns_meander.h.

206  {
207  return m_clippedBaseSeg.B;
208  }
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:341
VECTOR2I B
Definition: seg.h:50

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

410 {
411  const MEANDER_SETTINGS& st = Settings();
412 
413  bool checkMode = false;
414  MEANDER_TYPE prim1, prim2;
415 
416  if( aType == MT_CHECK_START )
417  {
418  prim1 = MT_START;
419  prim2 = MT_TURN;
420  checkMode = true;
421  }
422  else if( aType == MT_CHECK_FINISH )
423  {
424  prim1 = MT_TURN;
425  prim2 = MT_FINISH;
426  checkMode = true;
427  }
428 
429  if( checkMode )
430  {
433 
434  m1.SetBaselineOffset( m_baselineOffset );
435  m2.SetBaselineOffset( m_baselineOffset );
436 
437  bool c1 = m1.Fit( prim1, aSeg, aP, aSide );
438  bool c2 = false;
439 
440  if( c1 )
441  c2 = m2.Fit( prim2, aSeg, m1.End(), !aSide );
442 
443  if( c1 && c2 )
444  {
445  m_type = prim1;
446  m_shapes[0] = m1.m_shapes[0];
447  m_shapes[1] = m1.m_shapes[1];
448  m_baseSeg =aSeg;
449  m_p0 = aP;
450  m_side = aSide;
451  m_amplitude = m1.Amplitude();
452  m_dual = m1.m_dual;
453  m_baseSeg = m1.m_baseSeg;
454  m_baseIndex = m1.m_baseIndex;
456  m_baselineOffset = m1.m_baselineOffset;
457  return true;
458  } else
459  return false;
460  }
461 
462  int minAmpl = st.m_minAmplitude;
463  int maxAmpl = st.m_maxAmplitude;
464 
465  if( m_dual )
466  {
467  minAmpl = std::max( minAmpl, 2 * std::abs( m_baselineOffset ) );
468  maxAmpl = std::max( maxAmpl, 2 * std::abs( m_baselineOffset ) );
469  }
470 
471  for( int ampl = maxAmpl; ampl >= minAmpl; ampl -= st.m_step )
472  {
473  if( m_dual )
474  {
475  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, m_baselineOffset );
476  m_shapes[1] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, -m_baselineOffset );
477  }
478  else
479  {
480  m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, ampl, 0 );
481  }
482 
483  m_type = aType;
484  m_baseSeg = aSeg;
485  m_p0 = aP;
486  m_side = aSide;
487  m_amplitude = ampl;
488 
490 
491  if( m_placer->CheckFit( this ) )
492  return true;
493  }
494 
495  return false;
496 }
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:344
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:37
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:335
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:350
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:314
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:317
int m_width
Amplitude of the 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:347
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:329
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:326
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:49
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:338
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:320
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:109
VECTOR2I B
Definition: seg.h:50

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

251 {
252  m_currentPos += m_currentDir.Resize( aLength );
254 }
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:359
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
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:356
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:353

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

293 {
294  const MEANDER_SETTINGS& st = Settings();
295  int cr = cornerRadius();
296  int offset = aBaselineOffset;
297  int spc = spacing();
298 
299  if( aSide )
300  offset *= -1;
301 
302  VECTOR2D dir_u_b( aDir.Resize( offset ) );
303  VECTOR2D dir_v_b( dir_u_b.Perpendicular() );
304 
305  if( 2 * cr > aAmpl )
306  {
307  cr = aAmpl / 2;
308  }
309 
310  if( 2 * cr > spc )
311  {
312  cr = spc / 2;
313  }
314 
315  m_meanCornerRadius = cr;
316 
317  SHAPE_LINE_CHAIN lc;
318 
319  start( &lc, aP + dir_v_b, aDir );
320 
321  switch( aType )
322  {
323  case MT_EMPTY:
324  {
325  lc.Append( aP + dir_v_b + aDir );
326  break;
327  }
328  case MT_START:
329  {
330  miter( cr - offset, false );
331  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
332  forward( std::min( cr - offset, cr + offset ) );
333  forward( std::abs( offset ) );
334 
335  break;
336  }
337 
338  case MT_FINISH:
339  {
340  start( &lc, aP - dir_u_b, aDir );
341  turn( 90 );
342  forward( std::min( cr - offset, cr + offset ) );
343  forward( std::abs( offset ) );
344  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
345  miter( cr - offset, false );
346  break;
347  }
348 
349  case MT_TURN:
350  {
351  start( &lc, aP - dir_u_b, aDir );
352  turn( 90 );
353  forward( std::abs( offset ) );
354  uShape( aAmpl - cr, cr + offset, spc - 2 * cr );
355  forward( std::abs( offset ) );
356  break;
357  }
358 
359  case MT_SINGLE:
360  {
361  miter( cr - offset, false );
362  uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
363  miter( cr - offset, false );
364  lc.Append( aP + dir_v_b + aDir.Resize( 2 * st.m_spacing ) );
365  break;
366  }
367 
368  default:
369  break;
370  }
371 
372  if( aSide )
373  {
374  SEG axis( aP, aP + aDir );
375 
376  lc.Mirror( axis );
377  }
378 
379  return lc;
380 }
void uShape(int aSides, int aCorner, int aTop)
Generate a 90-degree circular arc.
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
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:332
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.
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
Definition: seg.h:41
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404
SHAPE_LINE_CHAIN.
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 })
Mirrors the line points about y or x (or both)

References SHAPE_LINE_CHAIN::Append(), cornerRadius(), forward(), m_meanCornerRadius, PNS::MEANDER_SETTINGS::m_spacing, SHAPE_LINE_CHAIN::Mirror(), miter(), PNS::MT_EMPTY, PNS::MT_FINISH, PNS::MT_SINGLE, PNS::MT_START, PNS::MT_TURN, VECTOR2< T >::Resize(), Settings(), 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 189 of file pns_meander.h.

190  {
191  return m_dual;
192  }
bool m_dual
Width of the line.
Definition: pns_meander.h:320

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

548 {
549  SetType( MT_CORNER );
550  m_shapes[0].Clear();
551  m_shapes[1].Clear();
552  m_shapes[0].Append( aP1 );
553  m_shapes[1].Append( aP2 );
554  m_clippedBaseSeg.A = aP1;
555  m_clippedBaseSeg.B = aP1;
556 }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:347
VECTOR2I A
Definition: seg.h:49
void Clear()
Function Clear() Removes all points from the line chain.
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:127
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:341
VECTOR2I B
Definition: seg.h:50

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

522 {
524 
526 
527  m_type = MT_EMPTY;
528 
530 
531  if( m_dual )
533 }
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:344
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:335
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:314
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:347
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:329
VECTOR2I A
Definition: seg.h:49
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:320
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:341
VECTOR2I B
Definition: seg.h:50

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

189 {
190  SHAPE_LINE_CHAIN lc;
191 
192  if( aDir.EuclideanNorm( ) == 0.0f )
193  {
194  lc.Append( aP );
195  return lc;
196  }
197 
198  VECTOR2D dir_u( aDir );
199  VECTOR2D dir_v( aDir.Perpendicular( ) );
200  VECTOR2D p = aP;
201  lc.Append( ( int ) p.x, ( int ) p.y );
202 
203 
204  // fixme: refactor
206  {
207  case MEANDER_STYLE_ROUND:
208  {
209  VECTOR2D center = aP + dir_v * ( aSide ? -1.0 : 1.0 );
210 
211  lc.Append( SHAPE_ARC( center, aP, ( aSide ? -90 : 90 ) ) );
212  }
213  break;
214 
216  {
217  double radius = (double) aDir.EuclideanNorm();
218  double correction = 0;
219  if( m_dual && radius > m_meanCornerRadius )
220  correction = (double)( -2 * abs(m_baselineOffset) ) * tan( 22.5 * M_PI / 180.0 );
221 
222  VECTOR2D dir_cu = dir_u.Resize( correction );
223  VECTOR2D dir_cv = dir_v.Resize( correction );
224 
225  p = aP - dir_cu;
226  lc.Append( ( int ) p.x, ( int ) p.y );
227  p = aP + dir_u + (dir_v + dir_cv) * ( aSide ? -1.0 : 1.0 );
228  lc.Append( ( int ) p.x, ( int ) p.y );
229  }
230  break;
231  }
232 
233  p = aP + dir_u + dir_v * ( aSide ? -1.0 : 1.0 );
234  lc.Append( ( int ) p.x, ( int ) p.y );
235 
236  return lc;
237 }
VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition: vector2d.h:314
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:88
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:332
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:317
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:329
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404
SHAPE_LINE_CHAIN.
bool m_dual
Width of the line.
Definition: pns_meander.h:320
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 583 of file pns_meander.cpp.

584 {
585  return CLine( 0 ).Length();
586 }
long long int Length() const
Function Length()
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:213

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

264 {
265  if( aRadius <= 0 )
266  {
267  turn( aSide ? -90 : 90 );
268  return;
269  }
270 
271  VECTOR2D dir = m_currentDir.Resize( (double) aRadius );
272  SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
273 
274  m_currentPos = lc.CPoint( -1 );
275  m_currentDir = dir.Rotate( aSide ? -M_PI / 2.0 : M_PI / 2.0 );
276 
277  m_currentTarget->Append( lc );
278 }
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:359
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)
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
SHAPE_LINE_CHAIN.
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:356
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:353

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

500 {
502 
503  if( m_dual )
505 
507 }
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:344
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:335
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:314
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:347
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:329
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:326
VECTOR2I A
Definition: seg.h:49
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:338
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:320
VECTOR2I B
Definition: seg.h:50

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

511 {
512  if( aAmpl < 0 )
513  return;
514 
515  m_amplitude = aAmpl;
516 
517  Recalculate();
518 }
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:326

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

144  {
145  m_baseIndex = aIndex;
146  }
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:350

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

275  {
276  m_baselineOffset = aOffset;
277  }
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:329

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:317
virtual const MEANDER_SETTINGS & MeanderSettings() const
Return the current meandering configuration.

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

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

◆ SetType()

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

Set the type of the meander.

Definition at line 127 of file pns_meander.h.

128  {
129  m_type = aType;
130  }
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:314

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

198  {
199  return m_side;
200  }
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:344

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  return std::max( 2 * m_width, Settings().m_spacing );
180  else
181  {
182  int sp = 2 * ( m_width + std::abs( m_baselineOffset ) );
183  return std::max( sp, Settings().m_spacing );
184  }
185 }
int m_width
Amplitude of the meander.
Definition: pns_meander.h:323
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:329
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
bool m_dual
Width of the line.
Definition: pns_meander.h:320

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

Move turtle forward by aLength.

Definition at line 240 of file pns_meander.cpp.

241 {
242  m_currentTarget = aTarget;
244  m_currentTarget->Append( aWhere );
245  m_currentDir = aDir;
246  m_currentPos = aWhere;
247 }
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:359
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
The line the turtle is drawing on.
Definition: pns_meander.h:356
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:353

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

258 {
259  m_currentDir = m_currentDir.Rotate( (double) aAngle * M_PI / 180.0 );
260 }
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:353

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

136  {
137  return m_type;
138  }
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:314

References m_type.

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

◆ updateBaseSegment()

void PNS::MEANDER_SHAPE::updateBaseSegment ( )
private

Return sanitized corner radius value.

Definition at line 589 of file pns_meander.cpp.

590 {
591  if( m_dual )
592  {
593  VECTOR2I midpA = ( CLine( 0 ).CPoint( 0 ) + CLine( 1 ).CPoint( 0 ) ) / 2;
594  VECTOR2I midpB = ( CLine( 0 ).CPoint( -1 ) + CLine( 1 ).CPoint( -1 ) ) / 2;
595 
598  }
599  else
600  {
601  m_clippedBaseSeg.A = m_baseSeg.LineProject( CLine( 0 ).CPoint( 0 ) );
602  m_clippedBaseSeg.B = m_baseSeg.LineProject( CLine( 0 ).CPoint( -1 ) );
603  }
604 }
const VECTOR2I & CPoint(int aIndex) const
Function Point()
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
Definition: seg.h:404
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:213
VECTOR2I A
Definition: seg.h:49
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:338
bool m_dual
Width of the line.
Definition: pns_meander.h:320
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:341
VECTOR2I B
Definition: seg.h:50

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

282 {
283  forward( aSides );
284  miter( aCorner, true );
285  forward( aTop );
286  miter( aCorner, true );
287  forward( aSides );
288 }
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 263 of file pns_meander.h.

264  {
265  return m_width;
266  }
int m_width
Amplitude of the meander.
Definition: pns_meander.h:323

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 280 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 326 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 350 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 329 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 338 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 341 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 353 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 356 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 359 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 320 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 332 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 335 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 317 of file pns_meander.h.

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

◆ m_shapes

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

Index of the meandered segment in the base line.

Definition at line 347 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 344 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 314 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 323 of file pns_meander.h.

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


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