Clean some more tenths-of-degrees out of GerbView.

This commit is contained in:
Jeff Young 2022-01-18 02:14:09 +00:00
parent 180137baa4
commit 78385f7ab5
5 changed files with 55 additions and 53 deletions

View File

@ -117,7 +117,6 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
VECTOR2I curPos = aShapePos; VECTOR2I curPos = aShapePos;
D_CODE* tool = aParent->GetDcodeDescr(); D_CODE* tool = aParent->GetDcodeDescr();
double rotation;
switch( primitive_id ) switch( primitive_id )
{ {
@ -134,9 +133,9 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
// shape rotation (if any): // shape rotation (if any):
if( params.size() >= 5 ) if( params.size() >= 5 )
{ {
rotation = params[4].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[4].GetValue( tool ), DEGREES_T );
if( rotation != 0) if( !rotation.IsZero() )
{ {
for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) for( unsigned ii = 0; ii < polybuffer.size(); ii++ )
RotatePoint( polybuffer[ii], -rotation ); RotatePoint( polybuffer[ii], -rotation );
@ -170,9 +169,9 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
ConvertShapeToPolygon( aParent, polybuffer ); ConvertShapeToPolygon( aParent, polybuffer );
// shape rotation: // shape rotation:
rotation = params[6].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[6].GetValue( tool ), DEGREES_T );
if( rotation != 0) if( !rotation.IsZero() )
{ {
for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) for( unsigned ii = 0; ii < polybuffer.size(); ii++ )
RotatePoint( polybuffer[ii], -rotation ); RotatePoint( polybuffer[ii], -rotation );
@ -202,9 +201,9 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
ConvertShapeToPolygon( aParent, polybuffer ); ConvertShapeToPolygon( aParent, polybuffer );
// shape rotation: // shape rotation:
rotation = params[5].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[5].GetValue( tool ), DEGREES_T );
if( rotation != 0 ) if( !rotation.IsZero() )
{ {
for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) for( unsigned ii = 0; ii < polybuffer.size(); ii++ )
RotatePoint( polybuffer[ii], -rotation ); RotatePoint( polybuffer[ii], -rotation );
@ -231,8 +230,9 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
ConvertShapeToPolygon( aParent, polybuffer ); ConvertShapeToPolygon( aParent, polybuffer );
// shape rotation: // shape rotation:
rotation = params[5].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[5].GetValue( tool ), DEGREES_T );
if( rotation != 0)
if( !rotation.IsZero() )
{ {
for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) for( unsigned ii = 0; ii < polybuffer.size(); ii++ )
RotatePoint( polybuffer[ii], -rotation ); RotatePoint( polybuffer[ii], -rotation );
@ -264,14 +264,14 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
ConvertShapeToPolygon( aParent, subshape_poly ); ConvertShapeToPolygon( aParent, subshape_poly );
// shape rotation: // shape rotation:
rotation = params[5].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[5].GetValue( tool ), DEGREES_T );
// Because a thermal shape has 4 identical sub-shapes, only one is created in subshape_poly. // Because a thermal shape has 4 identical sub-shapes, only one is created in subshape_poly.
// We must draw 4 sub-shapes rotated by 90 deg // We must draw 4 sub-shapes rotated by 90 deg
for( int ii = 0; ii < 4; ii++ ) for( int ii = 0; ii < 4; ii++ )
{ {
polybuffer = subshape_poly; polybuffer = subshape_poly;
double sub_rotation = rotation + 900 * ii; EDA_ANGLE sub_rotation = rotation + ANGLE_90 * ii;
for( unsigned jj = 0; jj < polybuffer.size(); jj++ ) for( unsigned jj = 0; jj < polybuffer.size(); jj++ )
RotatePoint( polybuffer[jj], -sub_rotation ); RotatePoint( polybuffer[jj], -sub_rotation );
@ -337,7 +337,7 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
// Draw the cross: // Draw the cross:
ConvertShapeToPolygon( aParent, polybuffer ); ConvertShapeToPolygon( aParent, polybuffer );
rotation = params[8].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[8].GetValue( tool ), DEGREES_T );
for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) for( unsigned ii = 0; ii < polybuffer.size(); ii++ )
{ {
@ -376,7 +376,7 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
// the shape rotation is the last param of list, after corners // the shape rotation is the last param of list, after corners
int last_prm = params.size() - 1; int last_prm = params.size() - 1;
rotation = params[last_prm].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[last_prm].GetValue( tool ), DEGREES_T );
VECTOR2I pos; VECTOR2I pos;
// Read points. // Read points.
@ -418,6 +418,7 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
} }
case AMP_POLYGON: case AMP_POLYGON:
{
/* Polygon, Primitive Code 5 /* Polygon, Primitive Code 5
* A polygon primitive is a regular polygon defined by the number of vertices n, the * A polygon primitive is a regular polygon defined by the number of vertices n, the
* center point and the diameter of the circumscribed circle * center point and the diameter of the circumscribed circle
@ -433,7 +434,8 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
ConvertShapeToPolygon( aParent, polybuffer ); ConvertShapeToPolygon( aParent, polybuffer );
// rotate polygon and move it to the actual position // rotate polygon and move it to the actual position
rotation = params[5].GetValue( tool ) * 10.0; EDA_ANGLE rotation( params[5].GetValue( tool ), DEGREES_T );
for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) for( unsigned ii = 0; ii < polybuffer.size(); ii++ )
{ {
RotatePoint( polybuffer[ii], -rotation ); RotatePoint( polybuffer[ii], -rotation );
@ -444,6 +446,7 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_S
TO_POLY_SHAPE; TO_POLY_SHAPE;
break; break;
}
case AMP_EOF: case AMP_EOF:
// not yet supported, waiting for you. // not yet supported, waiting for you.
@ -478,12 +481,12 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
if( radius <= 0 ) if( radius <= 0 )
break; break;
VECTOR2I center = VECTOR2I center = mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ),
mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); m_GerbMetric );
VECTOR2I corner; VECTOR2I corner;
const int delta = 3600 / seg_per_circle; // rot angle in 0.1 degree EDA_ANGLE delta = ANGLE_360 / seg_per_circle; // rot angle in 0.1 degree
for( int angle = 0; angle < 3600; angle += delta ) for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
{ {
corner.x = radius; corner.x = radius;
corner.y = 0; corner.y = 0;
@ -582,16 +585,16 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
innerRadius = std::max( 1, innerRadius ); innerRadius = std::max( 1, innerRadius );
int halfthickness = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ) / 2; int halfthickness = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ) / 2;
double angle_start = RAD2DECIDEG( asin( (double) halfthickness / innerRadius ) ); EDA_ANGLE angle_start( asin( (double) halfthickness / innerRadius ), RADIANS_T );
// Draw shape in the first quadrant (X and Y > 0) // Draw shape in the first quadrant (X and Y > 0)
VECTOR2I pos, startpos; VECTOR2I pos, startpos;
// Inner arc // Inner arc
startpos.x = innerRadius; startpos.x = innerRadius;
double angle_end = 900 - angle_start; EDA_ANGLE angle_end = ANGLE_90 - angle_start;
for( double angle = angle_start; angle < angle_end; angle += 100 ) for( EDA_ANGLE angle = angle_start; angle < angle_end; angle += EDA_ANGLE( 10, DEGREES_T ) )
{ {
pos = startpos; pos = startpos;
RotatePoint( pos, angle ); RotatePoint( pos, angle );
@ -606,11 +609,11 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
// outer arc // outer arc
startpos.x = outerRadius; startpos.x = outerRadius;
startpos.y = 0; startpos.y = 0;
angle_start = RAD2DECIDEG( asin( (double) halfthickness / outerRadius ) ); angle_start = EDA_ANGLE( asin( (double) halfthickness / outerRadius ), RADIANS_T );
angle_end = 900 - angle_start; angle_end = ANGLE_90 - angle_start;
// First point, near Y axis, outer arc // First point, near Y axis, outer arc
for( double angle = angle_end; angle > angle_start; angle -= 100 ) for( EDA_ANGLE angle = angle_end; angle > angle_start; angle -= EDA_ANGLE( 10, DEGREES_T ) )
{ {
pos = startpos; pos = startpos;
RotatePoint( pos, angle ); RotatePoint( pos, angle );
@ -650,7 +653,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
for( int ii = 0; ii < 4; ii++ ) for( int ii = 0; ii < 4; ii++ )
{ {
pos = aBuffer[ii]; pos = aBuffer[ii];
RotatePoint( pos, jj*900 ); RotatePoint( pos, ANGLE_90 * jj );
aBuffer.push_back( pos ); aBuffer.push_back( pos );
} }
} }
@ -677,7 +680,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
for( int ii = 0; ii <= vertexcount; ii++ ) for( int ii = 0; ii <= vertexcount; ii++ )
{ {
VECTOR2I pos( radius, 0 ); VECTOR2I pos( radius, 0 );
RotatePoint( pos, ii * 3600 / vertexcount ); RotatePoint( pos, ANGLE_360 * ii / vertexcount );
aBuffer.push_back( pos ); aBuffer.push_back( pos );
} }

View File

@ -354,7 +354,7 @@ void D_CODE::ConvertShapeToPolygon()
for( ; ii <= SEGS_CNT / 2; ii++ ) for( ; ii <= SEGS_CNT / 2; ii++ )
{ {
currpos = initialpos; currpos = initialpos;
RotatePoint( currpos, ii * 3600.0 / SEGS_CNT ); RotatePoint( currpos, ANGLE_360 * ii / SEGS_CNT );
currpos.x += delta; currpos.x += delta;
m_Polygon.Append( VECTOR2I( currpos ) ); m_Polygon.Append( VECTOR2I( currpos ) );
} }
@ -363,12 +363,12 @@ void D_CODE::ConvertShapeToPolygon()
for( ii = SEGS_CNT / 2; ii <= SEGS_CNT; ii++ ) for( ii = SEGS_CNT / 2; ii <= SEGS_CNT; ii++ )
{ {
currpos = initialpos; currpos = initialpos;
RotatePoint( currpos, ii * 3600.0 / SEGS_CNT ); RotatePoint( currpos, ANGLE_360 * ii / SEGS_CNT );
currpos.x -= delta; currpos.x -= delta;
m_Polygon.Append( VECTOR2I( currpos ) ); m_Polygon.Append( currpos );
} }
m_Polygon.Append( VECTOR2I( initialpos ) ); // close outline m_Polygon.Append( initialpos ); // close outline
if( m_Size.y > m_Size.x ) // vertical oval, rotate polygon. if( m_Size.y > m_Size.x ) // vertical oval, rotate polygon.
m_Polygon.Rotate( -M_PI / 2 ); m_Polygon.Rotate( -M_PI / 2 );
@ -393,8 +393,8 @@ void D_CODE::ConvertShapeToPolygon()
for( int ii = 0; ii < m_EdgesCount; ii++ ) for( int ii = 0; ii < m_EdgesCount; ii++ )
{ {
currpos = initialpos; currpos = initialpos;
RotatePoint( currpos, ii * 3600.0 / m_EdgesCount ); RotatePoint( currpos, ANGLE_360 * ii / m_EdgesCount );
m_Polygon.Append( VECTOR2I( currpos ) ); m_Polygon.Append( currpos );
} }
addHoleToPolygon( &m_Polygon, m_DrillShape, m_Drill, initialpos ); addHoleToPolygon( &m_Polygon, m_DrillShape, m_Drill, initialpos );

View File

@ -367,7 +367,7 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( const GERBER_DRAW_ITEM* aGb
{ {
seg_start = curr_start; seg_start = curr_start;
VECTOR2I curr_end = start; VECTOR2I curr_end = start;
RotatePoint( curr_end, aGbrItem->m_ArcCentre, -RAD2DECIDEG( DELTA_ANGLE * ii ) ); RotatePoint( curr_end, aGbrItem->m_ArcCentre, -EDA_ANGLE( DELTA_ANGLE, RADIANS_T ) * ii );
seg_end = curr_end; seg_end = curr_end;
// Reverse Y axis: // Reverse Y axis:

View File

@ -143,9 +143,9 @@ VECTOR2I GERBER_DRAW_ITEM::GetABPosition( const VECTOR2I& aXYPosition ) const
abPos += m_layerOffset + m_GerberImageFile->m_ImageOffset; abPos += m_layerOffset + m_GerberImageFile->m_ImageOffset;
abPos.x = KiROUND( abPos.x * m_drawScale.x ); abPos.x = KiROUND( abPos.x * m_drawScale.x );
abPos.y = KiROUND( abPos.y * m_drawScale.y ); abPos.y = KiROUND( abPos.y * m_drawScale.y );
double rotation = m_lyrRotation * 10 + m_GerberImageFile->m_ImageRotation * 10; EDA_ANGLE rotation( m_lyrRotation + m_GerberImageFile->m_ImageRotation, DEGREES_T );
if( rotation ) if( !rotation.IsZero() )
RotatePoint( abPos, -rotation ); RotatePoint( abPos, -rotation );
// Negate A axis if mirrored // Negate A axis if mirrored
@ -171,9 +171,9 @@ VECTOR2I GERBER_DRAW_ITEM::GetXYPosition( const VECTOR2I& aABPosition ) const
if( !m_mirrorB ) if( !m_mirrorB )
xyPos.y = -xyPos.y; xyPos.y = -xyPos.y;
double rotation = m_lyrRotation * 10 + m_GerberImageFile->m_ImageRotation * 10; EDA_ANGLE rotation( m_lyrRotation + m_GerberImageFile->m_ImageRotation, DEGREES_T );
if( rotation ) if( !rotation.IsZero() )
RotatePoint( xyPos, rotation ); RotatePoint( xyPos, rotation );
xyPos.x = KiROUND( xyPos.x / m_drawScale.x ); xyPos.x = KiROUND( xyPos.x / m_drawScale.x );

View File

@ -349,12 +349,11 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, const VECTOR2I& aStart, con
VECTOR2I end = dummyGbrItem.m_End - center; VECTOR2I end = dummyGbrItem.m_End - center;
/* Calculate angle arc /* Calculate angle arc
* angles are in 0.1 deg
* angle is trigonometrical (counter-clockwise), * angle is trigonometrical (counter-clockwise),
* and axis is the X,Y gerber coordinates * and axis is the X,Y gerber coordinates
*/ */
double start_angle = ArcTangente( start.y, start.x ); EDA_ANGLE start_angle( start );
double end_angle = ArcTangente( end.y, end.x ); EDA_ANGLE end_angle( end );
// dummyTrack has right geometric parameters, but // dummyTrack has right geometric parameters, but
// fillArcGBRITEM calculates arc parameters for a draw function that expects // fillArcGBRITEM calculates arc parameters for a draw function that expects
@ -362,13 +361,13 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, const VECTOR2I& aStart, con
// Due to the fact atan2 returns angles between -180 to + 180 degrees, // Due to the fact atan2 returns angles between -180 to + 180 degrees,
// this is not always the case ( a modulo 360.0 degrees can be lost ) // this is not always the case ( a modulo 360.0 degrees can be lost )
if( start_angle > end_angle ) if( start_angle > end_angle )
end_angle += 3600; end_angle += ANGLE_360;
double arc_angle = start_angle - end_angle; EDA_ANGLE arc_angle = start_angle - end_angle;
// Approximate arc by 36 segments per 360 degree // Approximate arc by 36 segments per 360 degree
const int increment_angle = 3600 / 36; EDA_ANGLE increment_angle = ANGLE_360 / 36;
int count = std::abs( arc_angle / increment_angle ); int count = std::abs( arc_angle.AsDegrees() / increment_angle.AsDegrees() );
if( aGbrItem->m_Polygon.OutlineCount() == 0 ) if( aGbrItem->m_Polygon.OutlineCount() == 0 )
aGbrItem->m_Polygon.NewOutline(); aGbrItem->m_Polygon.NewOutline();
@ -378,13 +377,13 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, const VECTOR2I& aStart, con
// and we must always create a polygon from start to end. // and we must always create a polygon from start to end.
for( int ii = 0; ii <= count; ii++ ) for( int ii = 0; ii <= count; ii++ )
{ {
double rot; EDA_ANGLE rot;
VECTOR2I end_arc = start; VECTOR2I end_arc = start;
if( aClockwise ) if( aClockwise )
rot = ii * increment_angle; // rot is in 0.1 deg rot = increment_angle * ii;
else else
rot = ( count - ii ) * increment_angle; // rot is in 0.1 deg rot = increment_angle * ( count - ii );
if( ii < count ) if( ii < count )
RotatePoint( end_arc, -rot ); RotatePoint( end_arc, -rot );