26#include <geometry/seg.h>
27#include <geometry/shape_line_chain.h>
28#include <math/vector2d.h>
106 VECTOR2I vec( aSeg.B - aSeg.A );
119 VECTOR2I vec( aArc.GetP1() - aArc.GetP0() );
172 const Directions OppositeMap[] = { S, SW, W, NW, N, NE, E, SE, UNDEFINED };
173 return OppositeMap[m_dir];
183 if( m_dir == UNDEFINED || aOther.m_dir == UNDEFINED )
184 return ANG_UNDEFINED;
186 int d = std::abs( m_dir - aOther.m_dir );
188 if( d == 1 || d == 7 )
190 else if( d == 2 || d == 6 )
192 else if( d == 3 || d == 5 )
195 return ANG_HALF_FULL;
205 return Angle( aOther ) == ANG_OBTUSE;
215 return ( m_dir % 2 ) == 1;
218 bool IsDefined()
const
220 return m_dir != UNDEFINED;
234 const SHAPE_LINE_CHAIN
BuildInitialTrace(
const VECTOR2I& aP0,
const VECTOR2I& aP1,
235 bool aStartDiagonal =
false,
238 bool operator==(
const DIRECTION_45& aOther )
const
240 return aOther.m_dir == m_dir;
243 bool operator!=(
const DIRECTION_45& aOther )
const
245 return aOther.m_dir != m_dir;
255 if ( m_dir != UNDEFINED )
258 r.m_dir =
static_cast<Directions>( ( m_dir + 2 ) % LAST );
260 r.m_dir =
static_cast<Directions>( ( m_dir + 1 ) % LAST );
269 const DIRECTION_45
Left()
const
273 if ( m_dir != UNDEFINED )
276 l.m_dir =
static_cast<Directions>( ( m_dir + LAST - 2 ) % LAST );
278 l.m_dir =
static_cast<Directions>( ( m_dir + LAST - 1 ) % LAST );
291 case N:
return VECTOR2I( 0, -1 );
292 case S:
return VECTOR2I( 0, 1 );
293 case E:
return VECTOR2I( 1, 0 );
294 case W:
return VECTOR2I( -1, 0 );
295 case NE:
return VECTOR2I( 1, -1 );
296 case NW:
return VECTOR2I( -1, -1 );
297 case SE:
return VECTOR2I( 1, 1 );
298 case SW:
return VECTOR2I( -1, 1 );
301 return VECTOR2I( 0, 0 );
307 return 1 << ( (int) m_dir );
317 void construct_(
const VECTOR2I& aVec )
321 if( aVec.x == 0 && aVec.y == 0 )
324 double mag = 360.0 - ( 180.0 / M_PI * atan2( (
double) aVec.y, (
double) aVec.x ) ) + 90.0;
332 int dir = ( mag + 22.5 ) / 45.0;
Represent route directions & corner angles in a 45-degree metric.
Definition direction45.h:37
const SHAPE_LINE_CHAIN BuildInitialTrace(const VECTOR2I &aP0, const VECTOR2I &aP1, bool aStartDiagonal=false, CORNER_MODE aMode=CORNER_MODE::MITERED_45) const
Build a 2-segment line chain between points aP0 and aP1 and following 45-degree routing regime.
Definition direction_45.cpp:23
AngleType Angle(const DIRECTION_45 &aOther) const
Return the type of angle between directions (this) and aOther.
Definition direction45.h:181
const DIRECTION_45 Left() const
Return the direction on the left side of this (i.e.
Definition direction45.h:269
const VECTOR2I ToVector() const
Definition direction45.h:287
AngleType
Represent kind of angle formed by vectors heading in two DIRECTION_45s.
Definition direction45.h:78
Directions
Available directions, there are 8 of them, as on a rectilinear map (north = up) + an extra undefined ...
Definition direction45.h:49
DIRECTION_45(const SEG &aSeg, bool a90=false)
Definition direction45.h:103
bool IsDiagonal() const
Returns true if the direction is diagonal (e.g.
Definition direction45.h:213
CORNER_MODE
Corner modes.
Definition direction45.h:67
@ ROUNDED_90
H/V with filleted corners.
Definition direction45.h:71
@ MITERED_90
H/V only (90-degree corners).
Definition direction45.h:70
@ ROUNDED_45
H/V/45 with filleted corners.
Definition direction45.h:69
@ MITERED_45
H/V/45 with mitered corners (default).
Definition direction45.h:68
const DIRECTION_45 Right() const
Return the direction on the right side of this (i.e.
Definition direction45.h:251
DIRECTION_45(const SHAPE_ARC &aArc, bool a90=false)
Create a DIRECTION_45 from the endpoints of a given arc.
Definition direction45.h:116
const std::string Format() const
Format the direction in a human readable word.
Definition direction45.h:129
DIRECTION_45(const VECTOR2I &aVec, bool a90=false)
Definition direction45.h:92
bool IsObtuse(const DIRECTION_45 &aOther) const
Definition direction45.h:203
DIRECTION_45 Opposite() const
Return a direction opposite (180 degree) to (this).
Definition direction45.h:170
Definition shape_arc.h:36