From 96370f666507e30bdca96bc39f00687c1397f33b Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Sun, 9 Jun 2024 20:01:45 +0300 Subject: [PATCH] Make sure to add start points to arcs in TransformOvalToPolygon. Otherwise the long line segments can be non-parallel to the centerline. This was the root cause of the slowdown in https://gitlab.com/kicad/code/kicad/-/issues/18156 Fixes https://gitlab.com/kicad/code/kicad/-/issues/18156 (cherry picked from commit 76b2741a9232f6651e6be463f8ec8afc6b6273af) --- libs/kimath/src/convert_basic_shapes_to_polygon.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libs/kimath/src/convert_basic_shapes_to_polygon.cpp b/libs/kimath/src/convert_basic_shapes_to_polygon.cpp index 17c1d07a82..fa2530213c 100644 --- a/libs/kimath/src/convert_basic_shapes_to_polygon.cpp +++ b/libs/kimath/src/convert_basic_shapes_to_polygon.cpp @@ -171,6 +171,10 @@ void TransformOvalToPolygon( SHAPE_POLY_SET& aBuffer, const VECTOR2I& aStart, co // add right rounded end: + // Right arc start: + corner = VECTOR2I( seg_len, radius ); + polyshape.Append( corner.x, corner.y ); + for( EDA_ANGLE angle = delta / 2; angle < ANGLE_180; angle += delta ) { corner = VECTOR2I( 0, radius ); @@ -179,10 +183,14 @@ void TransformOvalToPolygon( SHAPE_POLY_SET& aBuffer, const VECTOR2I& aStart, co polyshape.Append( corner.x, corner.y ); } - // Finish arc: + // Finish right arc: corner = VECTOR2I( seg_len, -radius ); polyshape.Append( corner.x, corner.y ); + // Left arc start: + corner = VECTOR2I( 0, -radius ); + polyshape.Append( corner.x, corner.y ); + // add left rounded end: for( EDA_ANGLE angle = delta / 2; angle < ANGLE_180; angle += delta ) { @@ -191,7 +199,7 @@ void TransformOvalToPolygon( SHAPE_POLY_SET& aBuffer, const VECTOR2I& aStart, co polyshape.Append( corner.x, corner.y ); } - // Finish arc: + // Finish left arc: corner = VECTOR2I( 0, radius ); polyshape.Append( corner.x, corner.y );