25 #include <geometry/seg.h> 26 #include <geometry/shape_line_chain.h> 86 construct_( aSeg.B - aSeg.A );
137 const Directions OppositeMap[] = { S, SW, W, NW, N, NE, E, SE, UNDEFINED };
138 return OppositeMap[m_dir];
148 if( m_dir == UNDEFINED || aOther.m_dir == UNDEFINED )
149 return ANG_UNDEFINED;
151 int d = std::abs( m_dir - aOther.m_dir );
153 if( d == 1 || d == 7 )
155 else if( d == 2 || d == 6 )
157 else if( d == 3 || d == 5 )
160 return ANG_HALF_FULL;
171 return Angle( aOther ) == ANG_OBTUSE;
181 return ( m_dir % 2 ) == 1;
184 bool IsDefined()
const 186 return m_dir != UNDEFINED;
201 bool aStartDiagonal =
false )
const 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 );
213 mp0 =
VECTOR2I( ( w - h ) * sw, 0 );
218 mp0 =
VECTOR2I( 0, sh * ( h - w ) );
224 if( m_dir == UNDEFINED )
225 start_diagonal = aStartDiagonal;
245 return aOther.m_dir == m_dir;
250 return aOther.m_dir != m_dir;
263 if ( m_dir != UNDEFINED )
264 r.m_dir =
static_cast<Directions>( ( m_dir + 1 ) % 8 );
279 if ( m_dir == UNDEFINED )
285 l.m_dir =
static_cast<Directions>( m_dir - 1 );
315 return 1 << ( (int) m_dir );
326 void construct_(
const VECTOR2I& aVec )
330 if( aVec.x == 0 && aVec.y == 0 )
333 double mag = 360.0 - ( 180.0 / M_PI * atan2( (
double) aVec.y, (
double) aVec.x ) ) + 90.0;
341 int dir = ( mag + 22.5 ) / 45.0;
358 #endif // DIRECTION45_H const std::string Format() const
Function Format() Formats the direction in a human readable word.
Definition: direction45.h:94
const VECTOR2I ToVector() const
Function ToVector()
Definition: direction45.h:295
const SHAPE_LINE_CHAIN BuildInitialTrace(const VECTOR2I &aP0, const VECTOR2I &aP1, bool aStartDiagonal=false) const
Function BuildInitialTrace()
Definition: direction45.h:199
const DIRECTION_45 Left() const
Function Left()
Definition: direction45.h:275
const DIRECTION_45 Right() const
Function Right()
Definition: direction45.h:259
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
Definition: shape_line_chain.h:330
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
Definition: shape_line_chain.cpp:417
AngleType Angle(const DIRECTION_45 &aOther) const
Function Angle() Returns the type of angle between directions (this) and aOther.
Definition: direction45.h:146
DIRECTION_45(const VECTOR2I &aVec)
Constructor.
Definition: direction45.h:75
Class DIRECTION_45.
Definition: direction45.h:33
DIRECTION_45 Opposite() const
Function Opposite() Returns a direction opposite (180 degree) to (this)
Definition: direction45.h:135
bool IsDiagonal() const
Function IsDiagonal() Returns true if the direction is diagonal (e.g.
Definition: direction45.h:179
DIRECTION_45(const SEG &aSeg)
Constructor.
Definition: direction45.h:84
AngleType
Enum AngleType Represents kind of angle formed by vectors heading in two DIRECTION_45s.
Definition: direction45.h:59
Class SHAPE_LINE_CHAIN.
Definition: shape_line_chain.h:47
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:42
bool IsObtuse(const DIRECTION_45 &aOther) const
Function IsObtuse()
Definition: direction45.h:169