25 #include <geometry/seg.h>
26 #include <geometry/shape_line_chain.h>
89 construct_( aSeg.B - aSeg.A );
140 const Directions OppositeMap[] = { S, SW, W, NW, N, NE, E, SE, UNDEFINED };
141 return OppositeMap[m_dir];
151 if( m_dir == UNDEFINED || aOther.m_dir == UNDEFINED )
152 return ANG_UNDEFINED;
154 int d = std::abs( m_dir - aOther.m_dir );
156 if( d == 1 || d == 7 )
158 else if( d == 2 || d == 6 )
160 else if( d == 3 || d == 5 )
163 return ANG_HALF_FULL;
174 return Angle( aOther ) == ANG_OBTUSE;
184 return ( m_dir % 2 ) == 1;
187 bool IsDefined()
const
189 return m_dir != UNDEFINED;
204 bool aStartDiagonal =
false )
const
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 );
216 mp0 =
VECTOR2I( ( w - h ) * sw, 0 );
221 mp0 =
VECTOR2I( 0, sh * ( h - w ) );
227 if( m_dir == UNDEFINED )
228 start_diagonal = aStartDiagonal;
248 return aOther.m_dir == m_dir;
253 return aOther.m_dir != m_dir;
266 if ( m_dir != UNDEFINED )
267 r.m_dir =
static_cast<Directions>( ( m_dir + 1 ) % 8 );
282 if ( m_dir == UNDEFINED )
288 l.m_dir =
static_cast<Directions>( m_dir - 1 );
318 return 1 << ( (int) m_dir );
329 void construct_(
const VECTOR2I& aVec )
333 if( aVec.x == 0 && aVec.y == 0 )
336 double mag = 360.0 - ( 180.0 / M_PI * atan2( (
double) aVec.y, (
double) aVec.x ) ) + 90.0;
344 int dir = ( mag + 22.5 ) / 45.0;
361 #endif // DIRECTION45_H
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
Definition: shape_line_chain.h:383
bool IsObtuse(const DIRECTION_45 &aOther) const
Function IsObtuse()
Definition: direction45.h:172
const SHAPE_LINE_CHAIN BuildInitialTrace(const VECTOR2I &aP0, const VECTOR2I &aP1, bool aStartDiagonal=false) const
Function BuildInitialTrace()
Definition: direction45.h:202
const DIRECTION_45 Left() const
Function Left()
Definition: direction45.h:278
DIRECTION_45 Opposite() const
Function Opposite() Returns a direction opposite (180 degree) to (this)
Definition: direction45.h:138
AngleType Angle(const DIRECTION_45 &aOther) const
Function Angle() Returns the type of angle between directions (this) and aOther.
Definition: direction45.h:149
const VECTOR2I ToVector() const
Function ToVector()
Definition: direction45.h:298
const std::string Format() const
Function Format() Formats the direction in a human readable word.
Definition: direction45.h:97
const DIRECTION_45 Right() const
Function Right()
Definition: direction45.h:262
bool IsDiagonal() const
Function IsDiagonal() Returns true if the direction is diagonal (e.g.
Definition: direction45.h:182
Class DIRECTION_45.
Definition: direction45.h:37
Class SHAPE_LINE_CHAIN.
Definition: shape_line_chain.h:50
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
Definition: shape_line_chain.cpp:483
DIRECTION_45(const VECTOR2I &aVec)
Constructor.
Definition: direction45.h:78
DIRECTION_45(const SEG &aSeg)
Constructor.
Definition: direction45.h:87
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:46
AngleType
Enum AngleType Represents kind of angle formed by vectors heading in two DIRECTION_45s.
Definition: direction45.h:63