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 33 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 59 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 42 of file direction45.h.

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

Constructor & Destructor Documentation

DIRECTION_45::DIRECTION_45 ( Directions  aDir = UNDEFINED)
inline

Definition at line 69 of file direction45.h.

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

Constructor.

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

Definition at line 75 of file direction45.h.

References construct_().

76  {
77  construct_( aVec );
78  }
void construct_(const VECTOR2I &aVec)
Function construct() Calculates the direction from a vector.
Definition: direction45.h:326
DIRECTION_45::DIRECTION_45 ( const SEG aSeg)
inline

Constructor.

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

Definition at line 84 of file direction45.h.

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

85  {
86  construct_( aSeg.B - aSeg.A );
87  }
VECTOR2I A
Definition: seg.h:47
void construct_(const VECTOR2I &aVec)
Function construct() Calculates the direction from a vector.
Definition: direction45.h:326
VECTOR2I B
Definition: seg.h:48

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 146 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().

147  {
148  if( m_dir == UNDEFINED || aOther.m_dir == UNDEFINED )
149  return ANG_UNDEFINED;
150 
151  int d = std::abs( m_dir - aOther.m_dir );
152 
153  if( d == 1 || d == 7 )
154  return ANG_OBTUSE;
155  else if( d == 2 || d == 6 )
156  return ANG_RIGHT;
157  else if( d == 3 || d == 5 )
158  return ANG_ACUTE;
159  else if( d == 4 )
160  return ANG_HALF_FULL;
161  else
162  return ANG_STRAIGHT;
163  }
#define abs(a)
Definition: auxiliary.h:84
Directions m_dir
our actual direction
Definition: direction45.h:355
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 199 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().

202  {
203  int w = abs( aP1.x - aP0.x );
204  int h = abs( aP1.y - aP0.y );
205  int sw = sign( aP1.x - aP0.x );
206  int sh = sign( aP1.y - aP0.y );
207 
208  VECTOR2I mp0, mp1;
209 
210  // we are more horizontal than vertical?
211  if( w > h )
212  {
213  mp0 = VECTOR2I( ( w - h ) * sw, 0 ); // direction: E
214  mp1 = VECTOR2I( h * sw, h * sh ); // direction: NE
215  }
216  else
217  {
218  mp0 = VECTOR2I( 0, sh * ( h - w ) ); // direction: N
219  mp1 = VECTOR2I( sw * w, sh * w ); // direction: NE
220  }
221 
222  bool start_diagonal;
223 
224  if( m_dir == UNDEFINED )
225  start_diagonal = aStartDiagonal;
226  else
227  start_diagonal = IsDiagonal();
228 
229  SHAPE_LINE_CHAIN pl;
230 
231  pl.Append( aP0 );
232 
233  if( start_diagonal )
234  pl.Append( aP0 + mp1 );
235  else
236  pl.Append( aP0 + mp0 );
237 
238  pl.Append( aP1 );
239  pl.Simplify();
240  return pl;
241  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
#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:179
Class SHAPE_LINE_CHAIN.
Directions m_dir
our actual direction
Definition: direction45.h:355
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 326 of file direction45.h.

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

Referenced by DIRECTION_45().

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

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

Definition at line 184 of file direction45.h.

References m_dir, and UNDEFINED.

185  {
186  return m_dir != UNDEFINED;
187  }
Directions m_dir
our actual direction
Definition: direction45.h:355
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 179 of file direction45.h.

References m_dir.

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

180  {
181  return ( m_dir % 2 ) == 1;
182  }
Directions m_dir
our actual direction
Definition: direction45.h:355
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 169 of file direction45.h.

References ANG_OBTUSE, and Angle().

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

170  {
171  return Angle( aOther ) == ANG_OBTUSE;
172  }
AngleType Angle(const DIRECTION_45 &aOther) const
Function Angle() Returns the type of angle between directions (this) and aOther.
Definition: direction45.h:146
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 275 of file direction45.h.

References m_dir, N, NW, and UNDEFINED.

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

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

Definition at line 313 of file direction45.h.

References m_dir.

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

314  {
315  return 1 << ( (int) m_dir );
316  }
Directions m_dir
our actual direction
Definition: direction45.h:355
bool DIRECTION_45::operator!= ( const DIRECTION_45 aOther) const
inline

Definition at line 248 of file direction45.h.

References m_dir.

249  {
250  return aOther.m_dir != m_dir;
251  }
Directions m_dir
our actual direction
Definition: direction45.h:355
bool DIRECTION_45::operator== ( const DIRECTION_45 aOther) const
inline

Definition at line 243 of file direction45.h.

References m_dir.

244  {
245  return aOther.m_dir == m_dir;
246  }
Directions m_dir
our actual direction
Definition: direction45.h:355
DIRECTION_45 DIRECTION_45::Opposite ( ) const
inline

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

Returns
opposite direction

Definition at line 135 of file direction45.h.

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

136  {
137  const Directions OppositeMap[] = { S, SW, W, NW, N, NE, E, SE, UNDEFINED };
138  return OppositeMap[m_dir];
139  }
Directions m_dir
our actual direction
Definition: direction45.h:355
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:42
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 259 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().

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

Function ToVector()

Returns a unit vector corresponding to our direction.

Definition at line 295 of file direction45.h.

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

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

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

Member Data Documentation

Directions DIRECTION_45::m_dir
private

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