Skip to content

Commit

Permalink
Optimise QgsLineString::sumUpArea
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 28, 2022
1 parent 2d1e3fb commit c2b30d9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/geometry/qgslinestring.cpp
Expand Up @@ -1936,11 +1936,19 @@ QgsPoint QgsLineString::centroid() const

void QgsLineString::sumUpArea( double &sum ) const
{
int maxIndex = numPoints() - 1;
const int maxIndex = mX.size();
if ( maxIndex == 0 )
return;

for ( int i = 0; i < maxIndex; ++i )
const double *x = mX.constData();
const double *y = mY.constData();
double prevX = *x++;
double prevY = *y++;
for ( int i = 1; i < maxIndex; ++i )
{
sum += 0.5 * ( mX.at( i ) * mY.at( i + 1 ) - mY.at( i ) * mX.at( i + 1 ) );
sum += 0.5 * ( prevX * ( *y ) - prevY * ( *x ) );
prevX = *x++;
prevY = *y++;
}
}

Expand Down

0 comments on commit c2b30d9

Please sign in to comment.