pcbnew: Really deal with missing segments this time

The OpenGL missing segments (when small) are due to rounding in larger
coordinates.  The GAL shader uses floats to represent int32 values for
position and distance.  Thus, at larger coordinates, the smaller integer
values cannot be represented accurately.  This tests for the rounding
error and, if it exists, draws a plain circle instead

Fixes https://gitlab.com/kicad/code/kicad/issues/5751
This commit is contained in:
Seth Hillbrand 2020-09-21 16:57:25 -07:00
parent ffa1947056
commit 76e44c2f4b
1 changed files with 9 additions and 3 deletions

View File

@ -654,9 +654,15 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP
VECTOR2D startEndVector = aEndPoint - aStartPoint;
double lineLength = startEndVector.EuclideanNorm();
// segments having a length <= 1 are just a circle.
// Moreover trying to draw them as a segment does not work fine.
if( lineLength <= 1 )
float startx = aStartPoint.x;
float starty = aStartPoint.y;
float endx = aStartPoint.x + lineLength;
float endy = aStartPoint.y + lineLength;
// Be careful about floating point rounding. As we draw segments in larger and larger coordinates,
// the shader (which uses floats) will lose precision and stop drawing small segments.
// In this case, we need to draw a circle for the minimal segment
if( startx == endx || starty == endy )
{
DrawCircle( aStartPoint, aWidth/2 );
return;