Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(optimization): Tiny optimization for pointsInternal #60138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/core/geometry/qgsellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,17 @@ void QgsEllipse::pointsInternal( unsigned int segments, QVector<double> &x, QVec
const bool hasZ = mCenter.is3D();
const bool hasM = mCenter.isMeasure();

std::vector<double> t( segments );
const QgsPoint p1 = mCenter.project( mSemiMajorAxis, mAzimuth );
const double azimuth = std::atan2( p1.y() - mCenter.y(), p1.x() - mCenter.x() );
const double cosAzimuth = std::cos( azimuth );
const double sinAzimuth = std::sin( azimuth );

std::vector<double> cosT( segments ), sinT( segments );
for ( unsigned int i = 0; i < segments; ++i )
{
t[i] = 2 * M_PI - ( ( 2 * M_PI ) / segments * i ); // Since the algorithm used rotates in the trigonometric direction (counterclockwise)
double angle = 2 * M_PI - ( ( 2 * M_PI ) / segments * i ); // Since the algorithm used rotates in the trigonometric direction (counterclockwise)
cosT[i] = std::cos( angle );
sinT[i] = std::sin( angle );
}

x.resize( segments );
Expand All @@ -235,21 +240,20 @@ void QgsEllipse::pointsInternal( unsigned int segments, QVector<double> &x, QVec
z.resize( segments );
if ( hasM )
m.resize( segments );

double *xOut = x.data();
double *yOut = y.data();
double *zOut = hasZ ? z.data() : nullptr;
double *mOut = hasM ? m.data() : nullptr;

const double cosAzimuth = std::cos( azimuth );
const double sinAzimuth = std::sin( azimuth );
for ( double it : t )
for ( unsigned int i = 0; i < segments; ++i )
{
*xOut++ = centerX +
mSemiMajorAxis * std::cos( it ) * cosAzimuth -
mSemiMinorAxis * std::sin( it ) * sinAzimuth;
mSemiMajorAxis * cosT[i] * cosAzimuth -
mSemiMinorAxis * sinT[i] * sinAzimuth;
*yOut++ = centerY +
mSemiMajorAxis * std::cos( it ) * sinAzimuth +
mSemiMinorAxis * std::sin( it ) * cosAzimuth;
mSemiMajorAxis * cosT[i] * sinAzimuth +
mSemiMinorAxis * sinT[i] * cosAzimuth;
if ( zOut )
*zOut++ = centerZ;
if ( mOut )
Expand Down
Loading