From 2c10d5e3a0a4fb33fffe99f6ed12a52b8d007047 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 13 Sep 2023 17:54:57 +0200 Subject: [PATCH] Pcbnew: fix some issues with very small arcs (size a few internal units) these very small arcs do not allow to calculate a reliable center position, and therefore a reliable radius. So seeing them as a very small segment fix plotting/drawing issues. Fixes #15639 https://gitlab.com/kicad/code/kicad/-/issues/15639 --- .../3d_canvas/create_3Dgraphic_brd_items.cpp | 13 +++++++++++++ pcbnew/pcb_track.cpp | 10 ++++++++++ pcbnew/pcb_track.h | 8 ++++++++ pcbnew/plot_board_layers.cpp | 15 +++++++++++++-- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index 321bea7c73..e3853277a9 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -286,6 +286,19 @@ void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDs { const PCB_ARC* arc = static_cast( aTrack ); + if( arc->IsDegenerated() ) + { + // Draw this very small arc like a track segment (a PCB_TRACE_T) + PCB_TRACK track( arc->GetParent() ); + track.SetStart( arc->GetStart() ); + track.SetEnd( arc->GetEnd() ); + track.SetWidth( arc->GetWidth() ); + track.SetLayer( arc->GetLayer() ); + + createTrack( &track, aDstContainer ); + return; + } + VECTOR2D center( arc->GetCenter() ); EDA_ANGLE arc_angle = arc->GetAngle(); double radius = arc->GetRadius(); diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index ffc1eda0bf..fde52dce48 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -1171,6 +1171,16 @@ EDA_ANGLE PCB_ARC::GetArcAngleEnd() const return angleEnd.Normalize(); } +bool PCB_ARC::IsDegenerated( int aThreshold ) const +{ + // Too small arcs cannot be really handled: arc center (and arc radius) + // cannot be safely computed if the distance between mid and end points + // is too small (a few internal units) + + return ( GetMid() - GetStart() ).EuclideanNorm() < aThreshold + || ( GetMid() - GetEnd() ).EuclideanNorm() < aThreshold; +} + bool PCB_TRACK::cmp_tracks::operator() ( const PCB_TRACK* a, const PCB_TRACK* b ) const { diff --git a/pcbnew/pcb_track.h b/pcbnew/pcb_track.h index b74d0be008..06681433ff 100644 --- a/pcbnew/pcb_track.h +++ b/pcbnew/pcb_track.h @@ -352,6 +352,14 @@ public: EDA_ITEM* Clone() const override; + /** + * @return true if the arc is too small to allow a safe calculation + * of center position and arc angles i.e if distance between m_Mid and each arc end + * is only a few internal units. + * @param aThreshold is the minimal dist in internal units. Default id 5 IU + */ + bool IsDegenerated( int aThreshold = 5 ) const; + protected: virtual void swapData( BOARD_ITEM* aImage ) override; diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 894f5b90b6..725f46d542 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -645,8 +645,19 @@ void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask, { const PCB_ARC* arc = static_cast( track ); - aPlotter->ThickArc( arc->GetCenter(), arc->GetArcAngleStart(), arc->GetAngle(), - arc->GetRadius(), width, plotMode, &gbr_metadata ); + // Too small arcs cannot be really handled: arc center (and arc radius) + // cannot be safely computed + if( !arc->IsDegenerated( 10 /* in IU */ ) ) + { + aPlotter->ThickArc( arc->GetCenter(), arc->GetArcAngleStart(), arc->GetAngle(), + arc->GetRadius(), width, plotMode, &gbr_metadata ); + } + else + { + // Approximate this very small arc by a segment. + aPlotter->ThickSegment( track->GetStart(), track->GetEnd(), width, plotMode, + &gbr_metadata ); + } } else {