Fix incorrect arc bounding box calculation.

add comments to SHAPE_ARC ctor.
This commit is contained in:
jean-pierre charras 2020-01-03 14:27:00 +01:00
parent 1bffe7f48b
commit baa1db031e
4 changed files with 41 additions and 7 deletions

View File

@ -155,9 +155,10 @@ const BOX2I SHAPE_ARC::BBox( int aClearance ) const
{
BOX2I bbox;
std::vector<VECTOR2I> 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();

View File

@ -34,6 +34,7 @@
#include <gerber_file_image.h>
#include <gerber_file_image_list.h>
#include <kicad_string.h>
#include <geometry/shape_arc.h>
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;
}

View File

@ -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;
}

View File

@ -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 ),