diff --git a/common/geometry/shape_arc.cpp b/common/geometry/shape_arc.cpp index aef384eb8d..3cf7cf281f 100644 --- a/common/geometry/shape_arc.cpp +++ b/common/geometry/shape_arc.cpp @@ -155,9 +155,10 @@ const BOX2I SHAPE_ARC::BBox( int aClearance ) const { BOX2I bbox; std::vector points; - points.push_back( m_pc ); + // Put start and end points in the point list points.push_back( m_p0 ); points.push_back( GetP1() ); +// points.push_back( m_pc ); the center point is not necessary in the BBox double start_angle = GetStartAngle(); double end_angle = start_angle + GetCentralAngle(); diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index c8ac97884d..6f31ae141f 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -34,6 +34,7 @@ #include #include #include +#include GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberImageFile ) : EDA_ITEM( (EDA_ITEM*)NULL, GERBER_DRAW_ITEM_T ) @@ -306,10 +307,23 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const case GBR_ARC: { - // Note: using a larger-than-necessary BB to simplify computation - double radius = GetLineLength( m_Start, m_ArcCentre ); - bbox.Move( m_ArcCentre - m_Start ); - bbox.Inflate( radius + m_Size.x, radius + m_Size.x ); + double arc_angle = + atan2( double( m_End.y - m_ArcCentre.y ), double( m_End.x - m_ArcCentre.x ) ) + - atan2( double( m_Start.y - m_ArcCentre.y ), double( m_Start.x - m_ArcCentre.x ) ); + + arc_angle *= 180.0 / M_PI; + + if( arc_angle < 0.0 ) + arc_angle += 360.0; + + if( m_End == m_Start ) // Arc with the end point = start point is expected to be a circle + arc_angle = 360.0; + + SHAPE_ARC arc( m_ArcCentre, m_Start, arc_angle ); + BOX2I arc_bbox = arc.BBox( m_Size.x / 2 ); // m_Size.x is the line thickness + bbox.SetOrigin( arc_bbox.GetX(), arc_bbox.GetY() ); + bbox.SetWidth( arc_bbox.GetWidth() ); + bbox.SetHeight( arc_bbox.GetHeight() ); break; } diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index ba00ca7398..4b95f64fb9 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -329,12 +329,24 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer ) m_gal->DrawArcSegment( center, radius, startAngle, endAngle, width ); #if 0 // Arc Debugging only + m_gal->SetIsFill( false ); + m_gal->SetIsStroke( true ); m_gal->SetLineWidth( 5 ); - m_gal->SetStrokeColor( COLOR4D( 0.0, 1.0, 0.0, 1.0 ) ); + m_gal->SetStrokeColor( COLOR4D( 0.1, 0.5, 0.0, 0.5 ) ); m_gal->DrawLine( center, aItem->GetABPosition( arcStart ) ); - m_gal->SetStrokeColor( COLOR4D( 1.0, 0.0, 0.0, 1.0 ) ); + m_gal->SetStrokeColor( COLOR4D( 0.6, 0.1, 0.0, 0.5 ) ); m_gal->DrawLine( center, aItem->GetABPosition( arcEnd ) ); #endif + +#if 0 // Bbox arc Debugging only + m_gal->SetIsFill( false ); + m_gal->SetIsStroke( true ); + EDA_RECT box = aItem->GetBoundingBox(); + m_gal->SetLineWidth( 5 ); + m_gal->SetStrokeColor( COLOR4D(0.9, 0.9, 0, 0.4) ); + // box coordinates are already in AB position. + m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() ); +#endif break; } diff --git a/include/geometry/shape_arc.h b/include/geometry/shape_arc.h index 99d32c7d70..1f23de170a 100644 --- a/include/geometry/shape_arc.h +++ b/include/geometry/shape_arc.h @@ -36,6 +36,13 @@ public: SHAPE_ARC() : SHAPE( SH_ARC ), m_centralAngle( 0.0 ), m_width( 0 ) {}; + /** + * SHAPE_ARC ctor. + * @param aArcCenter is the arc center + * @param aArcStartPoint is the arc start point + * @param aCenterAngle is the arc angle in degrees + * @param aWidth is the arc line thickness + */ SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint, double aCenterAngle, int aWidth = 0 ) : SHAPE( SH_ARC ), m_p0( aArcStartPoint ), m_pc( aArcCenter ), m_centralAngle( aCenterAngle ),