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 <cmath>
25 
26 #include "pns_line.h"
27 #include "pns_diff_pair.h"
28 #include "pns_node.h"
29 #include "pns_solid.h"
30 #include "pns_optimizer.h"
31 
32 #include "../../include/geometry/shape_simple.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 ITEM* aItem, bool aPermitDiagonal ) const
670 {
671  BREAKOUT_LIST breakouts;
672  const SHAPE_SIMPLE* convex = static_cast<const SHAPE_SIMPLE*>( aItem->Shape() );
673 
674  BOX2I bbox = convex->BBox( 0 );
675  VECTOR2I p0 = static_cast<const SOLID*>( aItem )->Pos();
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_SIMPLE:
795  return customBreakouts( aWidth, aItem, aPermitDiagonal );
796 
797  default:
798  break;
799  }
800 
801  break;
802  }
803 
804  default:
805  break;
806  }
807 
808  return BREAKOUT_LIST();
809 }
810 
811 
812 ITEM* OPTIMIZER::findPadOrVia( int aLayer, int aNet, const VECTOR2I& aP ) const
813 {
814  JOINT* jt = m_world->FindJoint( aP, aLayer, aNet );
815 
816  if( !jt )
817  return NULL;
818 
819  for( ITEM* item : jt->LinkList() )
820  {
821  if( item->OfKind( ITEM::VIA_T | ITEM::SOLID_T ) )
822  return item;
823  }
824 
825  return NULL;
826 }
827 
828 
829 int OPTIMIZER::smartPadsSingle( LINE* aLine, ITEM* aPad, bool aEnd, int aEndVertex )
830 {
831  int min_cost = INT_MAX; // COST_ESTIMATOR::CornerCost( line );
832  int min_len = INT_MAX;
833  DIRECTION_45 dir;
834 
835  const int ForbiddenAngles = DIRECTION_45::ANG_ACUTE | DIRECTION_45::ANG_RIGHT |
837 
838  typedef std::pair<int, SHAPE_LINE_CHAIN> RtVariant;
839  std::vector<RtVariant> variants;
840 
841  SOLID* solid = dyn_cast<SOLID*>( aPad );
842 
843  // don't do optimized connections for offset pads
844  if( solid && solid->Offset() != VECTOR2I( 0, 0 ) )
845  return -1;
846 
847 
848  BREAKOUT_LIST breakouts = computeBreakouts( aLine->Width(), aPad, true );
849 
850  SHAPE_LINE_CHAIN line = ( aEnd ? aLine->CLine().Reverse() : aLine->CLine() );
851 
852 
853  int p_end = std::min( aEndVertex, std::min( 3, line.PointCount() - 1 ) );
854 
855  for( int p = 1; p <= p_end; p++ )
856  {
857  for( SHAPE_LINE_CHAIN & l : breakouts ) {
858 
859  for( int diag = 0; diag < 2; diag++ )
860  {
862  SHAPE_LINE_CHAIN connect = dir.BuildInitialTrace( l.CPoint( -1 ),
863  line.CPoint( p ), diag == 0 );
864 
865  DIRECTION_45 dir_bkout( l.CSegment( -1 ) );
866 
867  if(!connect.SegmentCount())
868  continue;
869 
870  int ang1 = dir_bkout.Angle( DIRECTION_45( connect.CSegment( 0 ) ) );
871  int ang2 = 0;
872 
873  if( (ang1 | ang2) & ForbiddenAngles )
874  continue;
875 
876  if( l.Length() > line.Length() )
877  continue;
878 
879  v = l;
880 
881  v.Append( connect );
882 
883  for( int i = p + 1; i < line.PointCount(); i++ )
884  v.Append( line.CPoint( i ) );
885 
886  LINE tmp( *aLine, v );
887  int cc = tmp.CountCorners( ForbiddenAngles );
888 
889  if( cc == 0 )
890  {
891  RtVariant vp;
892  vp.first = p;
893  vp.second = aEnd ? v.Reverse() : v;
894  vp.second.Simplify();
895  variants.push_back( vp );
896  }
897  }
898  }
899  }
900 
901  SHAPE_LINE_CHAIN l_best;
902  bool found = false;
903  int p_best = -1;
904 
905  for( RtVariant& vp : variants )
906  {
907  LINE tmp( *aLine, vp.second );
908  int cost = COST_ESTIMATOR::CornerCost( vp.second );
909  int len = vp.second.Length();
910 
911  if( !checkColliding( &tmp ) )
912  {
913  if( cost < min_cost || ( cost == min_cost && len < min_len ) )
914  {
915  l_best = vp.second;
916  p_best = vp.first;
917  found = true;
918 
919  if( cost == min_cost )
920  min_len = std::min( len, min_len );
921 
922  min_cost = std::min( cost, min_cost );
923  }
924  }
925  }
926 
927  if( found )
928  {
929  aLine->SetShape( l_best );
930  return p_best;
931  }
932 
933  return -1;
934 }
935 
937 {
938  SHAPE_LINE_CHAIN& line = aLine->Line();
939 
940  if( line.PointCount() < 3 )
941  return false;
942 
943  VECTOR2I p_start = line.CPoint( 0 ), p_end = line.CPoint( -1 );
944 
945  ITEM* startPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_start );
946  ITEM* endPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_end );
947 
948  int vtx = -1;
949 
950  if( startPad )
951  vtx = smartPadsSingle( aLine, startPad, false, 3 );
952 
953  if( endPad )
954  smartPadsSingle( aLine, endPad, true,
955  vtx < 0 ? line.PointCount() - 1 : line.PointCount() - 1 - vtx );
956 
957  aLine->Line().Simplify();
958 
959  return true;
960 }
961 
962 
963 bool OPTIMIZER::Optimize( LINE* aLine, int aEffortLevel, NODE* aWorld )
964 {
965  OPTIMIZER opt( aWorld );
966 
967  opt.SetEffortLevel( aEffortLevel );
968  opt.SetCollisionMask( -1 );
969  return opt.Optimize( aLine );
970 }
971 
972 
974 {
975  if( aLine->PointCount() < 3 )
976  return false;
977 
978  VECTOR2I p_start = aLine->CPoint( 0 ), p_end = aLine->CPoint( -1 );
979 
980  ITEM* startPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_start );
981  ITEM* endPad = findPadOrVia( aLine->Layer(), aLine->Net(), p_end );
982 
983  int thr = aLine->Width() * 10;
984  int len = aLine->CLine().Length();
985 
986  if( !startPad )
987  return false;
988 
989  bool startMatch = startPad->OfKind( ITEM::VIA_T | ITEM::SOLID_T );
990  bool endMatch = false;
991 
992  if(endPad)
993  {
994  endMatch = endPad->OfKind( ITEM::VIA_T | ITEM::SOLID_T );
995  }
996  else
997  {
998  endMatch = aLine->EndsWithVia();
999  }
1000 
1001  if( startMatch && endMatch && len < thr )
1002  {
1003  for( int i = 0; i < 2; i++ )
1004  {
1005  SHAPE_LINE_CHAIN l2 = DIRECTION_45().BuildInitialTrace( p_start, p_end, i );
1006  LINE repl;
1007  repl = LINE( *aLine, l2 );
1008 
1009  if( !m_world->CheckColliding( &repl ) )
1010  {
1011  aLine->SetShape( repl.CLine() );
1012  return true;
1013  }
1014  }
1015  }
1016 
1017  return false;
1018 }
1019 
1020 
1021 int findCoupledVertices( const VECTOR2I& aVertex, const SEG& aOrigSeg, const SHAPE_LINE_CHAIN& aCoupled, DIFF_PAIR* aPair, int* aIndices )
1022 {
1023  int count = 0;
1024  for ( int i = 0; i < aCoupled.SegmentCount(); i++ )
1025  {
1026  SEG s = aCoupled.CSegment( i );
1027  VECTOR2I projOverCoupled = s.LineProject ( aVertex );
1028 
1029  if( s.ApproxParallel ( aOrigSeg ) )
1030  {
1031  int64_t dist = ( projOverCoupled - aVertex ).EuclideanNorm() - aPair->Width();
1032 
1033  if( aPair->GapConstraint().Matches( dist ) )
1034  {
1035  *aIndices++ = i;
1036  count++;
1037  }
1038  }
1039  }
1040 
1041  return count;
1042 }
1043 
1044 
1045 bool verifyDpBypass( NODE* aNode, DIFF_PAIR* aPair, bool aRefIsP, const SHAPE_LINE_CHAIN& aNewRef, const SHAPE_LINE_CHAIN& aNewCoupled )
1046 {
1047  LINE refLine ( aRefIsP ? aPair->PLine() : aPair->NLine(), aNewRef );
1048  LINE coupledLine ( aRefIsP ? aPair->NLine() : aPair->PLine(), aNewCoupled );
1049 
1050  if( aNode->CheckColliding( &refLine, &coupledLine, ITEM::ANY_T, aPair->Gap() - 10 ) )
1051  return false;
1052 
1053  if( aNode->CheckColliding ( &refLine ) )
1054  return false;
1055 
1056  if( aNode->CheckColliding ( &coupledLine ) )
1057  return false;
1058 
1059  return true;
1060 }
1061 
1062 
1063 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 )
1064 {
1065  int vStartIdx[1024]; // fixme: possible overflow
1066 
1067  int nStarts = findCoupledVertices( aRefBypass.CPoint( 0 ), aRefBypass.CSegment( 0 ), aCoupled, aPair, vStartIdx );
1068  DIRECTION_45 dir( aRefBypass.CSegment( 0 ) );
1069 
1070  int64_t bestLength = -1;
1071  bool found = false;
1072  SHAPE_LINE_CHAIN bestBypass;
1073  int si, ei;
1074 
1075  for( int i=0; i< nStarts; i++ )
1076  {
1077  for( int j = 1; j < aCoupled.PointCount() - 1; j++ )
1078  {
1079  int delta = std::abs ( vStartIdx[i] - j );
1080 
1081  if( delta > 1 )
1082  {
1083  const VECTOR2I& vs = aCoupled.CPoint( vStartIdx[i] );
1084  SHAPE_LINE_CHAIN bypass = dir.BuildInitialTrace( vs, aCoupled.CPoint(j), dir.IsDiagonal() );
1085 
1086  int64_t coupledLength = aPair->CoupledLength( aRef, bypass );
1087 
1088  SHAPE_LINE_CHAIN newCoupled = aCoupled;
1089 
1090  si = vStartIdx[i];
1091  ei = j;
1092 
1093  if(si < ei)
1094  newCoupled.Replace( si, ei, bypass );
1095  else
1096  newCoupled.Replace( ei, si, bypass.Reverse() );
1097 
1098  if(coupledLength > bestLength && verifyDpBypass( aNode, aPair, aRefIsP, aRef, newCoupled) )
1099  {
1100  bestBypass = newCoupled;
1101  bestLength = coupledLength;
1102  found = true;
1103  }
1104  }
1105  }
1106  }
1107 
1108 
1109  if( found )
1110  aNewCoupled = bestBypass;
1111 
1112  return found;
1113 }
1114 
1115 
1116 bool checkDpColliding( NODE* aNode, DIFF_PAIR* aPair, bool aIsP, const SHAPE_LINE_CHAIN& aPath )
1117 {
1118  LINE tmp ( aIsP ? aPair->PLine() : aPair->NLine(), aPath );
1119 
1120  return static_cast<bool>( aNode->CheckColliding( &tmp ) );
1121 }
1122 
1123 
1124 bool OPTIMIZER::mergeDpStep( DIFF_PAIR* aPair, bool aTryP, int step )
1125 {
1126  int n = 1;
1127 
1128  SHAPE_LINE_CHAIN currentPath = aTryP ? aPair->CP() : aPair->CN();
1129  SHAPE_LINE_CHAIN coupledPath = aTryP ? aPair->CN() : aPair->CP();
1130 
1131  int n_segs = currentPath.SegmentCount() - 1;
1132 
1133  int64_t clenPre = aPair->CoupledLength( currentPath, coupledPath );
1134  int64_t budget = clenPre / 10; // fixme: come up with somethig more intelligent here...
1135 
1136  while( n < n_segs - step )
1137  {
1138  const SEG s1 = currentPath.CSegment( n );
1139  const SEG s2 = currentPath.CSegment( n + step );
1140 
1141  DIRECTION_45 dir1( s1 );
1142  DIRECTION_45 dir2( s2 );
1143 
1144  if( dir1.IsObtuse( dir2 ) )
1145  {
1146  SHAPE_LINE_CHAIN bypass = DIRECTION_45().BuildInitialTrace( s1.A, s2.B, dir1.IsDiagonal() );
1147  SHAPE_LINE_CHAIN newRef;
1148  SHAPE_LINE_CHAIN newCoup;
1149  int64_t deltaCoupled = -1, deltaUni = -1;
1150 
1151  newRef = currentPath;
1152  newRef.Replace( s1.Index(), s2.Index(), bypass );
1153 
1154  deltaUni = aPair->CoupledLength ( newRef, coupledPath ) - clenPre + budget;
1155 
1156  if ( coupledBypass( m_world, aPair, aTryP, newRef, bypass, coupledPath, newCoup ) )
1157  {
1158  deltaCoupled = aPair->CoupledLength( newRef, newCoup ) - clenPre + budget;
1159 
1160  if( deltaCoupled >= 0 )
1161  {
1162  newRef.Simplify();
1163  newCoup.Simplify();
1164 
1165  aPair->SetShape( newRef, newCoup, !aTryP );
1166  return true;
1167  }
1168  }
1169  else if( deltaUni >= 0 && verifyDpBypass ( m_world, aPair, aTryP, newRef, coupledPath ) )
1170  {
1171  newRef.Simplify();
1172  coupledPath.Simplify();
1173 
1174  aPair->SetShape( newRef, coupledPath, !aTryP );
1175  return true;
1176  }
1177  }
1178 
1179  n++;
1180  }
1181 
1182  return false;
1183 }
1184 
1185 
1187 {
1188  int step_p = aPair->CP().SegmentCount() - 2;
1189  int step_n = aPair->CN().SegmentCount() - 2;
1190 
1191  while( 1 )
1192  {
1193  int n_segs_p = aPair->CP().SegmentCount();
1194  int n_segs_n = aPair->CN().SegmentCount();
1195 
1196  int max_step_p = n_segs_p - 2;
1197  int max_step_n = n_segs_n - 2;
1198 
1199  if( step_p > max_step_p )
1200  step_p = max_step_p;
1201 
1202  if( step_n > max_step_n )
1203  step_n = max_step_n;
1204 
1205  if( step_p < 1 && step_n < 1)
1206  break;
1207 
1208  bool found_anything_p = false;
1209  bool found_anything_n = false;
1210 
1211  if( step_p > 1 )
1212  found_anything_p = mergeDpStep( aPair, true, step_p );
1213 
1214  if( step_n > 1 )
1215  found_anything_n = mergeDpStep( aPair, false, step_n );
1216 
1217  if( !found_anything_n && !found_anything_p )
1218  {
1219  step_n--;
1220  step_p--;
1221  }
1222  }
1223  return true;
1224 }
1225 
1226 
1228 {
1229  return mergeDpSegments( aPair );
1230 }
1231 
1232 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
int Mask() const
Definition: direction45.h:316
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:310
bool m_restrictAreaActive
double CoupledLength() const
Class ITEM.
Definition: pns_item.h:53
RVERTEX(bool aRestricted, int aAllowedAngles)
void CacheStaticItem(ITEM *aItem)
Class SHAPE_SIMPLE.
Definition: shape_simple.h:42
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:150
Class NODE.
Definition: pns_node.h:136
void CacheRemove(ITEM *aItem)
void removeCachedSegments(LINE *aLine, int aStartVertex=0, int aEndVertex=-1)
const ENTRIES & CItems() const
Definition: pns_itemset.h:141
virtual int Layer() const
Function Layer()
Definition: pns_item.h:219
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:337
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:139
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Function IntersectLines()
Definition: seg.h:179
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:372
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:298
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:139
std::vector< RVERTEX > m_rs
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_simple.h:74
bool runSmartPads(LINE *aLine)
const Vec & GetSize() const
Definition: box2.h:177
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
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:61
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:132
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:200
int CountCorners(int aAngles) const
Returns the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:136
const SEG CSegment(int aIndex) const
Function CSegment()
Class JOINT.
Definition: pns_joint.h:43
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:294
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:36
int Gap() const
bool IsObtuse(const DIRECTION_45 &aOther) const
Function IsObtuse()
Definition: direction45.h:172
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:58
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:182
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:122
Definition: seg.h:36
OPTIMIZER(NODE *aWorld)
Optimizer.
Class DIFF_PAIR.
void cacheAdd(ITEM *aItem, bool aIsStatic)
bool operator()(ITEM *aOtherItem)
void Reverse()
Definition: seg.h:319
const SEG CSegment(int aIdx) const
Returns the aIdx-th segment of the line
Definition: pns_line.h:147
BREAKOUT_LIST customBreakouts(int aWidth, const ITEM *aItem, bool aPermitDiagonal) const
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
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:83
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:425
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:46
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:149
void Add(LINE &aLine)
VECTOR2I Offset() const
Definition: pns_solid.h:94
int Net() const
Function Net()
Definition: pns_item.h:179
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
OPT< OBSTACLE > OPT_OBSTACLE
Definition: pns_node.h:139
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:202
const LINKED_ITEMS & LinkList() const
Definition: pns_joint.h:190
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:253
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:45
Push and Shove diff pair dimensions (gap) settings dialog.
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:195
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:110
circle
Definition: shape.h:47
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:47