KiCad PCB EDA Suite
pns_optimizer.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 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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 
23 #include <geometry/shape_rect.h>
24 #include <geometry/shape_convex.h>
25 
26 #include <cmath>
27 
28 #include "pns_line.h"
29 #include "pns_diff_pair.h"
30 #include "pns_node.h"
31 #include "pns_solid.h"
32 #include "pns_optimizer.h"
33 #include "pns_utils.h"
34 #include "pns_router.h"
35 
36 namespace PNS {
37 
41 int COST_ESTIMATOR::CornerCost( const SEG& aA, const SEG& aB )
42 {
43  DIRECTION_45 dir_a( aA ), dir_b( aB );
44 
45  switch( dir_a.Angle( dir_b ) )
46  {
48  return 1;
49 
51  return 0;
52 
54  return 50;
55 
57  return 30;
58 
60  return 60;
61 
62  default:
63  return 100;
64  }
65 }
66 
67 
69 {
70  int total = 0;
71 
72  for( int i = 0; i < aLine.SegmentCount() - 1; ++i )
73  total += CornerCost( aLine.CSegment( i ), aLine.CSegment( i + 1 ) );
74 
75  return total;
76 }
77 
78 
79 int COST_ESTIMATOR::CornerCost( const LINE& aLine )
80 {
81  return CornerCost( aLine.CLine() );
82 }
83 
84 
85 void COST_ESTIMATOR::Add( LINE& aLine )
86 {
87  m_lengthCost += aLine.CLine().Length();
88  m_cornerCost += CornerCost( aLine );
89 }
90 
91 
93 {
94  m_lengthCost -= aLine.CLine().Length();
95  m_cornerCost -= CornerCost( aLine );
96 }
97 
98 
99 void COST_ESTIMATOR::Replace( LINE& aOldLine, LINE& aNewLine )
100 {
101  m_lengthCost -= aOldLine.CLine().Length();
102  m_cornerCost -= CornerCost( aOldLine );
103  m_lengthCost += aNewLine.CLine().Length();
104  m_cornerCost += CornerCost( aNewLine );
105 }
106 
107 
109  double aLengthTolerance,
110  double aCornerTolerance ) const
111 {
112  if( aOther.m_cornerCost < m_cornerCost && aOther.m_lengthCost < m_lengthCost )
113  return true;
114 
115  else if( aOther.m_cornerCost < m_cornerCost * aCornerTolerance &&
116  aOther.m_lengthCost < m_lengthCost * aLengthTolerance )
117  return true;
118 
119  return false;
120 }
121 
122 
127  m_world( aWorld ),
128  m_collisionKindMask( ITEM::ANY_T ),
129  m_effortLevel( MERGE_SEGMENTS ),
130  m_keepPostures( false ),
131  m_restrictAreaActive( false )
132 {
133 }
134 
135 
137 {
138 }
139 
140 
142 {
143  CACHE_VISITOR( const ITEM* aOurItem, NODE* aNode, int aMask ) :
144  m_ourItem( aOurItem ),
145  m_collidingItem( NULL ),
146  m_node( aNode ),
147  m_mask( aMask )
148  {}
149 
150  bool operator()( ITEM* aOtherItem )
151  {
152  if( !( m_mask & aOtherItem->Kind() ) )
153  return true;
154 
155  int clearance = m_node->GetClearance( aOtherItem, m_ourItem );
156 
157  if( !aOtherItem->Collide( m_ourItem, clearance ) )
158  return true;
159 
160  m_collidingItem = aOtherItem;
161  return false;
162  }
163 
164  const ITEM* m_ourItem;
167  int m_mask;
168 };
169 
170 
171 void OPTIMIZER::cacheAdd( ITEM* aItem, bool aIsStatic = false )
172 {
173  if( m_cacheTags.find( aItem ) != m_cacheTags.end() )
174  return;
175 
176  m_cache.Add( aItem );
177  m_cacheTags[aItem].m_hits = 1;
178  m_cacheTags[aItem].m_isStatic = aIsStatic;
179 }
180 
181 
182 void OPTIMIZER::removeCachedSegments( LINE* aLine, int aStartVertex, int aEndVertex )
183 {
184  if( !aLine->IsLinked() ) return;
185 
186  LINE::SEGMENT_REFS& segs = aLine->LinkedSegments();
187 
188  if( aEndVertex < 0 )
189  aEndVertex += aLine->PointCount();
190 
191  for( int i = aStartVertex; i < aEndVertex - 1; i++ )
192  {
193  SEGMENT* s = segs[i];
194  m_cacheTags.erase( s );
195  m_cache.Remove( s );
196  }
197 }
198 
199 
201 {
202  if( aItem->Kind() == ITEM::LINE_T )
203  removeCachedSegments( static_cast<LINE*>( aItem ) );
204 }
205 
206 
208 {
209  cacheAdd( aItem, true );
210 }
211 
212 
213 void OPTIMIZER::ClearCache( bool aStaticOnly )
214 {
215  if( !aStaticOnly )
216  {
217  m_cacheTags.clear();
218  m_cache.Clear();
219  return;
220  }
221 
222  for( CachedItemTags::iterator i = m_cacheTags.begin(); i!= m_cacheTags.end(); ++i )
223  {
224  if( i->second.m_isStatic )
225  {
226  m_cache.Remove( i->first );
227  m_cacheTags.erase( i->first );
228  }
229  }
230 }
231 
232 
234 {
235  public:
238 
239  void Build( NODE* aWorld, LINE* aOriginLine, const SHAPE_LINE_CHAIN& aLine, const BOX2I& aRestrictedArea, bool aRestrictedAreaEnable );
240  bool Check ( int aVertex1, int aVertex2, const SHAPE_LINE_CHAIN& aReplacement );
241  void Dump();
242 
243  private:
244  int allowedAngles( NODE* aWorld, const LINE* aLine, const VECTOR2I& aP, bool aFirst );
245 
246  struct RVERTEX
247  {
248  RVERTEX ( bool aRestricted, int aAllowedAngles ) :
249  restricted( aRestricted ),
250  allowedAngles( aAllowedAngles )
251  {
252  }
253 
256  };
257 
258  std::vector<RVERTEX> m_rs;
259 };
260 
261 
262 // fixme: use later
263 int LINE_RESTRICTIONS::allowedAngles( NODE* aWorld, const LINE* aLine, const VECTOR2I& aP, bool aFirst )
264 {
265  JOINT* jt = aWorld->FindJoint( aP , aLine );
266 
267  if( !jt )
268  return 0xff;
269 
270  DIRECTION_45 dirs [8];
271 
272  int n_dirs = 0;
273 
274  for( const ITEM* item : jt->Links().CItems() )
275  {
276  if( item->OfKind( ITEM::VIA_T ) || item->OfKind( ITEM::SOLID_T ) )
277  return 0xff;
278  else if( const SEGMENT* seg = dyn_cast<const SEGMENT*>( item ) )
279  {
280  SEG s = seg->Seg();
281  if( s.A != aP )
282  s.Reverse();
283 
284  if( n_dirs < 8 )
285  dirs[n_dirs++] = aFirst ? DIRECTION_45( s ) : DIRECTION_45( s ).Opposite();
286  }
287  }
288 
290  int outputMask = 0xff;
291 
292  for( int d = 0; d < 8; d++ )
293  {
294  DIRECTION_45 refDir( ( DIRECTION_45::Directions ) d );
295 
296  for( int i = 0; i < n_dirs; i++ )
297  {
298  if( !( refDir.Angle( dirs[i] ) & angleMask ) )
299  outputMask &= ~refDir.Mask();
300  }
301  }
302 
303  //DrawDebugDirs( aP, outputMask, 3 );
304  return 0xff;
305 }
306 
307 
308 void LINE_RESTRICTIONS::Build( NODE* aWorld, LINE* aOriginLine, const SHAPE_LINE_CHAIN& aLine, const BOX2I& aRestrictedArea, bool aRestrictedAreaEnable )
309 {
310  const SHAPE_LINE_CHAIN& l = aLine;
311  VECTOR2I v_prev;
312  int n = l.PointCount( );
313 
314  m_rs.reserve( n );
315 
316  for( int i = 0; i < n; i++ )
317  {
318  const VECTOR2I &v = l.CPoint( i );
319  RVERTEX r( false, 0xff );
320 
321  if( aRestrictedAreaEnable )
322  {
323  bool exiting = ( i > 0 && aRestrictedArea.Contains( v_prev ) && !aRestrictedArea.Contains( v ) );
324  bool entering = false;
325 
326  if( i != l.PointCount() - 1 )
327  {
328  const VECTOR2I& v_next = l.CPoint( i + 1 );
329  entering = ( !aRestrictedArea.Contains( v ) && aRestrictedArea.Contains( v_next ) );
330  }
331 
332  if( entering )
333  {
334  const SEG& sp = l.CSegment( i );
335  r.allowedAngles = DIRECTION_45( sp ).Mask();
336  }
337  else if( exiting )
338  {
339  const SEG& sp = l.CSegment( i - 1 );
340  r.allowedAngles = DIRECTION_45( sp ).Mask();
341  }
342  else
343  {
344  r.allowedAngles = ( !aRestrictedArea.Contains( v ) ) ? 0 : 0xff;
345  r.restricted = r.allowedAngles ? false : true;
346  }
347  }
348 
349  v_prev = v;
350  m_rs.push_back( r );
351  }
352 }
353 
354 
356 {
357 }
358 
359 
360 bool LINE_RESTRICTIONS::Check( int aVertex1, int aVertex2, const SHAPE_LINE_CHAIN& aReplacement )
361 {
362  if( m_rs.empty( ) )
363  return true;
364 
365  for( int i = aVertex1; i <= aVertex2; i++ )
366  if ( m_rs[i].restricted )
367  return false;
368 
369  const RVERTEX& v1 = m_rs[ aVertex1 ];
370  const RVERTEX& v2 = m_rs[ aVertex2 ];
371 
372  int m1 = DIRECTION_45( aReplacement.CSegment( 0 ) ).Mask();
373  int m2;
374 
375  if( aReplacement.SegmentCount() == 1 )
376  m2 = m1;
377  else
378  m2 = DIRECTION_45( aReplacement.CSegment( 1 ) ).Mask();
379 
380  return ( ( v1.allowedAngles & m1 ) != 0 ) &&
381  ( ( v2.allowedAngles & m2 ) != 0 );
382 }
383 
384 
385 bool OPTIMIZER::checkColliding( ITEM* aItem, bool aUpdateCache )
386 {
388 
389  return static_cast<bool>( m_world->CheckColliding( aItem ) );
390 
391 #if 0
392  // something is wrong with the cache, need to investigate.
393  m_cache.Query( aItem->Shape(), m_world->GetMaxClearance(), v, false );
394 
395  if( !v.m_collidingItem )
396  {
397  NODE::OPT_OBSTACLE obs = m_world->CheckColliding( aItem );
398 
399  if( obs )
400  {
401  if( aUpdateCache )
402  cacheAdd( obs->m_item );
403 
404  return true;
405  }
406  }
407  else
408  {
409  m_cacheTags[v.m_collidingItem].m_hits++;
410  return true;
411  }
412 
413  return false;
414 #endif
415 }
416 
417 
418 bool OPTIMIZER::checkColliding( LINE* aLine, const SHAPE_LINE_CHAIN& aOptPath )
419 {
420  LINE tmp( *aLine, aOptPath );
421 
422  return checkColliding( &tmp );
423 }
424 
425 
427 {
428  SHAPE_LINE_CHAIN& line = aLine->Line();
429 
430  int step = line.PointCount() - 3;
431  int iter = 0;
432  int segs_pre = line.SegmentCount();
433 
434  if( step < 0 )
435  return false;
436 
437  SHAPE_LINE_CHAIN current_path( line );
438 
439  while( 1 )
440  {
441  iter++;
442  int n_segs = current_path.SegmentCount();
443  int max_step = n_segs - 2;
444 
445  if( step > max_step )
446  step = max_step;
447 
448  if( step < 2 )
449  {
450  line = current_path;
451  return current_path.SegmentCount() < segs_pre;
452  }
453 
454  bool found_anything = false;
455  int n = 0;
456 
457  while( n < n_segs - step )
458  {
459  const SEG s1 = current_path.CSegment( n );
460  const SEG s2 = current_path.CSegment( n + step );
461  SEG s1opt, s2opt;
462 
463  if( DIRECTION_45( s1 ).IsObtuse( DIRECTION_45( s2 ) ) )
464  {
465  VECTOR2I ip = *s1.IntersectLines( s2 );
466 
467  if( s1.Distance( ip ) <= 1 || s2.Distance( ip ) <= 1 )
468  {
469  s1opt = SEG( s1.A, ip );
470  s2opt = SEG( ip, s2.B );
471  }
472  else
473  {
474  s1opt = SEG( s1.A, ip );
475  s2opt = SEG( ip, s2.B );
476  }
477 
478  if( DIRECTION_45( s1opt ).IsObtuse( DIRECTION_45( s2opt ) ) )
479  {
480  SHAPE_LINE_CHAIN opt_path;
481  opt_path.Append( s1opt.A );
482  opt_path.Append( s1opt.B );
483  opt_path.Append( s2opt.B );
484 
485  LINE opt_track( *aLine, opt_path );
486 
487  if( !checkColliding( &opt_track ) )
488  {
489  current_path.Replace( s1.Index() + 1, s2.Index(), ip );
490  // removeCachedSegments(aLine, s1.Index(), s2.Index());
491  n_segs = current_path.SegmentCount();
492  found_anything = true;
493  break;
494  }
495  }
496  }
497 
498  n++;
499  }
500 
501  if( !found_anything )
502  {
503  if( step <= 2 )
504  {
505  line = current_path;
506  return line.SegmentCount() < segs_pre;
507  }
508 
509  step--;
510  }
511  }
512 
513  return line.SegmentCount() < segs_pre;
514 }
515 
516 
518 {
519  SHAPE_LINE_CHAIN& line = aLine->Line();
520  int step = line.SegmentCount() - 1;
521 
522  int segs_pre = line.SegmentCount();
523 
524  line.Simplify();
525 
526  if( step < 0 )
527  return false;
528 
529  SHAPE_LINE_CHAIN current_path( line );
530 
531  while( 1 )
532  {
533  int n_segs = current_path.SegmentCount();
534  int max_step = n_segs - 2;
535 
536  if( step > max_step )
537  step = max_step;
538 
539  if( step < 1 )
540  break;
541 
542  bool found_anything = mergeStep( aLine, current_path, step );
543 
544  if( !found_anything )
545  step--;
546  }
547 
548  aLine->SetShape( current_path );
549 
550  return current_path.SegmentCount() < segs_pre;
551 }
552 
553 
554 bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult )
555 {
556  if( !aResult )
557  aResult = aLine;
558  else
559  *aResult = *aLine;
560 
561  m_keepPostures = false;
562 
563  bool rv = false;
564 
566  rv |= mergeFull( aResult );
567 
569  rv |= mergeObtuse( aResult );
570 
571  if( m_effortLevel & SMART_PADS )
572  rv |= runSmartPads( aResult );
573 
575  rv |= fanoutCleanup( aResult );
576 
577  return rv;
578 }
579 
580 
581 bool OPTIMIZER::mergeStep( LINE* aLine, SHAPE_LINE_CHAIN& aCurrentPath, int step )
582 {
583  int n = 0;
584  int n_segs = aCurrentPath.SegmentCount();
585 
586  int cost_orig = COST_ESTIMATOR::CornerCost( aCurrentPath );
587 
588  LINE_RESTRICTIONS restr;
589 
590  if( aLine->SegmentCount() < 4 )
591  return false;
592 
593  DIRECTION_45 orig_start( aLine->CSegment( 0 ) );
594  DIRECTION_45 orig_end( aLine->CSegment( -1 ) );
595 
596  restr.Build( m_world, aLine, aCurrentPath, m_restrictArea, m_restrictAreaActive );
597 
598  while( n < n_segs - step )
599  {
600  const SEG s1 = aCurrentPath.CSegment( n );
601  const SEG s2 = aCurrentPath.CSegment( n + step );
602 
603  SHAPE_LINE_CHAIN path[2];
604  SHAPE_LINE_CHAIN* picked = NULL;
605  int cost[2];
606 
607  for( int i = 0; i < 2; i++ )
608  {
609  bool postureMatch = true;
610  SHAPE_LINE_CHAIN bypass = DIRECTION_45().BuildInitialTrace( s1.A, s2.B, i );
611  cost[i] = INT_MAX;
612 
613  bool restrictionsOK = restr.Check ( n, n + step + 1, bypass );
614 
615  if( n == 0 && orig_start != DIRECTION_45( bypass.CSegment( 0 ) ) )
616  postureMatch = false;
617  else if( n == n_segs - step && orig_end != DIRECTION_45( bypass.CSegment( -1 ) ) )
618  postureMatch = false;
619 
620  if( restrictionsOK && (postureMatch || !m_keepPostures) && !checkColliding( aLine, bypass ) )
621  {
622  path[i] = aCurrentPath;
623  path[i].Replace( s1.Index(), s2.Index(), bypass );
624  path[i].Simplify();
625  cost[i] = COST_ESTIMATOR::CornerCost( path[i] );
626  }
627  }
628 
629  if( cost[0] < cost_orig && cost[0] < cost[1] )
630  picked = &path[0];
631  else if( cost[1] < cost_orig )
632  picked = &path[1];
633 
634  if( picked )
635  {
636  n_segs = aCurrentPath.SegmentCount();
637  aCurrentPath = *picked;
638  return true;
639  }
640 
641  n++;
642  }
643 
644  return false;
645 }
646 
647 
649  const SHAPE* aShape, bool aPermitDiagonal ) const
650 {
651  BREAKOUT_LIST breakouts;
652 
653  for( int angle = 0; angle < 360; angle += 45 )
654  {
655  const SHAPE_CIRCLE* cir = static_cast<const SHAPE_CIRCLE*>( aShape );
657  VECTOR2I p0 = cir->GetCenter();
658  VECTOR2I v0( cir->GetRadius() * M_SQRT2, 0 );
659  l.Append( p0 );
660  l.Append( p0 + v0.Rotate( angle * M_PI / 180.0 ) );
661  breakouts.push_back( l );
662  }
663 
664  return breakouts;
665 }
666 
667 
669  const SHAPE* aShape, bool aPermitDiagonal ) const
670 {
671  BREAKOUT_LIST breakouts;
672  const SHAPE_CONVEX* convex = static_cast<const SHAPE_CONVEX*>( aShape );
673 
674  BOX2I bbox = convex->BBox( 0 );
675  VECTOR2I p0 = bbox.Centre();
676  // must be large enough to guarantee intersecting the convex polygon
677  int length = bbox.GetSize().EuclideanNorm() / 2 + 5;
678 
679  for( int angle = 0; angle < 360; angle += ( aPermitDiagonal ? 45 : 90 ) )
680  {
682  VECTOR2I v0( p0 + VECTOR2I( length, 0 ).Rotate( angle * M_PI / 180.0 ) );
683  SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
684  int n = convex->Vertices().Intersect( SEG( p0, v0 ), intersections );
685  // if n == 1 intersected a segment
686  // if n == 2 intersected the common point of 2 segments
687  // n == 0 can not happen I think, but...
688  if( n > 0 )
689  {
690  l.Append( p0 );
691 
692  // for a breakout distance relative to the distance between
693  // center and polygon edge
694  //l.Append( intersections[0].p + (v0 - p0).Resize( (intersections[0].p - p0).EuclideanNorm() * 0.4 ) );
695 
696  // for an absolute breakout distance, e.g. 0.1 mm
697  l.Append( intersections[0].p + (v0 - p0).Resize( 100000 ) );
698 
699  // for the breakout right on the polygon edge
700  //l.Append( intersections[0].p );
701 
702  breakouts.push_back( l );
703  }
704  }
705 
706  return breakouts;
707 }
708 
709 
711  const SHAPE* aShape, bool aPermitDiagonal ) const
712 {
713  const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>(aShape);
714  VECTOR2I s = rect->GetSize(), c = rect->GetPosition() + VECTOR2I( s.x / 2, s.y / 2 );
715  BREAKOUT_LIST breakouts;
716 
717  VECTOR2I d_offset;
718 
719  d_offset.x = ( s.x > s.y ) ? ( s.x - s.y ) / 2 : 0;
720  d_offset.y = ( s.x < s.y ) ? ( s.y - s.x ) / 2 : 0;
721 
722  VECTOR2I d_vert = VECTOR2I( 0, s.y / 2 + aWidth );
723  VECTOR2I d_horiz = VECTOR2I( s.x / 2 + aWidth, 0 );
724 
725  breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_horiz ) );
726  breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_horiz ) );
727  breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_vert ) );
728  breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_vert ) );
729 
730  if( aPermitDiagonal )
731  {
732  int l = aWidth + std::min( s.x, s.y ) / 2;
733  VECTOR2I d_diag;
734 
735  if( s.x >= s.y )
736  {
737  breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
738  c + d_offset + VECTOR2I( l, l ) ) );
739  breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
740  c + d_offset - VECTOR2I( -l, l ) ) );
741  breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
742  c - d_offset + VECTOR2I( -l, l ) ) );
743  breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
744  c - d_offset - VECTOR2I( l, l ) ) );
745  }
746  else
747  {
748  // fixme: this could be done more efficiently
749  breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
750  c + d_offset + VECTOR2I( l, l ) ) );
751  breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
752  c - d_offset - VECTOR2I( -l, l ) ) );
753  breakouts.push_back( SHAPE_LINE_CHAIN( c, c + d_offset,
754  c + d_offset + VECTOR2I( -l, l ) ) );
755  breakouts.push_back( SHAPE_LINE_CHAIN( c, c - d_offset,
756  c - d_offset - VECTOR2I( l, l ) ) );
757  }
758  }
759 
760  return breakouts;
761 }
762 
763 
765  const ITEM* aItem, bool aPermitDiagonal ) const
766 {
767  switch( aItem->Kind() )
768  {
769  case ITEM::VIA_T:
770  {
771  const VIA* via = static_cast<const VIA*>( aItem );
772  return circleBreakouts( aWidth, via->Shape(), aPermitDiagonal );
773  }
774 
775  case ITEM::SOLID_T:
776  {
777  const SHAPE* shape = aItem->Shape();
778 
779  switch( shape->Type() )
780  {
781  case SH_RECT:
782  return rectBreakouts( aWidth, shape, aPermitDiagonal );
783 
784  case SH_SEGMENT:
785  {
786  const SHAPE_SEGMENT* seg = static_cast<const SHAPE_SEGMENT*> (shape);
787  const SHAPE_RECT rect = ApproximateSegmentAsRect ( *seg );
788  return rectBreakouts( aWidth, &rect, aPermitDiagonal );
789  }
790 
791  case SH_CIRCLE:
792  return circleBreakouts( aWidth, shape, aPermitDiagonal );
793 
794  case SH_CONVEX:
795  return convexBreakouts( aWidth, shape, aPermitDiagonal );
796 
797  default:
798  break;
799  }
800  }
801 
802  default:
803  break;
804  }
805 
806  return BREAKOUT_LIST();
807 }
808 
809 
810 ITEM* OPTIMIZER::findPadOrVia( int aLayer, int aNet, const VECTOR2I& aP ) const
811 {
812  JOINT* jt = m_world->FindJoint( aP, aLayer, aNet );
813 
814  if( !jt )
815  return NULL;
816 
817  for( ITEM* item : jt->LinkList() )
818  {
819  if( item->OfKind( ITEM::VIA_T | ITEM::SOLID_T ) )
820  return item;
821  }
822 
823  return NULL;
824 }
825 
826 
827 int OPTIMIZER::smartPadsSingle( LINE* aLine, ITEM* aPad, bool aEnd, int aEndVertex )
828 {
829  int min_cost = INT_MAX; // COST_ESTIMATOR::CornerCost( line );
830  int min_len = INT_MAX;
831  DIRECTION_45 dir;
832 
833  const int ForbiddenAngles = DIRECTION_45::ANG_ACUTE | DIRECTION_45::ANG_RIGHT |
835 
836  typedef std::pair<int, SHAPE_LINE_CHAIN> RtVariant;
837  std::vector<RtVariant> variants;
838 
839  SOLID* solid = dyn_cast<SOLID*>( aPad );
840 
841  // don't do auto-neckdown for offset pads
842  if( solid && solid->Offset() != VECTOR2I( 0, 0 ) )
843  return -1;
844 
845 
846  BREAKOUT_LIST breakouts = computeBreakouts( aLine->Width(), aPad, true );
847 
848  SHAPE_LINE_CHAIN line = ( aEnd ? aLine->CLine().Reverse() : aLine->CLine() );
849 
850 
851  int p_end = std::min( aEndVertex, std::min( 3, line.PointCount() - 1 ) );
852 
853  for( int p = 1; p <= p_end; p++ )
854  {
855  for( SHAPE_LINE_CHAIN & l : breakouts ) {
856 
857  for( int diag = 0; diag < 2; diag++ )
858  {
860  SHAPE_LINE_CHAIN connect = dir.BuildInitialTrace( l.CPoint( -1 ),
861  line.CPoint( p ), diag == 0 );
862 
863  DIRECTION_45 dir_bkout( l.CSegment( -1 ) );
864 
865  if(!connect.SegmentCount())
866  continue;
867 
868  int ang1 = dir_bkout.Angle( DIRECTION_45( connect.CSegment( 0 ) ) );
869  int ang2 = 0;
870 
871  if( (ang1 | ang2) & ForbiddenAngles )
872  continue;
873 
874  if( l.Length() > line.Length() )
875  continue;
876 
877  v = l;
878 
879  v.Append( connect );
880 
881  for( int i = p + 1; i < line.PointCount(); i++ )
882  v.Append( line.CPoint( i ) );
883 
884  LINE tmp( *aLine, v );
885  int cc = tmp.CountCorners( ForbiddenAngles );
886 
887  if( cc == 0 )
888  {
889  RtVariant vp;
890  vp.first = p;
891  vp.second = aEnd ? v.Reverse() : v;
892  vp.second.Simplify();
893  variants.push_back( vp );
894  }
895  }
896  }
897  }
898 
899  SHAPE_LINE_CHAIN l_best;
900  bool found = false;
901  int p_best = -1;
902 
903  for( RtVariant& vp : variants )
904  {
905  LINE tmp( *aLine, vp.second );
906  int cost = COST_ESTIMATOR::CornerCost( vp.second );
907  int len = vp.second.Length();
908 
909  if( !checkColliding( &tmp ) )
910  {
911  if( cost < min_cost || ( cost == min_cost && len < min_len ) )
912  {
913  l_best = vp.second;
914  p_best = vp.first;
915  found = true;
916 
917  if( cost == min_cost )
918  min_len = std::min( len, min_len );
919 
920  min_cost = std::min( cost, min_cost );
921  }
922  }
923  }
924 
925  if( found )
926  {
927  aLine->SetShape( l_best );
928  return p_best;
929  }
930 
931  return -1;
932 }
933 
935 {
936  SHAPE_LINE_CHAIN& line = aLine->Line();
937 
938  if( line.PointCount() < 3 )
939  return false;
940 
941  VECTOR2I p_start = line.CPoint( 0 ), p_end = line.CPoint( -1 );
942 
943  ITEM* startPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_start );
944  ITEM* endPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_end );
945 
946  int vtx = -1;
947 
948  if( startPad )
949  vtx = smartPadsSingle( aLine, startPad, false, 3 );
950 
951  if( endPad )
952  smartPadsSingle( aLine, endPad, true,
953  vtx < 0 ? line.PointCount() - 1 : line.PointCount() - 1 - vtx );
954 
955  aLine->Line().Simplify();
956 
957  return true;
958 }
959 
960 
961 bool OPTIMIZER::Optimize( LINE* aLine, int aEffortLevel, NODE* aWorld )
962 {
963  OPTIMIZER opt( aWorld );
964 
965  opt.SetEffortLevel( aEffortLevel );
966  opt.SetCollisionMask( -1 );
967  return opt.Optimize( aLine );
968 }
969 
970 
972 {
973  if( aLine->PointCount() < 3 )
974  return false;
975 
976  VECTOR2I p_start = aLine->CPoint( 0 ), p_end = aLine->CPoint( -1 );
977 
978  ITEM* startPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_start );
979  ITEM* endPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_end );
980 
981  int thr = aLine->Width() * 10;
982  int len = aLine->CLine().Length();
983 
984  if( !startPad )
985  return false;
986 
987  bool startMatch = startPad->OfKind( ITEM::VIA_T | ITEM::SOLID_T );
988  bool endMatch = false;
989 
990  if(endPad)
991  {
992  endMatch = endPad->OfKind( ITEM::VIA_T | ITEM::SOLID_T );
993  }
994  else
995  {
996  endMatch = aLine->EndsWithVia();
997  }
998 
999  if( startMatch && endMatch && len < thr )
1000  {
1001  for( int i = 0; i < 2; i++ )
1002  {
1003  SHAPE_LINE_CHAIN l2 = DIRECTION_45().BuildInitialTrace( p_start, p_end, i );
1004  LINE repl;
1005  repl = LINE( *aLine, l2 );
1006 
1007  if( !m_world->CheckColliding( &repl ) )
1008  {
1009  aLine->SetShape( repl.CLine() );
1010  return true;
1011  }
1012  }
1013  }
1014 
1015  return false;
1016 }
1017 
1018 
1019 int findCoupledVertices( const VECTOR2I& aVertex, const SEG& aOrigSeg, const SHAPE_LINE_CHAIN& aCoupled, DIFF_PAIR* aPair, int* aIndices )
1020 {
1021  int count = 0;
1022  for ( int i = 0; i < aCoupled.SegmentCount(); i++ )
1023  {
1024  SEG s = aCoupled.CSegment( i );
1025  VECTOR2I projOverCoupled = s.LineProject ( aVertex );
1026 
1027  if( s.ApproxParallel ( aOrigSeg ) )
1028  {
1029  int64_t dist = ( projOverCoupled - aVertex ).EuclideanNorm() - aPair->Width();
1030 
1031  if( aPair->GapConstraint().Matches( dist ) )
1032  {
1033  *aIndices++ = i;
1034  count++;
1035  }
1036  }
1037  }
1038 
1039  return count;
1040 }
1041 
1042 
1043 bool verifyDpBypass( NODE* aNode, DIFF_PAIR* aPair, bool aRefIsP, const SHAPE_LINE_CHAIN& aNewRef, const SHAPE_LINE_CHAIN& aNewCoupled )
1044 {
1045  LINE refLine ( aRefIsP ? aPair->PLine() : aPair->NLine(), aNewRef );
1046  LINE coupledLine ( aRefIsP ? aPair->NLine() : aPair->PLine(), aNewCoupled );
1047 
1048  if( aNode->CheckColliding( &refLine, &coupledLine, ITEM::ANY_T, aPair->Gap() - 10 ) )
1049  return false;
1050 
1051  if( aNode->CheckColliding ( &refLine ) )
1052  return false;
1053 
1054  if( aNode->CheckColliding ( &coupledLine ) )
1055  return false;
1056 
1057  return true;
1058 }
1059 
1060 
1061 bool coupledBypass( NODE* aNode, DIFF_PAIR* aPair, bool aRefIsP, const SHAPE_LINE_CHAIN& aRef, const SHAPE_LINE_CHAIN& aRefBypass, const SHAPE_LINE_CHAIN& aCoupled, SHAPE_LINE_CHAIN& aNewCoupled )
1062 {
1063  int vStartIdx[1024]; // fixme: possible overflow
1064 
1065  int nStarts = findCoupledVertices( aRefBypass.CPoint( 0 ), aRefBypass.CSegment( 0 ), aCoupled, aPair, vStartIdx );
1066  DIRECTION_45 dir( aRefBypass.CSegment( 0 ) );
1067 
1068  int64_t bestLength = -1;
1069  bool found = false;
1070  SHAPE_LINE_CHAIN bestBypass;
1071  int si, ei;
1072 
1073  for( int i=0; i< nStarts; i++ )
1074  {
1075  for( int j = 1; j < aCoupled.PointCount() - 1; j++ )
1076  {
1077  int delta = std::abs ( vStartIdx[i] - j );
1078 
1079  if( delta > 1 )
1080  {
1081  const VECTOR2I& vs = aCoupled.CPoint( vStartIdx[i] );
1082  SHAPE_LINE_CHAIN bypass = dir.BuildInitialTrace( vs, aCoupled.CPoint(j), dir.IsDiagonal() );
1083 
1084  int64_t coupledLength = aPair->CoupledLength( aRef, bypass );
1085 
1086  SHAPE_LINE_CHAIN newCoupled = aCoupled;
1087 
1088  si = vStartIdx[i];
1089  ei = j;
1090 
1091  if(si < ei)
1092  newCoupled.Replace( si, ei, bypass );
1093  else
1094  newCoupled.Replace( ei, si, bypass.Reverse() );
1095 
1096  if(coupledLength > bestLength && verifyDpBypass( aNode, aPair, aRefIsP, aRef, newCoupled) )
1097  {
1098  bestBypass = newCoupled;
1099  bestLength = coupledLength;
1100  found = true;
1101  }
1102  }
1103  }
1104  }
1105 
1106 
1107  if( found )
1108  aNewCoupled = bestBypass;
1109 
1110  return found;
1111 }
1112 
1113 
1114 bool checkDpColliding( NODE* aNode, DIFF_PAIR* aPair, bool aIsP, const SHAPE_LINE_CHAIN& aPath )
1115 {
1116  LINE tmp ( aIsP ? aPair->PLine() : aPair->NLine(), aPath );
1117 
1118  return static_cast<bool>( aNode->CheckColliding( &tmp ) );
1119 }
1120 
1121 
1122 bool OPTIMIZER::mergeDpStep( DIFF_PAIR* aPair, bool aTryP, int step )
1123 {
1124  int n = 1;
1125 
1126  SHAPE_LINE_CHAIN currentPath = aTryP ? aPair->CP() : aPair->CN();
1127  SHAPE_LINE_CHAIN coupledPath = aTryP ? aPair->CN() : aPair->CP();
1128 
1129  int n_segs = currentPath.SegmentCount() - 1;
1130 
1131  int64_t clenPre = aPair->CoupledLength( currentPath, coupledPath );
1132  int64_t budget = clenPre / 10; // fixme: come up with somethig more intelligent here...
1133 
1134  while( n < n_segs - step )
1135  {
1136  const SEG s1 = currentPath.CSegment( n );
1137  const SEG s2 = currentPath.CSegment( n + step );
1138 
1139  DIRECTION_45 dir1( s1 );
1140  DIRECTION_45 dir2( s2 );
1141 
1142  if( dir1.IsObtuse( dir2 ) )
1143  {
1144  SHAPE_LINE_CHAIN bypass = DIRECTION_45().BuildInitialTrace( s1.A, s2.B, dir1.IsDiagonal() );
1145  SHAPE_LINE_CHAIN newRef;
1146  SHAPE_LINE_CHAIN newCoup;
1147  int64_t deltaCoupled = -1, deltaUni = -1;
1148 
1149  newRef = currentPath;
1150  newRef.Replace( s1.Index(), s2.Index(), bypass );
1151 
1152  deltaUni = aPair->CoupledLength ( newRef, coupledPath ) - clenPre + budget;
1153 
1154  if ( coupledBypass( m_world, aPair, aTryP, newRef, bypass, coupledPath, newCoup ) )
1155  {
1156  deltaCoupled = aPair->CoupledLength( newRef, newCoup ) - clenPre + budget;
1157 
1158  if( deltaCoupled >= 0 )
1159  {
1160  newRef.Simplify();
1161  newCoup.Simplify();
1162 
1163  aPair->SetShape( newRef, newCoup, !aTryP );
1164  return true;
1165  }
1166  }
1167  else if( deltaUni >= 0 && verifyDpBypass ( m_world, aPair, aTryP, newRef, coupledPath ) )
1168  {
1169  newRef.Simplify();
1170  coupledPath.Simplify();
1171 
1172  aPair->SetShape( newRef, coupledPath, !aTryP );
1173  return true;
1174  }
1175  }
1176 
1177  n++;
1178  }
1179 
1180  return false;
1181 }
1182 
1183 
1185 {
1186  int step_p = aPair->CP().SegmentCount() - 2;
1187  int step_n = aPair->CN().SegmentCount() - 2;
1188 
1189  while( 1 )
1190  {
1191  int n_segs_p = aPair->CP().SegmentCount();
1192  int n_segs_n = aPair->CN().SegmentCount();
1193 
1194  int max_step_p = n_segs_p - 2;
1195  int max_step_n = n_segs_n - 2;
1196 
1197  if( step_p > max_step_p )
1198  step_p = max_step_p;
1199 
1200  if( step_n > max_step_n )
1201  step_n = max_step_n;
1202 
1203  if( step_p < 1 && step_n < 1)
1204  break;
1205 
1206  bool found_anything_p = false;
1207  bool found_anything_n = false;
1208 
1209  if( step_p > 1 )
1210  found_anything_p = mergeDpStep( aPair, true, step_p );
1211 
1212  if( step_n > 1 )
1213  found_anything_n = mergeDpStep( aPair, false, step_n );
1214 
1215  if( !found_anything_n && !found_anything_p )
1216  {
1217  step_n--;
1218  step_p--;
1219  }
1220  }
1221  return true;
1222 }
1223 
1224 
1226 {
1227  return mergeDpSegments( aPair );
1228 }
1229 
1230 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
int Mask() const
Definition: direction45.h:313
const SHAPE_LINE_CHAIN & CLine() const
Const accessor to the underlying shape
Definition: pns_line.h:123
int Index() const
Function Index()
Definition: seg.h:301
bool m_restrictAreaActive
double CoupledLength() const
Class ITEM.
Definition: pns_item.h:53
RVERTEX(bool aRestricted, int aAllowedAngles)
void CacheStaticItem(ITEM *aItem)
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_convex.h:74
const RANGED_NUM< int > GapConstraint() const
int Width() const
std::vector< INTERSECTION > INTERSECTIONS
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
int GetMaxClearance() const
Returns the pre-set worst case clearance between any pair of items
Definition: pns_node.h:151
Class NODE.
Definition: pns_node.h:137
void CacheRemove(ITEM *aItem)
void removeCachedSegments(LINE *aLine, int aStartVertex=0, int aEndVertex=-1)
const ENTRIES & CItems() const
Definition: pns_itemset.h:138
virtual int Layer() const
Function Layer()
Definition: pns_item.h:217
const SHAPE_LINE_CHAIN Reverse() const
Function Reverse()
void SetShape(const SHAPE_LINE_CHAIN &aP, const SHAPE_LINE_CHAIN &aN, bool aSwapLanes=false)
int PointCount() const
Function PointCount()
void Replace(LINE &aOldLine, LINE &aNewLine)
VECTOR2I LineProject(const VECTOR2I &aP) const
Function LineProject()
Definition: seg.h:322
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:139
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Function IntersectLines()
Definition: seg.h:170
bool mergeStep(LINE *aLine, SHAPE_LINE_CHAIN &aCurrentLine, int step)
int GetRadius() const
Definition: shape_circle.h:79
static const int dist[10][10]
Definition: dist.cpp:57
ITEM * findPadOrVia(int aLayer, int aNet, const VECTOR2I &aP) const
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
const SHAPE_LINE_CHAIN & CN() const
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Function Intersect()
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:296
Class SHAPE_CONVEX.
Definition: shape_convex.h:42
std::vector< RVERTEX > m_rs
bool runSmartPads(LINE *aLine)
const Vec & GetSize() const
Definition: box2.h:177
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
bool mergeFull(LINE *aLine)
#define abs(a)
Definition: auxiliary.h:84
int Width() const
Returns line width
Definition: pns_line.h:159
const SHAPE * Shape() const override
Function Shape()
Definition: pns_via.h:136
static const int delta[8][2]
Definition: solve.cpp:112
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:73
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
int allowedAngles(NODE *aWorld, const LINE *aLine, const VECTOR2I &aP, bool aFirst)
BREAKOUT_LIST circleBreakouts(int aWidth, const SHAPE *aShape, bool aPermitDiagonal) const
virtual bool Collide(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I &aMTV, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.cpp:44
int PointCount() const
Returns the number of points in the line
Definition: pns_line.h:135
void SetCollisionMask(int aMask)
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:130
bool mergeDpStep(DIFF_PAIR *aPair, bool aTryP, int step)
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Assigns a shape to the line (a polyline/line chain)
Definition: pns_line.h:105
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
ITEM_SET & Links()
Definition: pns_joint.h:187
int CountCorners(int aAngles) const
Returns the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:138
const SEG CSegment(int aIndex) const
Function CSegment()
Class JOINT.
Definition: pns_joint.h:44
BREAKOUT_LIST convexBreakouts(int aWidth, const SHAPE *aShape, bool aPermitDiagonal) const
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:295
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_convex.h:139
BREAKOUT_LIST rectBreakouts(int aWidth, const SHAPE *aShape, bool aPermitDiagonal) const
int SegmentCount() const
Returns the number of segments in the line
Definition: pns_line.h:129
Class DIRECTION_45.
Definition: direction45.h:33
int Gap() const
bool IsObtuse(const DIRECTION_45 &aOther) const
Function IsObtuse()
Definition: direction45.h:169
bool mergeDpSegments(DIFF_PAIR *aPair)
const VECTOR2I & GetPosition() const
Function GetPosition()
Definition: shape_rect.h:100
std::vector< SEGMENT * > SEGMENT_REFS
Definition: pns_line.h:63
bool EndsWithVia() const
Definition: pns_line.h:248
bool coupledBypass(NODE *aNode, DIFF_PAIR *aPair, bool aRefIsP, const SHAPE_LINE_CHAIN &aRef, const SHAPE_LINE_CHAIN &aRefBypass, const SHAPE_LINE_CHAIN &aCoupled, SHAPE_LINE_CHAIN &aNewCoupled)
bool Check(int aVertex1, int aVertex2, const SHAPE_LINE_CHAIN &aReplacement)
bool mergeObtuse(LINE *aLine)
Class SHAPE.
Definition: shape.h:57
bool IsBetter(COST_ESTIMATOR &aOther, double aLengthTolerance, double aCornerTollerace) const
bool IsDiagonal() const
Function IsDiagonal() Returns true if the direction is diagonal (e.g.
Definition: direction45.h:179
Vec Centre() const
Definition: box2.h:67
int findCoupledVertices(const VECTOR2I &aVertex, const SEG &aOrigSeg, const SHAPE_LINE_CHAIN &aCoupled, DIFF_PAIR *aPair, int *aIndices)
line chain (polyline)
Definition: shape.h:46
CachedItemTags m_cacheTags
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Function FindJoint()
Definition: pns_node.cpp:968
void Build(NODE *aWorld, LINE *aOriginLine, const SHAPE_LINE_CHAIN &aLine, const BOX2I &aRestrictedArea, bool aRestrictedAreaEnable)
SHAPE_LINE_CHAIN & Line()
Modifiable accessor to the underlying shape
Definition: pns_line.h:117
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:120
Definition: seg.h:37
OPTIMIZER(NODE *aWorld)
Optimizer.
Class DIFF_PAIR.
void cacheAdd(ITEM *aItem, bool aIsStatic)
bool operator()(ITEM *aOtherItem)
void Reverse()
Definition: seg.h:310
const SEG CSegment(int aIdx) const
Returns the aIdx-th segment of the line
Definition: pns_line.h:147
bool verifyDpBypass(NODE *aNode, DIFF_PAIR *aPair, bool aRefIsP, const SHAPE_LINE_CHAIN &aNewRef, const SHAPE_LINE_CHAIN &aNewCoupled)
CACHE_VISITOR(const ITEM *aOurItem, NODE *aNode, int aMask)
SEGMENT_REFS & LinkedSegments()
Returns the list of segments from the owning node that constitute this line (or NULL if the line is n...
Definition: pns_line.h:181
int GetClearance(const ITEM *aA, const ITEM *aB) const
Returns the expected clearance between items a and b.
Definition: pns_node.cpp:100
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:82
bool fanoutCleanup(LINE *aLine)
Class SHAPE_LINE_CHAIN.
SHAPE_RECT ApproximateSegmentAsRect(const SHAPE_SEGMENT &aSeg)
Definition: pns_utils.cpp:157
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:427
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
VECTOR2I A
Definition: seg.h:47
bool checkColliding(ITEM *aItem, bool aUpdateCache=true)
AngleType Angle(const DIRECTION_45 &aOther) const
Function Angle() Returns the type of angle between directions (this) and aOther.
Definition: direction45.h:146
void Add(LINE &aLine)
VECTOR2I Offset() const
Definition: pns_solid.h:94
int Net() const
Function Net()
Definition: pns_item.h:177
bool Matches(const T &aOther) const
Definition: ranged_num.h:43
static int CornerCost(const SEG &aA, const SEG &aB)
Cost Estimator Methods.
Class OPTIMIZER.
Definition: pns_optimizer.h:90
int smartPadsSingle(LINE *aLine, ITEM *aPad, bool aEnd, int aEndVertex)
SHAPE_INDEX_LIST< ITEM * > m_cache
void SetEffortLevel(int aEffort)
Definition: shape.h:43
std::vector< SHAPE_LINE_CHAIN > BREAKOUT_LIST
BREAKOUT_LIST computeBreakouts(int aWidth, const ITEM *aItem, bool aPermitDiagonal) const
const SHAPE_LINE_CHAIN BuildInitialTrace(const VECTOR2I &aP0, const VECTOR2I &aP1, bool aStartDiagonal=false) const
Function BuildInitialTrace()
Definition: direction45.h:199
const LINKED_ITEMS & LinkList() const
Definition: pns_joint.h:177
void Replace(int aStartIndex, int aEndIndex, const VECTOR2I &aP)
Function Replace()
static bool Optimize(LINE *aLine, int aEffortLevel, NODE *aWorld)
a quick shortcut to optmize a line without creating and setting up an optimizer
bool ApproxParallel(const SEG &aSeg) const
Definition: seg.h:244
Class COST_ESTIMATOR.
Definition: pns_optimizer.h:45
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:42
Push and Shove diff pair dimensions (gap) settings dialog.
circle
Definition: shape.h:47
void Remove(LINE &aLine)
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool checkDpColliding(NODE *aNode, DIFF_PAIR *aPair, bool aIsP, const SHAPE_LINE_CHAIN &aPath)
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:186
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:110
void ClearCache(bool aStaticOnly=false)
int SegmentCount() const
Function SegmentCount()
int Length() const
Function Length()
const SHAPE_LINE_CHAIN & CP() const
#define min(a, b)
Definition: auxiliary.h:85
axis-aligned rectangle
Definition: shape.h:44
const VECTOR2I & CPoint(int aIdx) const
Returns the aIdx-th point of the line
Definition: pns_line.h:141
bool IsLinked() const
Definition: pns_line.h:186
VECTOR2I B
Definition: seg.h:48