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 (const VECTOR2I &aP1, const VECTOR2I &aP2=VECTOR2I(0, 0))
 Create a dummy meander shape representing a line corner. More...
 
void MakeArc (const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
 Create a dummy meander shape representing an arc 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
 
long long int CurrentLength () const
 
long long int MinTunableLength () const
 
int MinAmplitude () 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...
 
void SetTargetBaselineLength (int aLength)
 Sets the target length of the baseline. 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 (const EDA_ANGLE &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 (const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide)
 Produce a meander shape of given type. More...
 
SHAPE_LINE_CHAIN genMeanderShape (const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide, MEANDER_TYPE aType, 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
 Minimum length of the base segment to target when resizing. More...
 
int m_targetBaseLen
 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 114 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 123 of file pns_meander.h.

123 :
124 m_placer( aPlacer ),
125 m_dual( aIsDual ),
126 m_width( aWidth ),
128 {
129 // Do not leave uninitialized members, and keep static analyzer quiet:
131 m_amplitude = 0;
132 m_targetBaseLen = 0;
133 m_side = false;
134 m_baseIndex = 0;
135 m_currentTarget = nullptr;
137 }
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:356
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:359
int m_targetBaseLen
First point of the meandered line.
Definition: pns_meander.h:377
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:371
int m_width
Amplitude of the meander.
Definition: pns_meander.h:365
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:389
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:395
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:404
bool m_dual
Width of the line.
Definition: pns_meander.h:362
int m_meanCornerRadius
Minimum length of the base segment to target when resizing.
Definition: pns_meander.h:374
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:368
@ MT_SINGLE
Definition: pns_meander.h:38

References m_amplitude, m_baseIndex, m_currentTarget, m_meanCornerRadius, m_side, m_targetBaseLen, 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 174 of file pns_meander.h.

175 {
176 return m_amplitude;
177 }

References m_amplitude.

Referenced by PNS::findAmplitudeForLength(), and Fit().

◆ BaseIndex()

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

Definition at line 166 of file pns_meander.h.

167 {
168 return m_baseIndex;
169 }

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

697{
698 return m_clippedBaseSeg.Length();
699}
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:386
int Length() const
Return the length (this).
Definition: seg.h:326

References SEG::Length(), and m_clippedBaseSeg.

Referenced by PNS::findAmplitudeForLength(), MinTunableLength(), and PNS::MEANDER_PLACER_BASE::tuneLineLength().

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

265 {
266 return m_clippedBaseSeg;
267 }

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

238 {
239 return m_shapes[aShape];
240 }
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:392

References m_shapes.

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

◆ cornerRadius()

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

Return sanitized spacing value.

Definition at line 205 of file pns_meander.cpp.

206{
207 // TODO: fix diff-pair meandering so we can use non-100% radii
208 int rPercent = m_dual ? 100 : Settings().m_cornerRadiusPercentage;
209
210 int optCr = (int64_t) spacing() * rPercent / 200;
211 int minCr = std::abs( m_baselineOffset );
212 int maxCr = std::min( m_amplitude / 2, spacing() / 2 );
213
214 if( maxCr > minCr )
215 return std::clamp( optCr, minCr, maxCr );
216 else
217 return maxCr;
218}
int m_cornerRadiusPercentage
Place meanders on one side.
Definition: pns_meander.h:99
int spacing() const
The type of meander.
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:418

References std::abs(), m_amplitude, m_baselineOffset, PNS::MEANDER_SETTINGS::m_cornerRadiusPercentage, m_dual, Settings(), and spacing().

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

◆ CurrentLength()

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

Definition at line 702 of file pns_meander.cpp.

703{
704 return CLine( 0 ).Length();
705}
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:237
long long int Length() const
Return length of the line chain in Euclidean metric.

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

Referenced by PNS::findAmplitudeBinarySearch(), PNS::findAmplitudeForLength(), and PNS::MEANDER_PLACER_BASE::tuneLineLength().

◆ End()

VECTOR2I PNS::MEANDER_SHAPE::End ( ) const
inline
Returns
end vertex of the base segment of the meander shape.

Definition at line 229 of file pns_meander.h.

230 {
231 return m_clippedBaseSeg.B;
232 }
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 488 of file pns_meander.cpp.

489{
490 const MEANDER_SETTINGS& st = Settings();
491
492 bool checkMode = false;
493 MEANDER_TYPE prim1, prim2;
494
495 if( aType == MT_CHECK_START )
496 {
497 prim1 = MT_START;
498 prim2 = MT_TURN;
499 checkMode = true;
500 }
501 else if( aType == MT_CHECK_FINISH )
502 {
503 prim1 = MT_TURN;
504 prim2 = MT_FINISH;
505 checkMode = true;
506 }
507
508 if( checkMode )
509 {
512
513 m1.SetBaselineOffset( m_baselineOffset );
514 m2.SetBaselineOffset( m_baselineOffset );
515
516 bool c1 = m1.Fit( prim1, aSeg, aP, aSide );
517 bool c2 = false;
518
519 if( c1 )
520 c2 = m2.Fit( prim2, aSeg, m1.End(), !aSide );
521
522 if( c1 && c2 )
523 {
524 m_type = prim1;
525 m_shapes[0] = m1.m_shapes[0];
526 m_shapes[1] = m1.m_shapes[1];
527 m_baseSeg =aSeg;
528 m_p0 = aP;
529 m_side = aSide;
530 m_amplitude = m1.Amplitude();
531 m_dual = m1.m_dual;
532 m_baseSeg = m1.m_baseSeg;
533 m_baseIndex = m1.m_baseIndex;
535 m_baselineOffset = m1.m_baselineOffset;
536 return true;
537 }
538 else
539 {
540 return false;
541 }
542 }
543
544 int minAmpl = MinAmplitude();
545 int maxAmpl = std::max( st.m_maxAmplitude, minAmpl );
546
547 for( int ampl = maxAmpl; ampl >= minAmpl; ampl -= st.m_step )
548 {
549 m_amplitude = ampl;
550
551 if( m_dual )
552 {
553 m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, m_baselineOffset );
554 m_shapes[1] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, -m_baselineOffset );
555 }
556 else
557 {
558 m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, 0 );
559 }
560
561 m_type = aType;
562 m_baseSeg = aSeg;
563 m_p0 = aP;
564 m_side = aSide;
565
567
568 if( m_placer->CheckFit( this ) )
569 return true;
570 }
571
572 return false;
573}
virtual bool CheckFit(MEANDER_SHAPE *aShape)
Checks if it's OK to place the shape aShape (i.e.
int MinAmplitude() const
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:383
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:123
SHAPE_LINE_CHAIN genMeanderShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide, MEANDER_TYPE aType, int aBaselineOffset=0)
Recalculate the clipped baseline after the parameters of the meander have been changed.
void updateBaseSegment()
Return sanitized corner radius value.
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:380
VECTOR2I A
Definition: seg.h:49
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,...
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:37
@ MT_TURN
Definition: pns_meander.h:41
@ MT_CHECK_START
Definition: pns_meander.h:42
@ MT_CHECK_FINISH
Definition: pns_meander.h:43
@ MT_START
Definition: pns_meander.h:39
@ MT_FINISH
Definition: pns_meander.h:40
MATRIX3x3D m2(VECTOR3I{ 6, 6, 6 }, { 1, 1, 1 }, { 3, 3, 3 })
Test suite for KiCad math code.

References SEG::A, Amplitude(), SEG::B, PNS::MEANDER_PLACER_BASE::CheckFit(), End(), Fit(), genMeanderShape(), m2, m_amplitude, m_baseIndex, m_baselineOffset, m_baseSeg, m_dual, PNS::MEANDER_SETTINGS::m_maxAmplitude, m_p0, m_placer, m_shapes, m_side, PNS::MEANDER_SETTINGS::m_step, m_type, m_width, MinAmplitude(), 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 298 of file pns_meander.cpp.

299{
300 m_currentPos += m_currentDir.Resize( aLength );
302}
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:398
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:401
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:350

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 ( const VECTOR2D aP,
const VECTOR2D aDir,
bool  aSide,
MEANDER_TYPE  aType,
int  aBaselineOffset = 0 
)
private

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

Definition at line 339 of file pns_meander.cpp.

342{
343 int cr = cornerRadius();
344 int offset = aBaselineOffset;
345 int spc = spacing();
346 int amplitude = m_amplitude;
347 int targetBaseLen = m_targetBaseLen;
348
349 if( aSide )
350 offset *= -1;
351
352 VECTOR2D dir_u_b( aDir.Resize( offset ) );
353 VECTOR2D dir_v_b( dir_u_b.Perpendicular() );
354
355 if( 2 * cr > amplitude )
356 {
357 cr = amplitude / 2;
358 }
359
360 if( 2 * cr > spc )
361 {
362 cr = spc / 2;
363 }
364
365 if( cr - offset < 0 )
366 {
367 cr = offset;
368 }
369
371
372 int sCorner = cr - offset;
373 int uCorner = cr + offset;
374 int startSide = amplitude - 2 * cr + std::abs( offset );
375 int turnSide = amplitude - cr;
376 int top = spc - 2 * cr;
377
379
380 start( &lc, aP + dir_v_b, aDir );
381
382 switch( aType )
383 {
384 case MT_EMPTY:
385 {
386 lc.Append( aP + dir_v_b + aDir );
387 break;
388 }
389 case MT_START:
390 {
391 if( targetBaseLen )
392 top = std::max( top, targetBaseLen - sCorner - uCorner * 2 + offset );
393
394 miter( sCorner, false );
395 uShape( startSide, uCorner, top );
396 forward( std::min( sCorner, uCorner ) );
397 forward( std::abs( offset ) );
398 break;
399 }
400
401 case MT_FINISH:
402 {
403 if( targetBaseLen )
404 top = std::max( top, targetBaseLen - cr - spc );
405
406 start( &lc, aP - dir_u_b, aDir );
407 turn( -ANGLE_90 );
408 forward( std::min( sCorner, uCorner ) );
409 forward( std::abs( offset ) );
410 uShape( startSide, uCorner, top );
411 miter( sCorner, false );
412
413 if( targetBaseLen >= spc + cr )
414 lc.Append( aP + dir_v_b + aDir.Resize( targetBaseLen ) );
415 else
416 lc.Append( aP + dir_v_b + aDir.Resize( 2 * spc - cr ) );
417
418 break;
419 }
420
421 case MT_TURN:
422 {
423 if( targetBaseLen )
424 top = std::max( top, targetBaseLen - uCorner * 2 + offset * 2 );
425
426 start( &lc, aP - dir_u_b, aDir );
427 turn( -ANGLE_90 );
428 forward( std::abs( offset ) );
429 uShape( turnSide, uCorner, top );
430 forward( std::abs( offset ) );
431 break;
432 }
433
434 case MT_SINGLE:
435 {
436 if( targetBaseLen )
437 top = std::max( top, ( targetBaseLen - sCorner * 2 - uCorner * 2 ) / 2 );
438
439 miter( sCorner, false );
440 uShape( startSide, uCorner, top );
441 miter( sCorner, false );
442 lc.Append( aP + dir_v_b + aDir.Resize( 2 * spc ) );
443 break;
444 }
445
446 default: break;
447 }
448
449 if( aSide )
450 {
451 SEG axis( aP, aP + aDir );
452
453 lc.Mirror( axis );
454 }
455
456 return lc;
457}
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
Move turtle forward by aLength.
void miter(int aRadius, bool aSide)
Tell the turtle to draw an U-like shape.
int cornerRadius() const
Return sanitized spacing value.
void turn(const EDA_ANGLE &aAngle)
Tell the turtle to draw a mitered corner of given radius and turn direction.
void forward(int aLength)
Turn the turtle by aAngle.
void uShape(int aSides, int aCorner, int aTop)
Generate a 90-degree circular arc.
Definition: seg.h:42
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both).
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:431
@ MT_EMPTY
Definition: pns_meander.h:46

References std::abs(), ANGLE_90, SHAPE_LINE_CHAIN::Append(), cornerRadius(), forward(), m_amplitude, m_meanCornerRadius, m_targetBaseLen, SHAPE_LINE_CHAIN::Mirror(), miter(), PNS::MT_EMPTY, PNS::MT_FINISH, PNS::MT_SINGLE, PNS::MT_START, PNS::MT_TURN, VECTOR2< T >::Perpendicular(), 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 213 of file pns_meander.h.

214 {
215 return m_dual;
216 }

References m_dual.

◆ MakeArc()

void PNS::MEANDER_SHAPE::MakeArc ( const SHAPE_ARC aArc1,
const SHAPE_ARC aArc2 = SHAPE_ARC() 
)

Create a dummy meander shape representing an arc corner.

Allows representing existing arc tracks so they can be reconstructed after length tuning.

Parameters
aArc1Arc shape on the 1st line.
aArc2Arc shape on the 2nd line (if m_dual == true).

Definition at line 666 of file pns_meander.cpp.

667{
669 m_shapes[0].Clear();
670 m_shapes[1].Clear();
671 m_shapes[0].Append( aArc1 );
672 m_shapes[1].Append( aArc2 );
673 m_clippedBaseSeg.A = aArc1.GetP1();
674 m_clippedBaseSeg.B = aArc1.GetP1();
675}
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:142
const VECTOR2I & GetP1() const
Definition: shape_arc.h:113
void Clear()
Remove all points from the line chain.
@ MT_CORNER
Definition: pns_meander.h:44

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

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

◆ MakeCorner()

void PNS::MEANDER_SHAPE::MakeCorner ( const VECTOR2I aP1,
const 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 654 of file pns_meander.cpp.

655{
657 m_shapes[0].Clear();
658 m_shapes[1].Clear();
659 m_shapes[0].Append( aP1 );
660 m_shapes[1].Append( aP2 );
661 m_clippedBaseSeg.A = aP1;
662 m_clippedBaseSeg.B = aP1;
663}

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

601{
603
605
607 m_amplitude = 0;
608
610
611 if( m_dual )
613}

References SEG::A, SEG::B, genMeanderShape(), m_amplitude, 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 ( const VECTOR2D aP,
const VECTOR2D aDir,
bool  aSide 
)
private

Produce a meander shape of given type.

Definition at line 235 of file pns_meander.cpp.

237{
239
240 if( aDir.EuclideanNorm( ) == 0.0f )
241 {
242 lc.Append( aP );
243 return lc;
244 }
245
246 VECTOR2D dir_u( aDir );
247 VECTOR2D dir_v( aDir.Perpendicular( ) );
248 VECTOR2D p = aP;
249 lc.Append( ( int ) p.x, ( int ) p.y );
250
251 // fixme: refactor
253 {
255 {
256 VECTOR2D center = aP + dir_v * ( aSide ? -1.0 : 1.0 );
257
258 lc.Append( SHAPE_ARC( center, aP, ( aSide ? -ANGLE_90 : ANGLE_90 ) ) );
259 }
260 break;
261
263 {
264 double radius = (double) aDir.EuclideanNorm();
265 double correction = 0;
266
267 if( m_dual && radius > m_meanCornerRadius )
268 correction = (double)( -2 * abs(m_baselineOffset) ) * tan( 22.5 * M_PI / 180.0 );
269
270 VECTOR2D dir_cu = dir_u.Resize( correction );
271 VECTOR2D dir_cv = dir_v.Resize( correction );
272
273 p = aP - dir_cu;
274 lc.Append( ( int ) p.x, ( int ) p.y );
275 p = aP + dir_u + (dir_v + dir_cv) * ( aSide ? -1.0 : 1.0 );
276 lc.Append( ( int ) p.x, ( int ) p.y );
277 }
278 break;
279 }
280
281 p = aP + dir_u + dir_v * ( aSide ? -1.0 : 1.0 );
282 lc.Append( ( int ) p.x, ( int ) p.y );
283
284 return lc;
285}
virtual const MEANDER_SETTINGS & MeanderSettings() const
Return the current meandering configuration.
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:96
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:265
VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition: vector2d.h:279
@ MEANDER_STYLE_ROUND
Definition: pns_meander.h:51
@ MEANDER_STYLE_CHAMFER
Definition: pns_meander.h:52
constexpr double correction

References std::abs(), ANGLE_90, SHAPE_LINE_CHAIN::Append(), correction, 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(), VECTOR2< T >::Resize(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by miter().

◆ MinAmplitude()

int PNS::MEANDER_SHAPE::MinAmplitude ( ) const
Returns
the minumum possible amplitude according to settings.

Definition at line 190 of file pns_meander.cpp.

191{
192 int minAmplitude = Settings().m_minAmplitude;
193
194 // DP meanders don't really support smaller amplitudes
195 minAmplitude = std::max( minAmplitude, std::abs( m_baselineOffset ) * 2 );
196
197 // The path length won't be correct with very small arcs
199 minAmplitude = std::max( minAmplitude, m_width + std::abs( m_baselineOffset ) * 2 );
200
201 return minAmplitude;
202}
int m_minAmplitude
Maximum meandering amplitude.
Definition: pns_meander.h:78

References std::abs(), m_baselineOffset, PNS::MEANDER_SETTINGS::m_cornerStyle, PNS::MEANDER_SETTINGS::m_minAmplitude, m_placer, m_width, PNS::MEANDER_STYLE_ROUND, PNS::MEANDER_PLACER_BASE::MeanderSettings(), and Settings().

Referenced by Fit().

◆ MinTunableLength()

long long int PNS::MEANDER_SHAPE::MinTunableLength ( ) const
Returns
the minumum tunable length according to settings.

Definition at line 708 of file pns_meander.cpp.

709{
710 MEANDER_SHAPE copy = *this;
711
712 copy.SetTargetBaselineLength( BaselineLength() );
713 copy.Resize( copy.MinAmplitude() );
714
715 return copy.CurrentLength();
716}
int BaselineLength() const

References BaselineLength(), and copy.

◆ miter()

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

Tell the turtle to draw an U-like shape.

Definition at line 311 of file pns_meander.cpp.

312{
313 if( aRadius <= 0 )
314 {
315 turn( aSide ? ANGLE_90 : -ANGLE_90 );
316 return;
317 }
318
319 VECTOR2D dir = m_currentDir.Resize( (double) aRadius );
320 SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
321
322 m_currentPos = lc.CPoint( -1 );
323 turn( aSide ? ANGLE_90 : -ANGLE_90 );
324
325 m_currentTarget->Append( lc );
326}
SHAPE_LINE_CHAIN makeMiterShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide)
Produce a meander shape of given type.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.

References ANGLE_90, SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::CPoint(), m_currentDir, m_currentPos, m_currentTarget, makeMiterShape(), VECTOR2< T >::Resize(), 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 576 of file pns_meander.cpp.

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

Referenced by Resize(), and PNS::MEANDER_PLACER_BASE::tuneLineLength().

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

590{
591 if( aAmpl < 0 )
592 return;
593
594 m_amplitude = aAmpl;
595
596 Recalculate();
597}
void Recalculate()
Recalculate the line chain representing the meander's shape.

References m_amplitude, and Recalculate().

Referenced by PNS::findAmplitudeBinarySearch().

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

159 {
160 m_baseIndex = aIndex;
161 }

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

309 {
310 m_baselineOffset = aOffset;
311 }

References m_baselineOffset.

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

◆ SetTargetBaselineLength()

void PNS::MEANDER_SHAPE::SetTargetBaselineLength ( int  aLength)
inline

Sets the target length of the baseline.

When resizing, the meander will try to fit the baseline length into the specified value.

Parameters
aLengththe minimum baseline length.

Definition at line 319 of file pns_meander.h.

319{ m_targetBaseLen = aLength; }

References m_targetBaseLen.

◆ 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}

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

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

◆ SetType()

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

Set the type of the meander.

Definition at line 142 of file pns_meander.h.

143 {
144 m_type = aType;
145 }

References m_type.

Referenced by MakeArc(), MakeCorner(), and PNS::MEANDER_PLACER_BASE::tuneLineLength().

◆ Side()

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

Definition at line 221 of file pns_meander.h.

222 {
223 return m_side;
224 }

References m_side.

◆ spacing()

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

The type of meander.

Definition at line 221 of file pns_meander.cpp.

222{
223 if( !m_dual )
224 {
225 return std::max( m_width + m_placer->Clearance(), Settings().m_spacing );
226 }
227 else
228 {
229 int sp = m_width + m_placer->Clearance() + ( 2 * std::abs( m_baselineOffset ) );
230 return std::max( sp, Settings().m_spacing );
231 }
232}
virtual int Clearance()
Return the clearance of the track(s) being length tuned.

References std::abs(), PNS::MEANDER_PLACER_BASE::Clearance(), m_baselineOffset, m_dual, m_placer, 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 288 of file pns_meander.cpp.

289{
290 m_currentTarget = aTarget;
292 m_currentTarget->Append( aWhere );
293 m_currentDir = aDir;
294 m_currentPos = aWhere;
295}

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 ( const EDA_ANGLE aAngle)
private

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

Definition at line 305 of file pns_meander.cpp.

306{
307 RotatePoint( m_currentDir, aAngle );
308}
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183

References m_currentDir, and RotatePoint().

Referenced by genMeanderShape(), and miter().

◆ Type()

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

Definition at line 150 of file pns_meander.h.

151 {
152 return m_type;
153 }

References m_type.

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

◆ updateBaseSegment()

void PNS::MEANDER_SHAPE::updateBaseSegment ( )
private

Return sanitized corner radius value.

Definition at line 719 of file pns_meander.cpp.

720{
721 if( m_dual )
722 {
723 VECTOR2I midpA = ( CLine( 0 ).CPoint( 0 ) + CLine( 1 ).CPoint( 0 ) ) / 2;
724 VECTOR2I midpB = ( CLine( 0 ).CPoint( -1 ) + CLine( 1 ).CPoint( -1 ) ) / 2;
725
728 }
729 else
730 {
733 }
734}
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:312

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

330{
331 forward( aSides );
332 miter( aCorner, true );
333 forward( aTop );
334 miter( aCorner, true );
335 forward( aSides );
336}

References forward(), and miter().

Referenced by genMeanderShape().

◆ Width()

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

Definition at line 297 of file pns_meander.h.

298 {
299 return m_width;
300 }

References m_width.

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

Friends And Related Function Documentation

◆ MEANDERED_LINE

friend class MEANDERED_LINE
friend

Start turtle drawing.

Definition at line 322 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 368 of file pns_meander.h.

Referenced by Amplitude(), cornerRadius(), Fit(), genMeanderShape(), MakeEmpty(), MEANDER_SHAPE(), and Resize().

◆ m_baseIndex

int PNS::MEANDER_SHAPE::m_baseIndex
private

The current turtle direction.

Definition at line 395 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 371 of file pns_meander.h.

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

◆ m_baseSeg

SEG PNS::MEANDER_SHAPE::m_baseSeg
private

Base segment (clipped).

Definition at line 383 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 386 of file pns_meander.h.

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

◆ m_currentDir

VECTOR2D PNS::MEANDER_SHAPE::m_currentDir
private

The current turtle position.

Definition at line 398 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 401 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 404 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 362 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

Minimum length of the base segment to target when resizing.

Definition at line 374 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 380 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 359 of file pns_meander.h.

Referenced by Fit(), makeMiterShape(), MinAmplitude(), 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 392 of file pns_meander.h.

Referenced by CLine(), Fit(), MakeArc(), 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 389 of file pns_meander.h.

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

◆ m_targetBaseLen

int PNS::MEANDER_SHAPE::m_targetBaseLen
private

First point of the meandered line.

Definition at line 377 of file pns_meander.h.

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

◆ m_type

MEANDER_TYPE PNS::MEANDER_SHAPE::m_type
private

The placer that placed this meander.

Definition at line 356 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 365 of file pns_meander.h.

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


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