From bfd04926b5ea246d6066fdb8cccfb3b3c4827611 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 20 Oct 2020 21:30:31 +0100 Subject: [PATCH] Performance improvement for polyset fracture. --- libs/kimath/src/geometry/shape_poly_set.cpp | 29 +++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index 260f77f937..6c7c83fd79 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -683,26 +683,30 @@ static int processEdge( FractureEdgeSet& edges, FractureEdge* edge ) FractureEdge* e_nearest = NULL; - for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i ) + for( FractureEdge* e : edges ) { - if( !(*i)->matches( y ) ) + if( !e->matches( y ) ) continue; int x_intersect; - if( (*i)->m_p1.y == (*i)->m_p2.y ) // horizontal edge - x_intersect = std::max( (*i)->m_p1.x, (*i)->m_p2.x ); + if( e->m_p1.y == e->m_p2.y ) // horizontal edge + { + x_intersect = std::max( e->m_p1.x, e->m_p2.x ); + } else - x_intersect = (*i)->m_p1.x + rescale( (*i)->m_p2.x - (*i)->m_p1.x, y - (*i)->m_p1.y, - (*i)->m_p2.y - (*i)->m_p1.y ); + { + x_intersect = e->m_p1.x + rescale( e->m_p2.x - e->m_p1.x, y - e->m_p1.y, + e->m_p2.y - e->m_p1.y ); + } int dist = ( x - x_intersect ); - if( dist >= 0 && dist < min_dist && (*i)->m_connected ) + if( dist >= 0 && dist < min_dist && e->m_connected ) { min_dist = dist; x_nearest = x_intersect; - e_nearest = (*i); + e_nearest = e; } } @@ -710,12 +714,9 @@ static int processEdge( FractureEdgeSet& edges, FractureEdge* edge ) { int count = 0; - FractureEdge* lead1 = - new FractureEdge( true, VECTOR2I( x_nearest, y ), VECTOR2I( x, y ) ); - FractureEdge* lead2 = - new FractureEdge( true, VECTOR2I( x, y ), VECTOR2I( x_nearest, y ) ); - FractureEdge* split_2 = - new FractureEdge( true, VECTOR2I( x_nearest, y ), e_nearest->m_p2 ); + FractureEdge* lead1 = new FractureEdge( true, VECTOR2I( x_nearest, y ), VECTOR2I( x, y ) ); + FractureEdge* lead2 = new FractureEdge( true, VECTOR2I( x, y ), VECTOR2I( x_nearest, y ) ); + FractureEdge* split_2 = new FractureEdge( true, VECTOR2I( x_nearest, y ), e_nearest->m_p2 ); edges.push_back( split_2 ); edges.push_back( lead1 );