From 18d836ef8b97c2e23d96ba83c9190f74ad7a6bf7 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop <dudesuchamazing@gmail.com> Date: Sat, 8 Mar 2025 23:03:21 +0300 Subject: [PATCH] Reduce CSegment calls in SHAPE_LINE_CHAIN::SelfIntersecting. --- libs/kimath/src/geometry/shape_line_chain.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index 6f453acc73..d26828a9cb 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -1969,11 +1969,14 @@ const std::optional<SHAPE_LINE_CHAIN::INTERSECTION> SHAPE_LINE_CHAIN::SelfInters { for( int s1 = 0; s1 < SegmentCount(); s1++ ) { + const SEG cs1 = CSegment( s1 ); + for( int s2 = s1 + 1; s2 < SegmentCount(); s2++ ) { - const VECTOR2I s2a = CSegment( s2 ).A, s2b = CSegment( s2 ).B; + const SEG cs2 = CSegment( s2 ); + const VECTOR2I s2a = cs2.A, s2b = cs2.B; - if( s1 + 1 != s2 && CSegment( s1 ).Contains( s2a ) ) + if( s1 + 1 != s2 && cs1.Contains( s2a ) ) { INTERSECTION is; is.index_our = s1; @@ -1981,7 +1984,7 @@ const std::optional<SHAPE_LINE_CHAIN::INTERSECTION> SHAPE_LINE_CHAIN::SelfInters is.p = s2a; return is; } - else if( CSegment( s1 ).Contains( s2b ) && + else if( cs1.Contains( s2b ) && // for closed polylines, the ending point of the // last segment == starting point of the first segment // this is a normal case, not self intersecting case @@ -1995,7 +1998,7 @@ const std::optional<SHAPE_LINE_CHAIN::INTERSECTION> SHAPE_LINE_CHAIN::SelfInters } else { - OPT_VECTOR2I p = CSegment( s1 ).Intersect( CSegment( s2 ), true ); + OPT_VECTOR2I p = cs1.Intersect( cs2, true ); if( p ) {