From db0523626cbf9fdf012ac60079a4060ffb16c7db Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 2 Apr 2019 17:16:49 -0700 Subject: [PATCH] GAL: Deal with thick circles Both Cairo and OpenGL had issues (different, though) with circles that are thicker in line width than they have radius. This corrects the OpenGL implementation (radius is calculated to the outer edge) as well as Cairo (line width needs to be clamped to twice the radius) Fixes: lp:1822765 * https://bugs.launchpad.net/kicad/+bug/1822765 --- common/gal/cairo/cairo_gal.cpp | 1 + common/gal/opengl/gl_builtin_shaders.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 7913912fbd..bcec4cd34e 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -245,6 +245,7 @@ void CAIRO_GAL_BASE::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) auto c = roundp( xform( aCenterPoint ) ); auto r = ::roundp( xform( aRadius ) ); + cairo_set_line_width( currentContext, std::min( 2.0 * r, lineWidthInPixels ) ); cairo_new_sub_path( currentContext ); cairo_arc( currentContext, c.x, c.y, r, 0.0, 2 * M_PI ); cairo_close_path( currentContext ); diff --git a/common/gal/opengl/gl_builtin_shaders.cpp b/common/gal/opengl/gl_builtin_shaders.cpp index 21bd36e898..d837cb9f76 100644 --- a/common/gal/opengl/gl_builtin_shaders.cpp +++ b/common/gal/opengl/gl_builtin_shaders.cpp @@ -333,12 +333,11 @@ int isPixelInSegment( vec2 aCoord ) void strokedCircle( vec2 aCoord, float aRadius, float aWidth ) { - float outerRadius = max( aRadius + ( aWidth / 2 ), 0.0 ); - float innerRadius = max( aRadius - ( aWidth / 2 ), 0.0 ); - float relWidth = innerRadius / outerRadius; + float outerRadius = max( aRadius, 0.0 ); + float innerRadius = max( aRadius - aWidth, 0.0 ); if( ( dot( aCoord, aCoord ) < 1.0 ) && - ( dot( aCoord, aCoord ) > relWidth * relWidth ) ) + ( dot( aCoord, aCoord ) * ( outerRadius * outerRadius ) > innerRadius * innerRadius ) ) gl_FragColor = gl_Color; else discard;