Janitor : Performance improvements identified by profiling

This commit is contained in:
Magne Sjaastad
2021-09-30 11:17:43 +02:00
parent 9bc3036e8a
commit 6a6fc52ef9

View File

@@ -110,12 +110,20 @@ bool RigSurfaceResampler::findClosestPointXY( const cvf::Vec3d& tar
// Find closest vertices // Find closest vertices
double shortestDistanceSquared = std::numeric_limits<double>::max(); double shortestDistanceSquared = std::numeric_limits<double>::max();
double closestZ = std::numeric_limits<double>::infinity(); double closestZ = std::numeric_limits<double>::infinity();
for ( auto v : vertices ) cvf::Vec3d p;
double distanceSquared = 0.0;
for ( const auto& v : vertices )
{ {
if ( std::fabs( targetPoint.x() - v.x() ) > maxDistance ) continue;
if ( std::fabs( targetPoint.y() - v.y() ) > maxDistance ) continue;
// Ignore height (z) component when finding closest by // Ignore height (z) component when finding closest by
// moving point to same height as target point above // moving point to same height as target point above
cvf::Vec3d p( v.x(), v.y(), targetPoint.z() ); p.x() = v.x();
double distanceSquared = p.pointDistanceSquared( targetPoint ); p.y() = v.y();
p.z() = targetPoint.z();
distanceSquared = p.pointDistanceSquared( targetPoint );
if ( distanceSquared < shortestDistanceSquared ) if ( distanceSquared < shortestDistanceSquared )
{ {
shortestDistanceSquared = distanceSquared; shortestDistanceSquared = distanceSquared;