KiCad PCB EDA Suite
PNS::LINE_RESTRICTIONS Class Reference

Classes

struct  RVERTEX
 

Public Member Functions

 LINE_RESTRICTIONS ()
 
 ~LINE_RESTRICTIONS ()
 
void Build (NODE *aWorld, LINE *aOriginLine, const SHAPE_LINE_CHAIN &aLine, const BOX2I &aRestrictedArea, bool aRestrictedAreaEnable)
 
bool Check (int aVertex1, int aVertex2, const SHAPE_LINE_CHAIN &aReplacement)
 
void Dump ()
 

Private Member Functions

int allowedAngles (NODE *aWorld, const LINE *aLine, const VECTOR2I &aP, bool aFirst)
 

Private Attributes

std::vector< RVERTEXm_rs
 

Detailed Description

Definition at line 233 of file pns_optimizer.cpp.

Constructor & Destructor Documentation

PNS::LINE_RESTRICTIONS::LINE_RESTRICTIONS ( )
inline

Definition at line 236 of file pns_optimizer.cpp.

236 {};
PNS::LINE_RESTRICTIONS::~LINE_RESTRICTIONS ( )
inline

Definition at line 237 of file pns_optimizer.cpp.

237 {};

Member Function Documentation

int PNS::LINE_RESTRICTIONS::allowedAngles ( NODE aWorld,
const LINE aLine,
const VECTOR2I aP,
bool  aFirst 
)
private

Definition at line 263 of file pns_optimizer.cpp.

References SEG::A, DIRECTION_45::ANG_HALF_FULL, DIRECTION_45::ANG_OBTUSE, DIRECTION_45::ANG_STRAIGHT, DIRECTION_45::Angle(), PNS::ITEM_SET::CItems(), PNS::NODE::FindJoint(), PNS::JOINT::Links(), DIRECTION_45::Mask(), SEG::Reverse(), PNS::ITEM::SOLID_T, and PNS::ITEM::VIA_T.

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 }
VECTOR2I & A
Definition: seg.h:51
Class DIRECTION_45.
Definition: direction45.h:33
Definition: seg.h:37
void Reverse()
Definition: seg.h:352
Struct SEGMENT is a simple container used when filling areas with segments.
Definition: class_zone.h:57
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:42
void PNS::LINE_RESTRICTIONS::Build ( NODE aWorld,
LINE aOriginLine,
const SHAPE_LINE_CHAIN aLine,
const BOX2I aRestrictedArea,
bool  aRestrictedAreaEnable 
)

Definition at line 308 of file pns_optimizer.cpp.

References PNS::LINE_RESTRICTIONS::RVERTEX::allowedAngles, BOX2< Vec >::Contains(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::CSegment(), m_rs, DIRECTION_45::Mask(), SHAPE_LINE_CHAIN::PointCount(), and PNS::LINE_RESTRICTIONS::RVERTEX::restricted.

Referenced by PNS::OPTIMIZER::mergeStep().

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 }
int Mask() const
Definition: direction45.h:313
int PointCount() const
Function PointCount()
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:139
std::vector< RVERTEX > m_rs
const SEG CSegment(int aIndex) const
Function CSegment()
Class DIRECTION_45.
Definition: direction45.h:33
Definition: seg.h:37
Class SHAPE_LINE_CHAIN.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool PNS::LINE_RESTRICTIONS::Check ( int  aVertex1,
int  aVertex2,
const SHAPE_LINE_CHAIN aReplacement 
)

Definition at line 360 of file pns_optimizer.cpp.

References PNS::LINE_RESTRICTIONS::RVERTEX::allowedAngles, SHAPE_LINE_CHAIN::CSegment(), m_rs, and SHAPE_LINE_CHAIN::SegmentCount().

Referenced by PNS::OPTIMIZER::mergeStep().

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 }
std::vector< RVERTEX > m_rs
const SEG CSegment(int aIndex) const
Function CSegment()
Class DIRECTION_45.
Definition: direction45.h:33
int SegmentCount() const
Function SegmentCount()
void PNS::LINE_RESTRICTIONS::Dump ( )

Definition at line 355 of file pns_optimizer.cpp.

356 {
357 }

Member Data Documentation

std::vector<RVERTEX> PNS::LINE_RESTRICTIONS::m_rs
private

Definition at line 258 of file pns_optimizer.cpp.

Referenced by Build(), and Check().


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