KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_meander.cpp
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "pns_node.h"
23#include "pns_itemset.h"
24#include "pns_meander.h"
26#include "pns_router.h"
27#include "pns_debug_decorator.h"
28
29namespace PNS {
30
31const long long int MEANDER_SETTINGS::DEFAULT_TOLERANCE( pcbIUScale.mmToIU( 0.1 ) );
32const long long int MEANDER_SETTINGS::LENGTH_UNCONSTRAINED( 1000000 * pcbIUScale.IU_PER_MM );
33const int MEANDER_SETTINGS::SKEW_UNCONSTRAINED( std::numeric_limits<int>::max() );
34
35
37{
38 m_minAmplitude = 200000;
39 m_maxAmplitude = 1000000;
40 m_step = 50000;
41 m_lenPadToDie = 0;
42 m_spacing = 600000;
44 SetTargetSkew( 0 );
48 m_singleSided = false;
51 m_keepEndpoints = false;
52}
53
54
55void MEANDER_SETTINGS::SetTargetLength( long long int aOpt )
56{
57 m_targetLength.SetOpt( aOpt );
58
60 {
62 m_targetLength.SetMax( aOpt );
63 }
64 else
65 {
68 }
69}
70
71
73{
74 SetTargetLength( aConstraint.Opt() );
75
76 if( aConstraint.HasMin() )
77 m_targetLength.SetMin( aConstraint.Min() );
78
79 if( aConstraint.HasMax() )
80 m_targetLength.SetMax( aConstraint.Max() );
81}
82
83
85{
86 m_targetSkew.SetOpt( aOpt );
87
89 {
91 m_targetSkew.SetMax( aOpt );
92 }
93 else
94 {
97 }
98}
99
100
102{
103 SetTargetSkew( aConstraint.Opt() );
104
105 if( aConstraint.HasMin() )
106 m_targetSkew.SetMin( aConstraint.Min() );
107
108 if( aConstraint.HasMax() )
109 m_targetSkew.SetMax( aConstraint.Max() );
110}
111
112
114{
115 return m_placer->MeanderSettings();
116}
117
118
120{
121 return m_placer->MeanderSettings();
122}
123
124
125void MEANDERED_LINE::MeanderSegment( const SEG& aBase, bool aSide, int aBaseIndex )
126{
127 double base_len = aBase.Length();
128
130
131 bool singleSided = Settings().m_singleSided;
132 bool side = aSide;
133 VECTOR2D dir( aBase.B - aBase.A );
134
135 if( !m_dual )
136 AddCorner( aBase.A );
137
138 bool turning = false;
139 bool started = false;
140
141 m_last = aBase.A;
142
143 do
144 {
146
148 m.SetBaseIndex( aBaseIndex );
149
150 double thr = (double) m.spacing();
151
152 bool fail = false;
153 double remaining = base_len - ( m_last - aBase.A ).EuclideanNorm();
154
155 auto flipInitialSide =
156 [&]()
157 {
159 settings.m_initialSide = (PNS::MEANDER_SIDE) -settings.m_initialSide;
160 m_placer->UpdateSettings( settings );
161 };
162
163 auto addSingleIfFits =
164 [&]()
165 {
166 fail = true;
167
168 if( m.Fit( MT_SINGLE, aBase, m_last, side ) )
169 {
170 AddMeander( new MEANDER_SHAPE( m ) );
171 fail = false;
172 started = false;
173 }
174
175 if( fail && !singleSided )
176 {
177 if( m.Fit( MT_SINGLE, aBase, m_last, !side ) )
178 {
179 if( !started )
180 flipInitialSide();
181
182 AddMeander( new MEANDER_SHAPE( m ) );
183 fail = false;
184 started = false;
185 side = !side;
186 }
187 }
188 };
189
190 if( remaining < Settings( ).m_step )
191 break;
192
193 if( !singleSided && remaining > 3.0 * thr )
194 {
195 if( !turning )
196 {
197 for( int i = 0; i < 2; i++ )
198 {
199 bool checkSide = ( i == 0 ) ? side : !side;
200
201 if( m.Fit( MT_CHECK_START, aBase, m_last, checkSide ) )
202 {
203 if( !started && checkSide != side )
204 flipInitialSide();
205
206 turning = true;
207 AddMeander( new MEANDER_SHAPE( m ) );
208 side = !checkSide;
209 started = true;
210 break;
211 }
212 }
213
214 if( !turning )
215 addSingleIfFits();
216 }
217 else
218 {
219 bool rv = m.Fit( MT_CHECK_FINISH, aBase, m_last, side );
220
221 if( rv )
222 {
223 m.Fit( MT_TURN, aBase, m_last, side );
224 AddMeander( new MEANDER_SHAPE( m ) );
225 side = !side;
226 started = true;
227 }
228 else
229 {
230 m.Fit( MT_FINISH, aBase, m_last, side );
231 started = false;
232 AddMeander( new MEANDER_SHAPE( m ) );
233 turning = false;
234 }
235 }
236 }
237 else if( !singleSided && started )
238 {
239 bool rv = m.Fit( MT_FINISH, aBase, m_last, side );
240
241 if( rv )
242 AddMeander( new MEANDER_SHAPE( m ) );
243
244 break;
245
246 }
247 else if( !turning && remaining > thr * 2.0 )
248 {
249 addSingleIfFits();
250 }
251 else
252 {
253 fail = true;
254 }
255
256 remaining = base_len - ( m_last - aBase.A ).EuclideanNorm( );
257
258 if( remaining < Settings( ).m_step )
259 break;
260
261 if( fail )
262 {
265 tmp.SetBaseIndex( aBaseIndex );
266
267 int nextP = tmp.spacing() - 2 * tmp.cornerRadius() + Settings().m_step;
268 VECTOR2I pn = m_last + dir.Resize( nextP );
269
270 if( aBase.Contains( pn ) && !m_dual )
271 AddCorner( pn );
272 else
273 break;
274 }
275
276
277 } while( true );
278
279 if( !m_dual )
280 AddCorner( aBase.B );
281}
282
283
285{
286 int minAmplitude = Settings().m_minAmplitude;
287
289 {
290 minAmplitude = std::max( minAmplitude, std::abs( m_baselineOffset ) + m_width );
291 }
292 else
293 {
294 int correction = m_width * tan( 1 - tan( DEG2RAD( 22.5 ) ) );
295 minAmplitude = std::max( minAmplitude, std::abs( m_baselineOffset ) + correction );
296 }
297
298 return minAmplitude;
299}
300
301
303{
304 if( m_amplitude == 0 )
305 return 0;
306
307 int minCr = 0;
308
310 minCr = std::abs( m_baselineOffset ) + m_width / 2;
311 else
312 minCr = std::abs( m_baselineOffset ) + m_width / 2 * ( 1 - tan( DEG2RAD( 22.5 ) ) );
313
314 int maxCr1 = ( m_amplitude + std::abs( m_baselineOffset ) ) / 2;
315 int maxCr2 = spacing() / 2;
316 int maxCr = std::min( maxCr1, maxCr2 );
317
318 wxCHECK2_MSG( maxCr >= minCr, return maxCr,
319 wxString::Format( "cornerRadius %d < %d amp %d spc %d w %d off %d", maxCr, minCr,
321
322 int rPercent = Settings().m_cornerRadiusPercentage;
323 int optCr = static_cast<int>( static_cast<SEG::ecoord>( spacing() ) * rPercent / 200 );
324
325 return std::clamp( optCr, minCr, maxCr );
326}
327
328
330{
331 if( !m_dual )
332 {
333 return std::max( m_width + m_placer->Clearance(), Settings().m_spacing );
334 }
335 else
336 {
337 int sp = m_width + m_placer->Clearance() + ( 2 * std::abs( m_baselineOffset ) );
338 return std::max( sp, Settings().m_spacing );
339 }
340}
341
342
344 bool aSide )
345{
347
348 if( aDir.EuclideanNorm( ) == 0.0f )
349 {
350 lc.Append( aP );
351 return lc;
352 }
353
354 VECTOR2D dir_u( aDir );
355 VECTOR2D dir_v( aDir.Perpendicular() );
356
357 VECTOR2D endPoint = aP + dir_u + dir_v * ( aSide ? -1.0 : 1.0 );
358 VECTOR2D p = aP;
359 lc.Append( ( int ) p.x, ( int ) p.y );
360
361 // fixme: refactor
363 {
365 {
366 VECTOR2I arcEnd( (int) endPoint.x, (int) endPoint.y );
367
368 SHAPE_ARC arc;
369 arc.ConstructFromStartEndAngle( aP, arcEnd, ( aSide ? -ANGLE_90 : ANGLE_90 ) );
370 lc.Append( arc );
371 break;
372 }
373
375 {
376 double radius = (double) aDir.EuclideanNorm();
377 double correction = 0;
378
379 if( m_dual && radius > m_meanCornerRadius )
380 correction = (double) ( -2 * abs( m_baselineOffset ) ) * tan( DEG2RAD( 22.5 ) );
381
382 VECTOR2D dir_cu = dir_u.Resize( correction );
383 VECTOR2D dir_cv = dir_v.Resize( correction );
384
385 p = aP - dir_cu;
386 lc.Append( ( int ) p.x, ( int ) p.y );
387 p = aP + dir_u + (dir_v + dir_cv) * ( aSide ? -1.0 : 1.0 );
388 lc.Append( ( int ) p.x, ( int ) p.y );
389
390 p = endPoint;
391 lc.Append( (int) p.x, (int) p.y );
392 break;
393 }
394
395 default:
396 break;
397 }
398
399 return lc;
400}
401
402
403void MEANDER_SHAPE::start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir )
404{
405 m_currentTarget = aTarget;
407 m_currentTarget->Append( aWhere );
408 m_currentDir = aDir;
409 m_currentPos = aWhere;
410}
411
412
413void MEANDER_SHAPE::forward( int aLength )
414{
415 // Very small segments cause problems.
416 if( aLength < 5 )
417 return;
418
419 m_currentPos += m_currentDir.Resize( aLength );
421}
422
423
424void MEANDER_SHAPE::turn( const EDA_ANGLE& aAngle )
425{
426 RotatePoint( m_currentDir, aAngle );
427}
428
429
430void MEANDER_SHAPE::miter( int aRadius, bool aSide )
431{
432 if( aRadius <= 0 )
433 {
434 turn( aSide ? ANGLE_90 : -ANGLE_90 );
435 return;
436 }
437
438 VECTOR2D dir = m_currentDir.Resize( (double) aRadius );
439 SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
440
441 m_currentPos = lc.CPoint( -1 );
442 turn( aSide ? ANGLE_90 : -ANGLE_90 );
443
444 m_currentTarget->Append( lc );
445}
446
447
448void MEANDER_SHAPE::uShape( int aSides, int aCorner, int aTop )
449{
450 forward( aSides );
451 miter( aCorner, true );
452 forward( aTop );
453 miter( aCorner, true );
454 forward( aSides );
455}
456
457
459 bool aSide, MEANDER_TYPE aType,
460 int aBaselineOffset )
461{
462 int cr = cornerRadius();
463 int offset = aBaselineOffset;
464 int spc = spacing();
465 int amplitude = m_amplitude;
466 int targetBaseLen = m_targetBaseLen;
467
468 if( aSide )
469 offset *= -1;
470
471 VECTOR2D dir_u_b( aDir.Resize( offset ) );
472 VECTOR2D dir_v_b( dir_u_b.Perpendicular() );
473
474 if( 2 * cr > amplitude + std::abs( offset ) )
475 cr = ( amplitude + std::abs( offset ) ) / 2;
476
477 if( 2 * cr > spc )
478 cr = spc / 2;
479
480 if( cr - offset < 0 )
481 cr = offset;
482
484
485 int sCorner = cr - offset;
486 int uCorner = cr + offset;
487 int startSide = amplitude - 2 * cr + std::abs( offset );
488 int turnSide = amplitude - cr;
489 int top = spc - 2 * cr;
490
492
493 start( &lc, aP + dir_v_b, aDir );
494
495 switch( aType )
496 {
497 case MT_EMPTY:
498 {
499 lc.Append( aP + dir_v_b + aDir );
500 break;
501 }
502 case MT_START:
503 {
504 if( targetBaseLen )
505 top = std::max( top, targetBaseLen - sCorner - uCorner * 2 + offset );
506
507 miter( sCorner, false );
508 uShape( startSide, uCorner, top );
509 forward( std::min( sCorner, uCorner ) );
510 forward( std::abs( offset ) );
511 break;
512 }
513
514 case MT_FINISH:
515 {
516 if( targetBaseLen )
517 top = std::max( top, targetBaseLen - cr - spc );
518
519 start( &lc, aP - dir_u_b, aDir );
520 turn( -ANGLE_90 );
521 forward( std::min( sCorner, uCorner ) );
522 forward( std::abs( offset ) );
523 uShape( startSide, uCorner, top );
524 miter( sCorner, false );
525
526 if( targetBaseLen >= spc + cr )
527 lc.Append( aP + dir_v_b + aDir.Resize( targetBaseLen ) );
528 else
529 lc.Append( aP + dir_v_b + aDir.Resize( 2 * spc - cr ) );
530
531 break;
532 }
533
534 case MT_TURN:
535 {
536 if( targetBaseLen )
537 top = std::max( top, targetBaseLen - uCorner * 2 + offset * 2 );
538
539 start( &lc, aP - dir_u_b, aDir );
540 turn( -ANGLE_90 );
541 forward( std::abs( offset ) );
542 uShape( turnSide, uCorner, top );
543 forward( std::abs( offset ) );
544 break;
545 }
546
547 case MT_SINGLE:
548 {
549 if( targetBaseLen )
550 top = std::max( top, ( targetBaseLen - sCorner * 2 - uCorner * 2 ) / 2 );
551
552 miter( sCorner, false );
553 uShape( startSide, uCorner, top );
554 miter( sCorner, false );
555 lc.Append( aP + dir_v_b + aDir.Resize( 2 * spc ) );
556 break;
557 }
558
559 default:
560 break;
561 }
562
563 if( aSide )
564 {
565 SEG axis( aP, aP + aDir );
566
567 lc.Mirror( axis );
568 }
569
570 return lc;
571}
572
573
575{
576 for( int i = m_meanders.size() - 1; i >= 0; i-- )
577 {
579
580 if( m->Type() == MT_EMPTY || m->Type() == MT_CORNER )
581 continue;
582
583 const SEG& b1 = aShape->BaseSegment();
584 const SEG& b2 = m->BaseSegment();
585
586 if( b1.ApproxParallel( b2 ) )
587 continue;
588
589 int n = m->CLine( 0 ).SegmentCount();
590
591 for( int j = n - 1; j >= 0; j-- )
592 {
593 if( aShape->CLine( 0 ).Collide( m->CLine( 0 ) .CSegment( j ), aClearance ) )
594 return false;
595 }
596 }
597
598 return true;
599}
600
601
602bool MEANDER_SHAPE::Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide )
603{
604 const MEANDER_SETTINGS& st = Settings();
605
606 bool checkMode = false;
607 MEANDER_TYPE prim1, prim2;
608
609 if( aType == MT_CHECK_START )
610 {
611 prim1 = MT_START;
612 prim2 = MT_TURN;
613 checkMode = true;
614 }
615 else if( aType == MT_CHECK_FINISH )
616 {
617 prim1 = MT_TURN;
618 prim2 = MT_FINISH;
619 checkMode = true;
620 }
621
622 if( checkMode )
623 {
626
628 m2.SetBaselineOffset( m_baselineOffset );
629
630 bool c1 = m1.Fit( prim1, aSeg, aP, aSide );
631 bool c2 = false;
632
633 if( c1 )
634 c2 = m2.Fit( prim2, aSeg, m1.End(), !aSide );
635
636 if( c1 && c2 )
637 {
638 m_type = prim1;
639 m_shapes[0] = m1.m_shapes[0];
640 m_shapes[1] = m1.m_shapes[1];
641 m_baseSeg =aSeg;
642 m_p0 = aP;
643 m_side = aSide;
644 m_amplitude = m1.Amplitude();
645 m_dual = m1.m_dual;
646 m_baseSeg = m1.m_baseSeg;
650 return true;
651 }
652 else
653 {
654 return false;
655 }
656 }
657
658 int minAmpl = MinAmplitude();
659 int maxAmpl = std::max( st.m_maxAmplitude, minAmpl );
660
661 for( int ampl = maxAmpl; ampl >= minAmpl; ampl -= st.m_step )
662 {
663 m_amplitude = ampl;
664
665 if( m_dual )
666 {
667 m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, m_baselineOffset );
668 m_shapes[1] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, -m_baselineOffset );
669 }
670 else
671 {
672 m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, 0 );
673 }
674
675 m_type = aType;
676 m_baseSeg = aSeg;
677 m_p0 = aP;
678 m_side = aSide;
679
681
682 if( m_placer->CheckFit( this ) )
683 return true;
684 }
685
686 return false;
687}
688
689
691{
693 m_dual ? m_baselineOffset : 0 );
694
695 if( m_dual )
698
700}
701
702
703void MEANDER_SHAPE::Resize( int aAmpl )
704{
705 if( aAmpl < 0 )
706 return;
707
708 m_amplitude = aAmpl;
709
710 Recalculate();
711}
712
713
715{
717
719
721 m_amplitude = 0;
722
724
725 if( m_dual )
727}
728
729
730void MEANDERED_LINE::AddCorner( const VECTOR2I& aA, const VECTOR2I& aB )
731{
733
734 m->MakeCorner( aA, aB );
735 m_last = aA;
736
737 m_meanders.push_back( m );
738}
739
740
741void MEANDERED_LINE::AddArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 )
742{
744
745 m->MakeArc( aArc1, aArc2 );
746 m_last = aArc1.GetP1();
747
748 m_meanders.push_back( m );
749}
750
751
752void MEANDERED_LINE::AddArcAndPt( const SHAPE_ARC& aArc1, const VECTOR2I& aPt2 )
753{
754 SHAPE_ARC arc2( aPt2, aPt2, aPt2, 0 );
755
756 AddArc( aArc1, arc2 );
757}
758
759
760void MEANDERED_LINE::AddPtAndArc( const VECTOR2I& aPt1, const SHAPE_ARC& aArc2 )
761{
762 SHAPE_ARC arc1( aPt1, aPt1, aPt1, 0 );
763
764 AddArc( arc1, aArc2 );
765}
766
767
768void MEANDER_SHAPE::MakeCorner( const VECTOR2I& aP1, const VECTOR2I& aP2 )
769{
771 m_shapes[0].Clear();
772 m_shapes[1].Clear();
773 m_shapes[0].Append( aP1 );
774 m_shapes[1].Append( aP2 );
775 m_clippedBaseSeg.A = aP1;
776 m_clippedBaseSeg.B = aP1;
777}
778
779
780void MEANDER_SHAPE::MakeArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 )
781{
783 m_shapes[0].Clear();
784 m_shapes[1].Clear();
785 m_shapes[0].Append( aArc1 );
786 m_shapes[1].Append( aArc2 );
787 m_clippedBaseSeg.A = aArc1.GetP1();
788 m_clippedBaseSeg.B = aArc1.GetP1();
789}
790
791
793{
794 m_last = aShape->BaseSegment().B;
795 m_meanders.push_back( aShape );
796}
797
798
800{
801 for( MEANDER_SHAPE* m : m_meanders )
802 delete m;
803
804 m_meanders.clear( );
805}
806
807
809{
810 return m_clippedBaseSeg.Length();
811}
812
813
814long long int MEANDER_SHAPE::CurrentLength() const
815{
816 return CLine( 0 ).Length();
817}
818
819
821{
822 MEANDER_SHAPE copy = *this;
823
824 copy.SetTargetBaselineLength( BaselineLength() );
825 copy.Resize( copy.MinAmplitude() );
826
827 return copy.CurrentLength();
828}
829
830
832{
833 if( m_dual )
834 {
835 VECTOR2I midpA = ( CLine( 0 ).CPoint( 0 ) + CLine( 1 ).CPoint( 0 ) ) / 2;
836 VECTOR2I midpB = ( CLine( 0 ).CPoint( -1 ) + CLine( 1 ).CPoint( -1 ) ) / 2;
837
840 }
841 else
842 {
845 }
846}
847
848}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
T Min() const
Definition: minoptmax.h:33
void SetMin(T v)
Definition: minoptmax.h:41
bool HasMax() const
Definition: minoptmax.h:38
void SetOpt(T v)
Definition: minoptmax.h:43
bool HasMin() const
Definition: minoptmax.h:37
void SetMax(T v)
Definition: minoptmax.h:42
T Max() const
Definition: minoptmax.h:34
T Opt() const
Definition: minoptmax.h:35
void AddMeander(MEANDER_SHAPE *aShape)
Add a new meander shape to the meandered line.
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:550
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
void Clear()
Clear the line geometry, removing all corners and meanders.
std::vector< MEANDER_SHAPE * > m_meanders
Definition: pns_meander.h:551
void MeanderSegment(const SEG &aSeg, bool aSide, int aBaseIndex=0)
Fit maximum amplitude meanders on a given segment and adds to the current line.
void AddArc(const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
Create a dummy meander shape representing an arc corner.
void AddArcAndPt(const SHAPE_ARC &aArc1, const VECTOR2I &aPt2)
Create a dummy meander shape representing an arc corner.
bool CheckSelfIntersections(MEANDER_SHAPE *aShape, int aClearance)
Check if the given shape is intersecting with any other meander in the current line.
const MEANDER_SETTINGS & Settings() const
void AddPtAndArc(const VECTOR2I &aPt1, const SHAPE_ARC &aArc2)
Create a dummy meander shape representing an arc corner.
virtual void UpdateSettings(const MEANDER_SETTINGS &aSettings)
virtual bool CheckFit(MEANDER_SHAPE *aShape)
Checks if it's OK to place the shape aShape (i.e.
virtual int Clearance()
Return the clearance of the track(s) being length tuned.
virtual const MEANDER_SETTINGS & MeanderSettings() const
Return the current meandering configuration.
Dimensions for the meandering algorithm.
Definition: pns_meander.h:68
int m_minAmplitude
Maximum meandering amplitude.
Definition: pns_meander.h:83
void SetTargetLength(long long int aOpt)
Definition: pns_meander.cpp:55
static const long long int LENGTH_UNCONSTRAINED
Definition: pns_meander.h:71
int m_cornerRadiusPercentage
Place meanders on one side.
Definition: pns_meander.h:109
MEANDER_SIDE m_initialSide
Allowable tuning error.
Definition: pns_meander.h:115
bool m_singleSided
Initial side when placing meanders at segment.
Definition: pns_meander.h:112
static const int SKEW_UNCONSTRAINED
Definition: pns_meander.h:72
MINOPTMAX< long long int > m_targetLength
Target skew value for diff pair de-skewing.
Definition: pns_meander.h:98
void SetTargetSkew(int aOpt)
Definition: pns_meander.cpp:84
int m_lengthTolerance
Keep vertices between pre, tuned and post parts of the line.
Definition: pns_meander.h:118
int m_step
Length PadToDie.
Definition: pns_meander.h:92
MINOPTMAX< int > m_targetSkew
Definition: pns_meander.h:101
static const long long int DEFAULT_TOLERANCE
Definition: pns_meander.h:70
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:106
int m_maxAmplitude
Meandering period/spacing (see dialog picture for explanation).
Definition: pns_meander.h:86
bool m_overrideCustomRules
Type of corners for the meandered line.
Definition: pns_meander.h:103
int m_lenPadToDie
Desired length of the tuned line/diff pair (this is in nm, so allow more than board width).
Definition: pns_meander.h:95
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:89
The geometry of a single meander.
Definition: pns_meander.h:128
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:369
int MinAmplitude() const
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:372
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:396
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:399
int Amplitude() const
Definition: pns_meander.h:187
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:155
int m_targetBaseLen
First point of the meandered line.
Definition: pns_meander.h:390
VECTOR2I End() const
Definition: pns_meander.h:242
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 start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
Move turtle forward by aLength.
void SetBaseIndex(int aIndex)
Set an auxiliary index of the segment being meandered in its original LINE.
Definition: pns_meander.h:171
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:384
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:411
int m_width
Amplitude of the meander.
Definition: pns_meander.h:378
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:414
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:405
long long int CurrentLength() const
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:402
void updateBaseSegment()
Return sanitized corner radius value.
SHAPE_LINE_CHAIN makeMiterShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide)
Produce a meander shape of given type.
void MakeArc(const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
Create a dummy meander shape representing an arc corner.
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:408
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:417
bool m_dual
Width of the line.
Definition: pns_meander.h:375
void Recalculate()
Recalculate the line chain representing the meander's shape.
void miter(int aRadius, bool aSide)
Tell the turtle to draw an U-like shape.
long long int MinTunableLength() const
void Resize(int aAmpl)
Change the amplitude of the meander shape to aAmpl and recalculates the resulting line chain.
int m_meanCornerRadius
Minimum length of the base segment to target when resizing.
Definition: pns_meander.h:387
int spacing() const
The type of meander.
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:381
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 SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:321
void forward(int aLength)
Turn the turtle by aAngle.
MEANDER_TYPE Type() const
Definition: pns_meander.h:163
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:393
const MEANDER_SETTINGS & Settings() const
void MakeEmpty()
Replace the meander with straight bypass line(s), effectively clearing it.
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 feature...
void uShape(int aSides, int aCorner, int aTop)
Generate a 90-degree circular arc.
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:250
int BaselineLength() const
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
Definition: pns_meander.h:277
void MakeCorner(const VECTOR2I &aP1, const VECTOR2I &aP2=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I::extended_type ecoord
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:50
int Length() const
Return the length (this).
Definition: seg.h:333
bool ApproxParallel(const SEG &aSeg, int aDistanceThreshold=1) const
Definition: seg.cpp:489
bool Contains(const SEG &aSeg) const
Definition: seg.h:314
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:371
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, const EDA_ANGLE &aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
Definition: shape_arc.cpp:194
const VECTOR2I & GetP1() const
Definition: shape_arc.h:115
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
void Clear()
Remove all points from the line chain.
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.
int SegmentCount() const
Return the number of segments in this line chain.
void Mirror(const VECTOR2I &aRef, FLIP_DIRECTION aFlipDirection)
Mirror the line points about y or x (or both).
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
long long int Length() const
Return length of the line chain in Euclidean metric.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:283
constexpr VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition: vector2d.h:314
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
Push and Shove diff pair dimensions (gap) settings dialog.
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:38
@ MT_TURN
Definition: pns_meander.h:42
@ MT_CHECK_START
Definition: pns_meander.h:43
@ MT_CHECK_FINISH
Definition: pns_meander.h:44
@ MT_START
Definition: pns_meander.h:40
@ MT_FINISH
Definition: pns_meander.h:41
@ MT_EMPTY
Definition: pns_meander.h:47
@ MT_CORNER
Definition: pns_meander.h:45
@ MT_SINGLE
Definition: pns_meander.h:39
MEANDER_SIDE
Definition: pns_meander.h:58
@ MEANDER_SIDE_LEFT
Definition: pns_meander.h:59
@ MEANDER_STYLE_ROUND
Definition: pns_meander.h:52
@ MEANDER_STYLE_CHAMFER
Definition: pns_meander.h:53
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390
constexpr double correction
const double IU_PER_MM
Definition: base_units.h:76
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
MATRIX3x3D m2(VECTOR3I{ 6, 6, 6 }, { 1, 1, 1 }, { 3, 3, 3 })
Test suite for KiCad math code.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:229
double DEG2RAD(double deg)
Definition: trigo.h:166