Commit 63e4defd authored by Maciej Suminski's avatar Maciej Suminski

Corrected bounding box for arcs (DRAWSEGMENT).

parent 25dfbcd3
...@@ -134,7 +134,7 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const ...@@ -134,7 +134,7 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const
return endPoint; // after rotation, the end of the arc. return endPoint; // after rotation, the end of the arc.
} }
const double DRAWSEGMENT::GetArcAngleStart() const double DRAWSEGMENT::GetArcAngleStart() const
{ {
// due to the Y axis orient atan2 needs - y value // due to the Y axis orient atan2 needs - y value
double angleStart = ArcTangente( GetArcStart().y - GetCenter().y, double angleStart = ArcTangente( GetArcStart().y - GetCenter().y,
...@@ -148,6 +148,7 @@ const double DRAWSEGMENT::GetArcAngleStart() const ...@@ -148,6 +148,7 @@ const double DRAWSEGMENT::GetArcAngleStart() const
return angleStart; return angleStart;
} }
void DRAWSEGMENT::SetAngle( double aAngle ) void DRAWSEGMENT::SetAngle( double aAngle )
{ {
NORMALIZE_ANGLE_360( aAngle ); NORMALIZE_ANGLE_360( aAngle );
...@@ -379,6 +380,59 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const ...@@ -379,6 +380,59 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const
wxPoint end = m_End; wxPoint end = m_End;
RotatePoint( &end, m_Start, -m_Angle ); RotatePoint( &end, m_Start, -m_Angle );
bbox.Merge( end ); bbox.Merge( end );
// Determine the starting quarter
// 0 right-bottom
// 1 left-bottom
// 2 left-top
// 3 right-top
unsigned int quarter = 0; // assume right-bottom
if( m_End.y < m_Start.y ) // change to left-top
quarter |= 3;
if( m_End.x < m_Start.x ) // for left side, the LSB is 2nd bit negated
quarter ^= 1;
int radius = GetRadius();
int angle = (int) GetArcAngleStart() % 900 + m_Angle;
bool directionCW = ( m_Angle > 0 ); // Is the direction of arc clockwise?
if( !directionCW )
{
angle = 900 - angle;
quarter = ( quarter + 3 ) % 4; // -1 modulo arithmetic
}
while( angle > 900 )
{
switch( quarter )
{
case 0:
bbox.Merge( wxPoint( m_Start.x, m_Start.y + radius ) ); // down
break;
case 1:
bbox.Merge( wxPoint( m_Start.x - radius, m_Start.y ) ); // left
break;
case 2:
bbox.Merge( wxPoint( m_Start.x, m_Start.y - radius ) ); // up
break;
case 3:
bbox.Merge( wxPoint( m_Start.x + radius, m_Start.y ) ); // right
break;
}
if( directionCW )
++quarter;
else
quarter += 3; // -1 modulo arithmetic
quarter %= 4;
angle -= 900;
}
} }
break; break;
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#ifndef CLASS_DRAWSEGMENT_H_ #ifndef CLASS_DRAWSEGMENT_H_
#define CLASS_DRAWSEGMENT_H_ #define CLASS_DRAWSEGMENT_H_
#include <class_board_item.h> #include <class_board_item.h>
#include <PolyLine.h> #include <PolyLine.h>
#include <math_for_graphics.h> #include <math_for_graphics.h>
...@@ -126,9 +125,9 @@ public: ...@@ -126,9 +125,9 @@ public:
/** /**
* function GetArcAngleStart() * function GetArcAngleStart()
* @return the angle of the stating point of this arc, between 0 and 3600 in 0.1 deg * @return the angle of the starting point of this arc, between 0 and 3600 in 0.1 deg
*/ */
const double GetArcAngleStart() const; double GetArcAngleStart() const;
/** /**
* Function GetRadius * Function GetRadius
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment