7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 11:21:41 +00:00

Some more EDA_ANGLE cleanup.

This commit is contained in:
Jeff Young 2022-01-16 16:15:07 +00:00
parent ef6ce972d6
commit e84c574830
41 changed files with 323 additions and 325 deletions

View File

@ -523,12 +523,14 @@ EDA_ANGLE EDA_SHAPE::GetArcAngle() const
}
void EDA_SHAPE::SetArcAngleAndEnd( double aAngle, bool aCheckNegativeAngle )
void EDA_SHAPE::SetArcAngleAndEnd( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle )
{
m_end = m_start;
RotatePoint( m_end, m_arcCenter, -NormalizeAngle360Max( aAngle ) );
EDA_ANGLE angle( aAngle );
if( aCheckNegativeAngle && aAngle < 0 )
m_end = m_start;
RotatePoint( m_end, m_arcCenter, -angle.Normalize720() );
if( aCheckNegativeAngle && aAngle < ANGLE_0 )
{
std::swap( m_start, m_end );
m_endsSwapped = true;

View File

@ -317,14 +317,17 @@ void CAIRO_GAL_BASE::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
}
void CAIRO_GAL_BASE::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle,
double aEndAngle )
void CAIRO_GAL_BASE::DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle )
{
syncLineWidth();
double startAngle = aStartAngle.AsRadians();
double endAngle = aEndAngle.AsRadians();
// calculate start and end arc angles according to the rotation transform matrix
// and normalize:
arc_angles_xform_and_normalize( aStartAngle, aEndAngle );
arc_angles_xform_and_normalize( startAngle, endAngle );
double r = xform( aRadius );
@ -342,7 +345,7 @@ void CAIRO_GAL_BASE::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, doub
if( m_isFillEnabled )
cairo_move_to( m_currentContext, mid.x, mid.y );
cairo_arc( m_currentContext, mid.x, mid.y, r, aStartAngle, aEndAngle );
cairo_arc( m_currentContext, mid.x, mid.y, r, startAngle, endAngle );
if( m_isFillEnabled )
cairo_close_path( m_currentContext );
@ -354,8 +357,8 @@ void CAIRO_GAL_BASE::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, doub
void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
double aStartAngle, double aEndAngle, double aWidth,
double aMaxError )
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle,
double aWidth, double aMaxError )
{
// Note: aMaxError is not used because Cairo can draw true arcs
if( m_isFillEnabled )
@ -373,8 +376,8 @@ void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadiu
// calculate start and end arc angles according to the rotation transform matrix
// and normalize:
double startAngleS = aStartAngle;
double endAngleS = aEndAngle;
double startAngleS = aStartAngle.AsRadians();
double endAngleS = aEndAngle.AsRadians();
arc_angles_xform_and_normalize( startAngleS, endAngleS );
double r = xform( aRadius );

View File

@ -803,14 +803,17 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
}
void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle,
double aEndAngle )
void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle )
{
if( aRadius <= 0 )
return;
double startAngle = aStartAngle.AsRadians();
double endAngle = aEndAngle.AsRadians();
// Swap the angles, if start angle is greater than end angle
SWAP( aStartAngle, >, aEndAngle );
SWAP( startAngle, >, endAngle );
const double alphaIncrement = calcAngleStep( aRadius );
@ -824,7 +827,7 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
m_currentManager->Shader( SHADER_NONE );
// Triangle fan
for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
for( alpha = startAngle; ( alpha + alphaIncrement ) < endAngle; )
{
m_currentManager->Reserve( 3 );
m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
@ -836,7 +839,7 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
}
// The last missing triangle
const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
const VECTOR2D endPoint( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
m_currentManager->Reserve( 3 );
m_currentManager->Vertex( 0.0, 0.0, m_layerDepth );
@ -849,10 +852,10 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
m_currentManager->Color( m_strokeColor.r, m_strokeColor.g, m_strokeColor.b,
m_strokeColor.a );
VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
VECTOR2D p( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
double alpha;
for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
{
VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
DrawLine( p, p_next );
@ -861,9 +864,9 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
}
// Draw the last missing part
if( alpha != aEndAngle )
if( alpha != endAngle )
{
VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
VECTOR2D p_last( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
DrawLine( p, p_last );
}
}
@ -873,7 +876,7 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
double aStartAngle, double aEndAngle,
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle,
double aWidth, double aMaxError )
{
if( aRadius <= 0 )
@ -885,8 +888,11 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
return;
}
double startAngle = aStartAngle.AsRadians();
double endAngle = aEndAngle.AsRadians();
// Swap the angles, if start angle is greater than end angle
SWAP( aStartAngle, >, aEndAngle );
SWAP( startAngle, >, endAngle );
// Calculate the seg count to approximate the arc with aMaxError or less
int segCount360 = GetArcToSegmentCount( aRadius, aMaxError, FULL_CIRCLE );
@ -896,14 +902,14 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
// Refinement: Use a segment count multiple of 2, because we have a control point
// on the middle of the arc, and the look is better if it is on a segment junction
// because there is no approx error
int seg_count = KiROUND( ( aEndAngle - aStartAngle ) / alphaIncrement );
int seg_count = KiROUND( ( endAngle - startAngle ) / alphaIncrement );
if( seg_count % 2 != 0 )
seg_count += 1;
// Recalculate alphaIncrement with a even integer number of segment
if( seg_count )
alphaIncrement = ( aEndAngle - aStartAngle ) / seg_count;
alphaIncrement = ( endAngle - startAngle ) / seg_count;
Save();
m_currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
@ -914,21 +920,21 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
m_strokeColor.a );
double width = aWidth / 2.0;
VECTOR2D startPoint( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
VECTOR2D startPoint( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
VECTOR2D endPoint( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
drawStrokedSemiCircle( endPoint, width, aEndAngle );
drawStrokedSemiCircle( startPoint, width, startAngle + M_PI );
drawStrokedSemiCircle( endPoint, width, endAngle );
VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
sin( aStartAngle ) * ( aRadius + width ) );
VECTOR2D pOuter( cos( startAngle ) * ( aRadius + width ),
sin( startAngle ) * ( aRadius + width ) );
VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
sin( aStartAngle ) * ( aRadius - width ) );
VECTOR2D pInner( cos( startAngle ) * ( aRadius - width ),
sin( startAngle ) * ( aRadius - width ) );
double alpha;
for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
{
VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
sin( alpha ) * ( aRadius + width ) );
@ -943,12 +949,12 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
}
// Draw the last missing part
if( alpha != aEndAngle )
if( alpha != endAngle )
{
VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
sin( aEndAngle ) * ( aRadius + width ) );
VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
sin( aEndAngle ) * ( aRadius - width ) );
VECTOR2D pLastOuter( cos( endAngle ) * ( aRadius + width ),
sin( endAngle ) * ( aRadius + width ) );
VECTOR2D pLastInner( cos( endAngle ) * ( aRadius - width ),
sin( endAngle ) * ( aRadius - width ) );
DrawLine( pOuter, pLastOuter );
DrawLine( pInner, pLastInner );
@ -960,10 +966,10 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
m_currentManager->Color( m_fillColor.r, m_fillColor.g, m_fillColor.b, m_fillColor.a );
SetLineWidth( aWidth );
VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
VECTOR2D p( cos( startAngle ) * aRadius, sin( startAngle ) * aRadius );
double alpha;
for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
for( alpha = startAngle + alphaIncrement; alpha <= endAngle; alpha += alphaIncrement )
{
VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
DrawLine( p, p_next );
@ -972,9 +978,9 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
}
// Draw the last missing part
if( alpha != aEndAngle )
if( alpha != endAngle )
{
VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
VECTOR2D p_last( cos( endAngle ) * aRadius, sin( endAngle ) * aRadius );
DrawLine( p, p_last );
}
}

View File

@ -124,38 +124,38 @@ void STROKE_PARAMS::Stroke( const SHAPE* aShape, PLOT_DASH_TYPE aLineStyle, int
{
const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( aShape );
double r = arc->GetRadius();
double C = 2.0 * M_PI * r;
VECTOR2I center = arc->GetCenter();
VECTOR2D startRadial( arc->GetP0() - center );
double startAngle = 180.0 / M_PI * atan2( startRadial.y, startRadial.x );
VECTOR2D endRadial( arc->GetP1() - center );
double arcEndAngle = 180.0 / M_PI * atan2( endRadial.y, endRadial.x );
double r = arc->GetRadius();
double C = 2.0 * M_PI * r;
VECTOR2I center = arc->GetCenter();
VECTOR2D startRadial( arc->GetP0() - center );
EDA_ANGLE startAngle( startRadial );
VECTOR2D endRadial( arc->GetP1() - center );
EDA_ANGLE arcEndAngle( endRadial );
if( arcEndAngle == startAngle )
arcEndAngle = startAngle + 360.0; // ring, not null
arcEndAngle = startAngle + ANGLE_360; // ring, not null
if( startAngle > arcEndAngle )
{
if( arcEndAngle < 0 )
arcEndAngle = NormalizeAngleDegrees( arcEndAngle, 0.0, 360.0 );
if( arcEndAngle < ANGLE_0 )
arcEndAngle = arcEndAngle.Normalize();
else
startAngle = NormalizeAngleDegrees( startAngle, -360.0, 0.0 );
startAngle = startAngle.Normalize() - ANGLE_360;
}
wxASSERT( startAngle < arcEndAngle );
for( size_t i = 0; i < 10000 && startAngle < arcEndAngle; ++i )
{
double theta = 360.0 * strokes[ i % wrapAround ] / C;
double endAngle = std::min( startAngle + theta, arcEndAngle );
EDA_ANGLE theta = ANGLE_360 * strokes[ i % wrapAround ] / C;
EDA_ANGLE endAngle = std::min( startAngle + theta, arcEndAngle );
if( i % 2 == 0 )
{
VECTOR2I a( center.x + r * cos( startAngle * M_PI / 180.0 ),
center.y + r * sin( startAngle * M_PI / 180.0 ) );
VECTOR2I b( center.x + r * cos( endAngle * M_PI / 180.0 ),
center.y + r * sin( endAngle * M_PI / 180.0 ) );
VECTOR2I a( center.x + r * cos( startAngle.AsRadians() ),
center.y + r * sin( startAngle.AsRadians() ) );
VECTOR2I b( center.x + r * cos( endAngle.AsRadians() ),
center.y + r * sin( endAngle.AsRadians() ) );
aStroker( a, b );
}

View File

@ -94,7 +94,8 @@ struct VIEW_OVERLAY::COMMAND_CIRCLE : public VIEW_OVERLAY::COMMAND
struct VIEW_OVERLAY::COMMAND_ARC : public VIEW_OVERLAY::COMMAND
{
COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, double aStartAngle, double aEndAngle ) :
COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, const EDA_ANGLE& aStartAngle,
const EDA_ANGLE& aEndAngle ) :
m_center( aCenter ),
m_radius( aRadius ),
m_startAngle( aStartAngle ),
@ -106,10 +107,10 @@ struct VIEW_OVERLAY::COMMAND_ARC : public VIEW_OVERLAY::COMMAND
aView->GetGAL()->DrawArc( m_center, m_radius, m_startAngle, m_endAngle );
}
VECTOR2D m_center;
double m_radius;
double m_startAngle;
double m_endAngle;
VECTOR2D m_center;
double m_radius;
EDA_ANGLE m_startAngle;
EDA_ANGLE m_endAngle;
};
@ -363,8 +364,8 @@ void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
}
void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle,
double aEndAngle )
void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
const EDA_ANGLE& aEndAngle )
{
m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
}

View File

@ -643,8 +643,8 @@ void SCH_PAINTER::draw( const LIB_SHAPE *aShape, int aLayer )
TRANSFORM().MapAngles( &startAngle, &endAngle );
m_gal->DrawArc( mapCoords( aShape->GetCenter() ), aShape->GetRadius(),
startAngle.AsRadians(), endAngle.AsRadians() );
m_gal->DrawArc( mapCoords( aShape->GetCenter() ), aShape->GetRadius(), startAngle,
endAngle );
}
break;
@ -1356,8 +1356,8 @@ void SCH_PAINTER::draw( const SCH_SHAPE* aShape, int aLayer )
EDA_ANGLE endAngle;
aShape->CalcArcAngles( startAngle, endAngle );
m_gal->DrawArc( aShape->GetCenter(), aShape->GetRadius(),
startAngle.AsRadians(), endAngle.AsRadians() );
m_gal->DrawArc( aShape->GetCenter(), aShape->GetRadius(), startAngle,
endAngle );
}
break;

View File

@ -1326,7 +1326,7 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map<wxString, wxString>& aPropertie
arc->SetCenter( elem.center + m_sheetOffset );
arc->SetStart( elem.center + startOffset + m_sheetOffset );
arc->SetArcAngleAndEnd( includedAngle.Normalize().AsTenthsOfADegree(), true );
arc->SetArcAngleAndEnd( includedAngle.Normalize(), true );
arc->SetStroke( STROKE_PARAMS( elem.lineWidth, PLOT_DASH_TYPE::SOLID ) );

View File

@ -83,8 +83,9 @@ bool TRANSFORM::MapAngles( EDA_ANGLE* aAngle1, EDA_ANGLE* aAngle2 ) const
static const EDA_ANGLE epsilon( 0.1, DEGREES_T );
double x, y, t;
bool swap = false;
double x, y;
VECTOR2D v;
bool swap = false;
EDA_ANGLE delta = *aAngle2 - *aAngle1;
@ -96,17 +97,13 @@ bool TRANSFORM::MapAngles( EDA_ANGLE* aAngle1, EDA_ANGLE* aAngle2 ) const
x = cos( aAngle1->AsRadians() );
y = sin( aAngle1->AsRadians() );
t = x * x1 + y * y1;
y = x * x2 + y * y2;
x = t;
*aAngle1 = EDA_ANGLE( VECTOR2I( x, y ) );
v = VECTOR2D( x * x1 + y * y1, x * x2 + y * y2 );
*aAngle1 = EDA_ANGLE( v );
x = cos( aAngle2->AsRadians() );
y = sin( aAngle2->AsRadians() );
t = x * x1 + y * y1;
y = x * x2 + y * y2;
x = t;
*aAngle2 = EDA_ANGLE( VECTOR2I( x, y ) );
v = VECTOR2D( x * x1 + y * y1, x * x2 + y * y2 );
*aAngle2 = EDA_ANGLE( v );
aAngle1->Normalize();
aAngle2->Normalize();
@ -116,9 +113,7 @@ bool TRANSFORM::MapAngles( EDA_ANGLE* aAngle1, EDA_ANGLE* aAngle2 ) const
if( *aAngle2 - *aAngle1 > ANGLE_180 ) // Need to swap the two angles
{
EDA_ANGLE temp = *aAngle1;
*aAngle1 = *aAngle2;
*aAngle2 = temp;
std::swap( *aAngle1, *aAngle2 );
aAngle1->Normalize();
aAngle2->Normalize();

View File

@ -519,7 +519,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
aBuffer.push_back( currpt );
// Rotate rectangle and move it to the actual start point
double angle = ArcTangente( delta.y, delta.x );
EDA_ANGLE angle( delta );
for( unsigned ii = 0; ii < 4; ii++ )
{

View File

@ -319,18 +319,18 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer )
m_gal->SetIsStroke( !isFilled );
m_gal->SetLineWidth( isFilled ? width : m_gerbviewSettings.m_outlineWidth );
double startAngle = startVec.Angle();
double endAngle = endVec.Angle();
EDA_ANGLE startAngle( startVec );
EDA_ANGLE endAngle( endVec );
// GAL fills in direction of increasing angle, so we have to convert
// the angle from the -PI to PI domain of atan2() to ensure that
// the arc goes in the right direction
if( startAngle > endAngle )
endAngle += (2 * M_PI);
endAngle += ANGLE_360;
// In Gerber, 360-degree arcs are stored in the file with start equal to end
if( arcStart == arcEnd )
endAngle = startAngle + 2*M_PI;
endAngle = startAngle + ANGLE_360;
m_gal->DrawArcSegment( center, radius, startAngle, endAngle, width, ARC_HIGH_DEF );

View File

@ -160,10 +160,8 @@ public:
/**
* Set the end point from the angle center and start.
*
* @param aAngle is tenths of degrees.
*/
void SetArcAngleAndEnd( double aAngle, bool aCheckNegativeAngle = false );
void SetArcAngleAndEnd( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle = false );
EDA_ANGLE GetArcAngle() const;

View File

@ -79,12 +79,12 @@ public:
/// @copydoc GAL::DrawArc()
void DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
double aStartAngle, double aEndAngle ) override;
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle ) override;
/// @copydoc GAL::DrawArcSegment()
/// Note: aMaxError is not used in Cairo, because Cairo can draw true arcs
void DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
double aStartAngle, double aEndAngle, double aWidth,
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle, double aWidth,
double aMaxError ) override;
/// @copydoc GAL::DrawRectangle()

View File

@ -40,6 +40,7 @@
#include <newstroke_font.h>
#include <font/stroke_font.h>
#include <eda_rect.h>
#include <geometry/eda_angle.h>
class SHAPE_LINE_CHAIN;
class SHAPE_POLY_SET;
@ -134,8 +135,8 @@ public:
* @param aStartAngle is the start angle of the arc.
* @param aEndAngle is the end angle of the arc.
*/
virtual void DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle,
double aEndAngle ) {};
virtual void DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle ) {};
/**
* Draw an arc segment.
@ -155,8 +156,9 @@ public:
* @param aMaxError is the max allowed error to create segments to approximate a circle.
* It has meaning only for back ends that can't draw a true arc, and use segments to approximate.
*/
virtual void DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle,
double aEndAngle, double aWidth, double aMaxError ) {};
virtual void DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle,
double aWidth, double aMaxError ) {};
/**
* Draw a rectangle.

View File

@ -126,13 +126,12 @@ public:
void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) override;
/// @copydoc GAL::DrawArc()
void DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
double aStartAngle, double aEndAngle ) override;
void DrawArc( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
const EDA_ANGLE& aEndAngle ) override;
/// @copydoc GAL::DrawArcSegment()
void DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
double aStartAngle, double aEndAngle, double aWidth,
double aMaxError ) override;
void DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
const EDA_ANGLE& aEndAngle, double aWidth, double aMaxError ) override;
/// @copydoc GAL::DrawRectangle()
void DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override;

View File

@ -80,7 +80,8 @@ public:
void Line( const SEG& aSeg );
void Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth );
void Circle( const VECTOR2D& aCenterPoint, double aRadius );
void Arc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle, double aEndAngle );
void Arc( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
const EDA_ANGLE& aEndAngle );
void Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint );
void Cross( const VECTOR2D& aP, int aSize );

View File

@ -53,7 +53,7 @@ public:
{
case RADIANS_T:
m_radians = aValue;
m_value = int( aValue / TENTHS_OF_A_DEGREE_TO_RADIANS );
m_value = KiROUND( aValue / TENTHS_OF_A_DEGREE_TO_RADIANS );
break;
default:
@ -70,7 +70,7 @@ public:
{
case RADIANS_T:
m_radians = aValue;
m_value = int( aValue / TENTHS_OF_A_DEGREE_TO_RADIANS );
m_value = KiROUND( aValue / TENTHS_OF_A_DEGREE_TO_RADIANS );
break;
default:
@ -78,6 +78,50 @@ public:
}
}
explicit EDA_ANGLE( const VECTOR2D& aVector ) :
m_value( 0 ),
m_radians( 0.0 ),
m_initial_type( TENTHS_OF_A_DEGREE_T )
{
if( aVector.x == 0.0 && aVector.y == 0.0 )
{
m_value = 0;
}
else if( aVector.y == 0.0 )
{
if( aVector.x >= 0 )
m_value = 0;
else
m_value = -1800;
}
else if( aVector.x == 0.0 )
{
if( aVector.y >= 0.0 )
m_value = 900;
else
m_value = -900;
}
else if( aVector.x == aVector.y )
{
if( aVector.x >= 0.0 )
m_value = 450;
else
m_value = -1800 + 450;
}
else if( aVector.x == -aVector.y )
{
if( aVector.x >= 0.0 )
m_value = -450;
else
m_value = 1800 - 450;
}
else
{
m_value = KiROUND( atan2( (double) aVector.y, (double) aVector.x )
/ TENTHS_OF_A_DEGREE_TO_RADIANS );
}
}
explicit EDA_ANGLE( const VECTOR2I& aVector ) :
m_value( 0 ),
m_radians( 0.0 ),
@ -119,8 +163,8 @@ public:
}
else
{
m_value = atan2( (double) aVector.y, (double) aVector.x )
/ TENTHS_OF_A_DEGREE_TO_RADIANS;
m_value = KiROUND( atan2( (double) aVector.y, (double) aVector.x )
/ TENTHS_OF_A_DEGREE_TO_RADIANS );
}
}

View File

@ -246,33 +246,6 @@ inline double RAD2DECIDEG( double rad ) { return rad * 1800.0 / M_PI; }
/* These are templated over T (and not simply double) because Eeschema
is still using int for angles in some place */
/// Normalize angle to be >=-360.0 and <= 360.0
/// Angle can be equal to -360 or +360
template <class T> inline T NormalizeAngle360Max( T Angle )
{
while( Angle < -3600 )
Angle += 3600;
while( Angle > 3600 )
Angle -= 3600;
return Angle;
}
/// Normalize angle to be in the 0.0 .. -360.0 range: angle is in 1/10 degrees.
template <class T>
inline T NormalizeAngleNeg( T Angle )
{
while( Angle <= -3600 )
Angle += 3600;
while( Angle > 0 )
Angle -= 3600;
return Angle;
}
/// Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
template <class T> inline T NormalizeAnglePos( T Angle )
{
@ -289,18 +262,6 @@ template <class T> inline void NORMALIZE_ANGLE_POS( T& Angle )
}
/// Normalize angle to be aMin < angle <= aMax angle is in degrees.
inline double NormalizeAngleDegrees( double Angle, double aMin, double aMax )
{
while( Angle < aMin )
Angle += 360.0;
while( Angle >= aMax )
Angle -= 360.0;
return Angle;
}
/// Normalize angle to be in the -180.0 .. 180.0 range
template <class T> inline T NormalizeAngle180( T Angle )
{

View File

@ -208,14 +208,18 @@ SHAPE_ARC& SHAPE_ARC::ConstructFromStartEndCenter( const VECTOR2I& aStart, const
VECTOR2I startLine = aStart - aCenter;
VECTOR2I endLine = aEnd - aCenter;
double startangle = NormalizeAnglePos(RAD2DECIDEG( startLine.Angle() ));
double endangle = NormalizeAnglePos(RAD2DECIDEG( endLine.Angle() ));
double angle = endangle - startangle;
EDA_ANGLE startAngle( startLine );
EDA_ANGLE endAngle( endLine );
startAngle.Normalize();
endAngle.Normalize();
EDA_ANGLE angle = endAngle - startAngle;
if( aClockwise )
angle = NormalizeAngleNeg( angle );
angle = angle.Normalize() - ANGLE_360;
else
angle = NormalizeAnglePos( angle );
angle = angle.Normalize();
m_start = aStart;
m_end = aEnd;

View File

@ -166,15 +166,15 @@ const VECTOR2I CalcArcMid( const VECTOR2I& aStart, const VECTOR2I& aEnd, const V
VECTOR2I startVector = aStart - aCenter;
VECTOR2I endVector = aEnd - aCenter;
double startAngle = ArcTangente( startVector.y, startVector.x );
double endAngle = ArcTangente( endVector.y, endVector.x );
double midPointRotAngleDeciDeg = NormalizeAngle180( startAngle - endAngle ) / 2;
EDA_ANGLE startAngle( startVector );
EDA_ANGLE endAngle( endVector );
EDA_ANGLE midPointRotAngle = ( startAngle - endAngle ).Normalize180() / 2;
if( !aMinArcAngle )
midPointRotAngleDeciDeg += 1800.0;
midPointRotAngle += ANGLE_180;
VECTOR2I newMid = aStart;
RotatePoint( newMid, aCenter, midPointRotAngleDeciDeg );
RotatePoint( newMid, aCenter, midPointRotAngle );
return newMid;
}

View File

@ -190,26 +190,26 @@ bool DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow()
switch( m_shape->GetShape() )
{
case SHAPE_T::SEGMENT:
m_shape->SetStart( wxPoint( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetEnd( wxPoint( m_endX.GetValue(), m_endY.GetValue() ) );
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetEnd( VECTOR2I( m_endX.GetValue(), m_endY.GetValue() ) );
break;
case SHAPE_T::BEZIER:
m_shape->SetStart( wxPoint( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetEnd( wxPoint( m_endX.GetValue(), m_endY.GetValue() ) );
m_shape->SetBezierC1( wxPoint( m_ctrl1X.GetValue(), m_ctrl1Y.GetValue()));
m_shape->SetBezierC1( wxPoint( m_ctrl2X.GetValue(), m_ctrl2Y.GetValue()));
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetEnd( VECTOR2I( m_endX.GetValue(), m_endY.GetValue() ) );
m_shape->SetBezierC1( VECTOR2I( m_ctrl1X.GetValue(), m_ctrl1Y.GetValue()));
m_shape->SetBezierC1( VECTOR2I( m_ctrl2X.GetValue(), m_ctrl2Y.GetValue()));
break;
case SHAPE_T::ARC:
m_shape->SetCenter( wxPoint( m_endX.GetValue(), m_endY.GetValue() ) );
m_shape->SetStart( wxPoint( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetArcAngleAndEnd( m_radius.GetValue() );
m_shape->SetCenter( VECTOR2I( m_endX.GetValue(), m_endY.GetValue() ) );
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetArcAngleAndEnd( m_radius.GetAngleValue() );
break;
case SHAPE_T::CIRCLE:
m_shape->SetStart( wxPoint( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetEnd( m_shape->GetStart() + wxPoint( m_radius.GetValue(), 0 ) );
m_shape->SetStart( VECTOR2I( m_startX.GetValue(), m_startY.GetValue() ) );
m_shape->SetEnd( m_shape->GetStart() + VECTOR2I( m_radius.GetValue(), 0 ) );
break;
case SHAPE_T::POLY:

View File

@ -184,12 +184,14 @@ VECTOR2I FP_SHAPE::GetArcMid0() const
}
void FP_SHAPE::SetArcAngleAndEnd0( double aAngle, bool aCheckNegativeAngle )
void FP_SHAPE::SetArcAngleAndEnd0( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle )
{
m_end0 = m_start0;
RotatePoint( m_end0, m_arcCenter0, -NormalizeAngle360Max( aAngle ) );
EDA_ANGLE angle( aAngle );
if( aCheckNegativeAngle && aAngle < 0 )
m_end0 = m_start0;
RotatePoint( m_end0, m_arcCenter0, -angle.Normalize720() );
if( aCheckNegativeAngle && aAngle < ANGLE_0 )
std::swap( m_start0, m_end0 );
}

View File

@ -69,7 +69,7 @@ public:
* Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
* @param aAngle is tenths of degrees, but will soon be degrees.
*/
void SetArcAngleAndEnd0( double aAngle, bool aCheckNegativeAngle = false );
void SetArcAngleAndEnd0( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle = false );
void SetArcGeometry0( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd );

View File

@ -269,8 +269,8 @@ public:
void AddPrimitiveCircle( const VECTOR2I& aCenter, int aRadius, int aThickness, bool aFilled );
void AddPrimitiveRect( const VECTOR2I& aStart, const VECTOR2I& aEnd, int aThickness,
bool aFilled );
void AddPrimitiveArc( const VECTOR2I& aCenter, const VECTOR2I& aStart, int aArcAngle,
int aThickness );
void AddPrimitiveArc( const VECTOR2I& aCenter, const VECTOR2I& aStart,
const EDA_ANGLE& aArcAngle, int aThickness );
void AddPrimitiveCurve( const VECTOR2I& aStart, const VECTOR2I& aEnd, const VECTOR2I& aCtrl1,
const VECTOR2I& aCtrl2, int aThickness );

View File

@ -80,8 +80,8 @@ void PAD::AddPrimitiveSegment( const VECTOR2I& aStart, const VECTOR2I& aEnd, int
}
void PAD::AddPrimitiveArc( const VECTOR2I& aCenter, const VECTOR2I& aStart, int aArcAngle,
int aThickness )
void PAD::AddPrimitiveArc( const VECTOR2I& aCenter, const VECTOR2I& aStart,
const EDA_ANGLE& aArcAngle, int aThickness )
{
PCB_SHAPE* item = new PCB_SHAPE( nullptr, SHAPE_T::ARC );
item->SetFilled( false );

View File

@ -670,8 +670,8 @@ void PCB_PAINTER::draw( const PCB_ARC* aArc, int aLayer )
m_gal->SetIsFill( not outline_mode );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->DrawArcSegment( center, radius, start_angle.AsRadians(),
( start_angle + angle ).AsRadians(), width, m_maxError );
m_gal->DrawArcSegment( center, radius, start_angle, start_angle + angle, width,
m_maxError );
}
// Clearance lines
@ -686,9 +686,8 @@ void PCB_PAINTER::draw( const PCB_ARC* aArc, int aLayer )
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->DrawArcSegment( center, radius, start_angle.AsRadians(),
( start_angle + angle ).AsRadians(), width + clearance * 2,
m_maxError );
m_gal->DrawArcSegment( center, radius, start_angle, start_angle + angle,
width + clearance * 2, m_maxError );
}
// Debug only: enable this code only to test the TransformArcToPolygon function
@ -829,22 +828,22 @@ void PCB_PAINTER::draw( const PCB_VIA* aVia, int aLayer )
if( !outline_mode )
m_gal->SetLineWidth( ( aVia->GetWidth() - aVia->GetDrillValue() ) / 2.0 );
m_gal->DrawArc( center, radius, M_PI * -0.375, M_PI * 0.375 );
m_gal->DrawArc( center, radius, M_PI * 0.625, M_PI * 1.375 );
m_gal->DrawArc( center, radius, EDA_ANGLE( -60, DEGREES_T ), EDA_ANGLE( 60, DEGREES_T ) );
m_gal->DrawArc( center, radius, EDA_ANGLE( 120, DEGREES_T ), EDA_ANGLE( 240, DEGREES_T ) );
if( outline_mode )
m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, layerTop ) );
else
m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerTop ) );
m_gal->DrawArc( center, radius, M_PI * 1.375, M_PI * 1.625 );
m_gal->DrawArc( center, radius, EDA_ANGLE( 240, DEGREES_T ), EDA_ANGLE( 300, DEGREES_T ) );
if( outline_mode )
m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
else
m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
m_gal->DrawArc( center, radius, M_PI * 0.375, M_PI * 0.625 );
m_gal->DrawArc( center, radius, EDA_ANGLE( 60, DEGREES_T ), EDA_ANGLE( 120, DEGREES_T ) );
}
// Clearance lines
@ -1407,18 +1406,16 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
if( outline_mode )
{
m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(),
startAngle.AsRadians(), endAngle.AsRadians(), thickness,
m_maxError );
m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
endAngle, thickness, m_maxError );
}
else
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(),
startAngle.AsRadians(), endAngle.AsRadians(), thickness,
m_maxError );
m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
endAngle, thickness, m_maxError );
}
break;
}

Some files were not shown because too many files have changed in this diff Show More