KiCad PCB EDA Suite
DIRECTION_45 Class Reference

Class DIRECTION_45. More...

#include <direction45.h>

Public Types

enum  Directions {
  N = 0, NE = 1, E = 2, SE = 3,
  S = 4, SW = 5, W = 6, NW = 7,
  UNDEFINED = -1
}
 Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north = up) + an extra undefined direction, reserved for traces that don't respect 45-degree routing regime. More...
 
enum  AngleType {
  ANG_OBTUSE = 0x01, ANG_RIGHT = 0x02, ANG_ACUTE = 0x04, ANG_STRAIGHT = 0x08,
  ANG_HALF_FULL = 0x10, ANG_UNDEFINED = 0x20
}
 Enum AngleType Represents kind of angle formed by vectors heading in two DIRECTION_45s. More...
 

Public Member Functions

 DIRECTION_45 (Directions aDir=UNDEFINED)
 
 DIRECTION_45 (const VECTOR2I &aVec)
 Constructor. More...
 
 DIRECTION_45 (const SEG &aSeg)
 Constructor. More...
 
const std::string Format () const
 Function Format() Formats the direction in a human readable word. More...
 
DIRECTION_45 Opposite () const
 Function Opposite() Returns a direction opposite (180 degree) to (this) More...
 
AngleType Angle (const DIRECTION_45 &aOther) const
 Function Angle() Returns the type of angle between directions (this) and aOther. More...
 
bool IsObtuse (const DIRECTION_45 &aOther) const
 Function IsObtuse() More...
 
bool IsDiagonal () const
 Function IsDiagonal() Returns true if the direction is diagonal (e.g. More...
 
bool IsDefined () const
 
const SHAPE_LINE_CHAIN BuildInitialTrace (const VECTOR2I &aP0, const VECTOR2I &aP1, bool aStartDiagonal=false) const
 Function BuildInitialTrace() More...
 
bool operator== (const DIRECTION_45 &aOther) const
 
bool operator!= (const DIRECTION_45 &aOther) const
 
const DIRECTION_45 Right () const
 Function Right() More...
 
const DIRECTION_45 Left () const
 Function Left() More...
 
const VECTOR2I ToVector () const
 Function ToVector() More...
 
int Mask () const
 

Private Member Functions

void construct_ (const VECTOR2I &aVec)
 Function construct() Calculates the direction from a vector. More...
 

Private Attributes

Directions m_dir
 

our actual direction

More...
 

Detailed Description

Class DIRECTION_45.

Represents route directions & corner angles in a 45-degree metric.

Definition at line 36 of file direction45.h.

Member Enumeration Documentation

Enum AngleType Represents kind of angle formed by vectors heading in two DIRECTION_45s.

Enumerator
ANG_OBTUSE 
ANG_RIGHT 
ANG_ACUTE 
ANG_STRAIGHT 
ANG_HALF_FULL 
ANG_UNDEFINED 

Definition at line 62 of file direction45.h.

Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north = up) + an extra undefined direction, reserved for traces that don't respect 45-degree routing regime.

Enumerator
NE 
SE 
SW 
NW 
UNDEFINED 

Definition at line 45 of file direction45.h.

46  {
47  N = 0,
48  NE = 1,
49  E = 2,
50  SE = 3,
51  S = 4,
52  SW = 5,
53  W = 6,
54  NW = 7,
55  UNDEFINED = -1
56  };

Constructor & Destructor Documentation

DIRECTION_45::DIRECTION_45 ( Directions  aDir = UNDEFINED)
inline

Definition at line 72 of file direction45.h.

72 : m_dir( aDir ) {}
Directions m_dir
our actual direction
Definition: direction45.h:358
DIRECTION_45::DIRECTION_45 ( const VECTOR2I aVec)
inline

Constructor.

Parameters
aVecvector, whose direction will be translated into a DIRECTION_45.

Definition at line 78 of file direction45.h.

References construct_().

79  {
80  construct_( aVec );
81  }
void construct_(const VECTOR2I &aVec)
Function construct() Calculates the direction from a vector.
Definition: direction45.h:329
DIRECTION_45::DIRECTION_45 ( const SEG aSeg)
inline

Constructor.

Parameters
aSegsegment, whose direction will be translated into a DIRECTION_45.

Definition at line 87 of file direction45.h.

References SEG::A, SEG::B, and construct_().

88  {
89  construct_( aSeg.B - aSeg.A );
90  }
VECTOR2I A
Definition: seg.h:46
void construct_(const VECTOR2I &aVec)
Function construct() Calculates the direction from a vector.
Definition: direction45.h:329
VECTOR2I B
Definition: seg.h:47

Member Function Documentation

AngleType DIRECTION_45::Angle ( const DIRECTION_45 aOther) const
inline

Function Angle() Returns the type of angle between directions (this) and aOther.

Parameters
aOtherdirection to compare angle with

Definition at line 149 of file direction45.h.

References abs, ANG_ACUTE, ANG_HALF_FULL, ANG_OBTUSE, ANG_RIGHT, ANG_STRAIGHT, ANG_UNDEFINED, m_dir, and UNDEFINED.

Referenced by PNS::LINE_RESTRICTIONS::allowedAngles(), PNS::angle(), PNS::LINE::CountCorners(), IsObtuse(), PNS::LINE_PLACER::mergeHead(), and PNS::OPTIMIZER::smartPadsSingle().

150  {
151  if( m_dir == UNDEFINED || aOther.m_dir == UNDEFINED )
152  return ANG_UNDEFINED;
153 
154  int d = std::abs( m_dir - aOther.m_dir );
155 
156  if( d == 1 || d == 7 )
157  return ANG_OBTUSE;
158  else if( d == 2 || d == 6 )
159  return ANG_RIGHT;
160  else if( d == 3 || d == 5 )
161  return ANG_ACUTE;
162  else if( d == 4 )
163  return ANG_HALF_FULL;
164  else
165  return ANG_STRAIGHT;
166  }
#define abs(a)
Definition: auxiliary.h:84
Directions m_dir
our actual direction
Definition: direction45.h:358
const SHAPE_LINE_CHAIN DIRECTION_45::BuildInitialTrace ( const VECTOR2I aP0,
const VECTOR2I aP1,
bool  aStartDiagonal = false 
) const
inline

Function BuildInitialTrace()

Builds a 2-segment line chain between points aP0 and aP1 and following 45-degree routing regime. If aStartDiagonal is true, the trace starts with a diagonal segment.

Parameters
aP0starting point
aP1ending point
aStartDiagonalwhether the first segment has to be diagonal
Returns
the trace

Definition at line 202 of file direction45.h.

References abs, SHAPE_LINE_CHAIN::Append(), IsDiagonal(), m_dir, sign(), SHAPE_LINE_CHAIN::Simplify(), UNDEFINED, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PNS::DP_GATEWAYS::buildDpContinuation(), PNS::DP_GATEWAYS::buildEntries(), PNS::DIFF_PAIR::BuildInitial(), PNS::LINE_PLACER::buildInitialLine(), PNS::dragCornerInternal(), PNS::OPTIMIZER::fanoutCleanup(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeStep(), PNS::LINE_PLACER::reduceTail(), and PNS::OPTIMIZER::smartPadsSingle().

205  {
206  int w = abs( aP1.x - aP0.x );
207  int h = abs( aP1.y - aP0.y );
208  int sw = sign( aP1.x - aP0.x );
209  int sh = sign( aP1.y - aP0.y );
210 
211  VECTOR2I mp0, mp1;
212 
213  // we are more horizontal than vertical?
214  if( w > h )
215  {
216  mp0 = VECTOR2I( ( w - h ) * sw, 0 ); // direction: E
217  mp1 = VECTOR2I( h * sw, h * sh ); // direction: NE
218  }
219  else
220  {
221  mp0 = VECTOR2I( 0, sh * ( h - w ) ); // direction: N
222  mp1 = VECTOR2I( sw * w, sh * w ); // direction: NE
223  }
224 
225  bool start_diagonal;
226 
227  if( m_dir == UNDEFINED )
228  start_diagonal = aStartDiagonal;
229  else
230  start_diagonal = IsDiagonal();
231 
232  SHAPE_LINE_CHAIN pl;
233 
234  pl.Append( aP0 );
235 
236  if( start_diagonal )
237  pl.Append( aP0 + mp1 );
238  else
239  pl.Append( aP0 + mp0 );
240 
241  pl.Append( aP1 );
242  pl.Simplify();
243  return pl;
244  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
#define abs(a)
Definition: auxiliary.h:84
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
bool IsDiagonal() const
Function IsDiagonal() Returns true if the direction is diagonal (e.g.
Definition: direction45.h:182
Class SHAPE_LINE_CHAIN.
Directions m_dir
our actual direction
Definition: direction45.h:358
int sign(T val)
Definition: math_util.h:44
void DIRECTION_45::construct_ ( const VECTOR2I aVec)
inlineprivate

Function construct() Calculates the direction from a vector.

If the vector's angle is not a multiple of 45 degrees, the direction is rounded to the nearest octant.

Parameters
aVecour vector

Definition at line 329 of file direction45.h.

References m_dir, UNDEFINED, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DIRECTION_45().

330  {
331  m_dir = UNDEFINED;
332 
333  if( aVec.x == 0 && aVec.y == 0 )
334  return;
335 
336  double mag = 360.0 - ( 180.0 / M_PI * atan2( (double) aVec.y, (double) aVec.x ) ) + 90.0;
337 
338  if( mag >= 360.0 )
339  mag -= 360.0;
340 
341  if( mag < 0.0 )
342  mag += 360.0;
343 
344  int dir = ( mag + 22.5 ) / 45.0;
345 
346  if( dir >= 8 )
347  dir = dir - 8;
348 
349  if( dir < 0 )
350  dir = dir + 8;
351 
352  m_dir = (Directions) dir;
353 
354  return;
355  }
Directions m_dir
our actual direction
Definition: direction45.h:358
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:45
const std::string DIRECTION_45::Format ( ) const
inline

Function Format() Formats the direction in a human readable word.

Returns
name of the direction

Definition at line 97 of file direction45.h.

References E, m_dir, N, NE, NW, S, SE, SW, UNDEFINED, and W.

Referenced by PNS::LINE_PLACER::initPlacement(), PNS::LINE_PLACER::mergeHead(), and PNS::LINE_PLACER::routeStep().

98  {
99  switch( m_dir )
100  {
101  case N:
102  return "north";
103 
104  case NE:
105  return "north-east";
106 
107  case E:
108  return "east";
109 
110  case SE:
111  return "south-east";
112 
113  case S:
114  return "south";
115 
116  case SW:
117  return "south-west";
118 
119  case W:
120  return "west";
121 
122  case NW:
123  return "north-west";
124 
125  case UNDEFINED:
126  return "undefined";
127 
128  default:
129  return "<Error>";
130  }
131  }
Directions m_dir
our actual direction
Definition: direction45.h:358
bool DIRECTION_45::IsDefined ( ) const
inline

Definition at line 187 of file direction45.h.

References m_dir, and UNDEFINED.

188  {
189  return m_dir != UNDEFINED;
190  }
Directions m_dir
our actual direction
Definition: direction45.h:358
bool DIRECTION_45::IsDiagonal ( ) const
inline

Function IsDiagonal() Returns true if the direction is diagonal (e.g.

North-West, South-East, etc)

Returns
true, when diagonal.

Definition at line 182 of file direction45.h.

References m_dir.

Referenced by BuildInitialTrace(), and PNS::OPTIMIZER::mergeDpStep().

183  {
184  return ( m_dir % 2 ) == 1;
185  }
Directions m_dir
our actual direction
Definition: direction45.h:358
bool DIRECTION_45::IsObtuse ( const DIRECTION_45 aOther) const
inline

Function IsObtuse()

Returns
true, when (this) forms an obtuse angle with aOther

Definition at line 172 of file direction45.h.

References ANG_OBTUSE, and Angle().

Referenced by PNS::LINE_PLACER::checkObtusity(), PNS::LINE::dragSegment45(), and PNS::OPTIMIZER::mergeDpStep().

173  {
174  return Angle( aOther ) == ANG_OBTUSE;
175  }
AngleType Angle(const DIRECTION_45 &aOther) const
Function Angle() Returns the type of angle between directions (this) and aOther.
Definition: direction45.h:149
const DIRECTION_45 DIRECTION_45::Left ( ) const
inline

Function Left()

Returns the direction on the left side of this (i.e. turns left by 45 deg)

Definition at line 278 of file direction45.h.

References m_dir, N, NW, and UNDEFINED.

Referenced by PNS::DP_GATEWAYS::buildDpContinuation(), and PNS::LINE::dragSegment45().

279  {
280  DIRECTION_45 l;
281 
282  if ( m_dir == UNDEFINED )
283  return l;
284 
285  if( m_dir == N )
286  l.m_dir = NW;
287  else
288  l.m_dir = static_cast<Directions>( m_dir - 1 );
289 
290  return l;
291  }
Class DIRECTION_45.
Definition: direction45.h:36
Directions m_dir
our actual direction
Definition: direction45.h:358
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:45
int DIRECTION_45::Mask ( ) const
inline

Definition at line 316 of file direction45.h.

References m_dir.

Referenced by PNS::LINE_RESTRICTIONS::allowedAngles(), and PNS::LINE_RESTRICTIONS::Build().

317  {
318  return 1 << ( (int) m_dir );
319  }
Directions m_dir
our actual direction
Definition: direction45.h:358
bool DIRECTION_45::operator!= ( const DIRECTION_45 aOther) const
inline

Definition at line 251 of file direction45.h.

References m_dir.

252  {
253  return aOther.m_dir != m_dir;
254  }
Directions m_dir
our actual direction
Definition: direction45.h:358
bool DIRECTION_45::operator== ( const DIRECTION_45 aOther) const
inline

Definition at line 246 of file direction45.h.

References m_dir.

247  {
248  return aOther.m_dir == m_dir;
249  }
Directions m_dir
our actual direction
Definition: direction45.h:358
DIRECTION_45 DIRECTION_45::Opposite ( ) const
inline

Function Opposite() Returns a direction opposite (180 degree) to (this)

Returns
opposite direction

Definition at line 138 of file direction45.h.

References E, m_dir, N, NE, NW, S, SE, SW, UNDEFINED, and W.

139  {
140  const Directions OppositeMap[] = { S, SW, W, NW, N, NE, E, SE, UNDEFINED };
141  return OppositeMap[m_dir];
142  }
Directions m_dir
our actual direction
Definition: direction45.h:358
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:45
const DIRECTION_45 DIRECTION_45::Right ( ) const
inline

Function Right()

Returns the direction on the right side of this (i.e. turns right by 45 deg)

Definition at line 262 of file direction45.h.

References m_dir, and UNDEFINED.

Referenced by PNS::DP_GATEWAYS::buildDpContinuation(), PNS::LINE_PLACER::buildInitialLine(), PNS::LINE::dragSegment45(), PNS::LINE_PLACER::FlipPosture(), and PNS::LINE_PLACER::mergeHead().

263  {
264  DIRECTION_45 r;
265 
266  if ( m_dir != UNDEFINED )
267  r.m_dir = static_cast<Directions>( ( m_dir + 1 ) % 8 );
268 
269  return r;
270  }
Class DIRECTION_45.
Definition: direction45.h:36
Directions m_dir
our actual direction
Definition: direction45.h:358
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:45
const VECTOR2I DIRECTION_45::ToVector ( ) const
inline

Function ToVector()

Returns a unit vector corresponding to our direction.

Definition at line 298 of file direction45.h.

References E, m_dir, N, NE, NW, S, SE, SW, and W.

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::AddDirections(), PNS::ApproximateSegmentAsRect(), PNS::DP_GATEWAYS::buildDpContinuation(), and PNS::LINE::dragSegment45().

299  {
300  switch( m_dir )
301  {
302  case N: return VECTOR2I( 0, 1 );
303  case S: return VECTOR2I( 0, -1 );
304  case E: return VECTOR2I( 1, 0 );
305  case W: return VECTOR2I( -1, 0 );
306  case NE: return VECTOR2I( 1, 1 );
307  case NW: return VECTOR2I( -1, 1 );
308  case SE: return VECTOR2I( 1, -1 );
309  case SW: return VECTOR2I( -1, -1 );
310 
311  default:
312  return VECTOR2I( 0, 0 );
313  }
314  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
Directions m_dir
our actual direction
Definition: direction45.h:358

Member Data Documentation

Directions DIRECTION_45::m_dir
private

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