From e7fe69b97ff558c208c6ef35d4f3270277cbb61d Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 13 Feb 2023 11:18:04 -0800 Subject: [PATCH] Better handling of vertex sorting Nominally, the zcode of a vertex is unique. This is not 100% true, however, as we must interlace two 32-bit numbers into a single 32-bit number. Sorting needs to account for the possibility that the zcode will be the same while other elements of the vertex are different. This commit fixes the broken boolean logic to more clearly handle these cases Fixes https://gitlab.com/kicad/code/kicad/issues/13867 --- .../include/geometry/polygon_triangulation.h | 11 ++++++++++- pcbnew/drc/drc_test_provider_connection_width.cpp | 14 ++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libs/kimath/include/geometry/polygon_triangulation.h b/libs/kimath/include/geometry/polygon_triangulation.h index ccb7a1acf1..788d8d3255 100644 --- a/libs/kimath/include/geometry/polygon_triangulation.h +++ b/libs/kimath/include/geometry/polygon_triangulation.h @@ -210,7 +210,16 @@ private: std::sort( queue.begin(), queue.end(), []( const Vertex* a, const Vertex* b ) { - return a->z < b->z; + if( a->z != b->z ) + return a->z < b->z; + + if( a->x != b->x ) + return a->x < b->x; + + if( a->y != b->y ) + return a->y < b->y; + + return a->i < b->i; } ); Vertex* prev_elem = nullptr; diff --git a/pcbnew/drc/drc_test_provider_connection_width.cpp b/pcbnew/drc/drc_test_provider_connection_width.cpp index a51d865553..b72d856e75 100644 --- a/pcbnew/drc/drc_test_provider_connection_width.cpp +++ b/pcbnew/drc/drc_test_provider_connection_width.cpp @@ -252,10 +252,16 @@ private: std::sort( queue.begin(), queue.end(), []( const Vertex* a, const Vertex* b ) { - return a->z < b->z || ( a->z == b->z - && ( ( a->x < b->x ) - || ( a->y < b->y ) - || ( a->i < b->i ) ) ); + if( a->z != b->z ) + return a->z < b->z; + + if( a->x != b->x ) + return a->x < b->x; + + if( a->y != b->y ) + return a->y < b->y; + + return a->i < b->i; } ); Vertex* prev_elem = nullptr;