From c9f8b928138c41270599c2da5c53a3a78d71a901 Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Fri, 31 May 2024 10:46:14 +0200 Subject: [PATCH] fix(compute_gradient): Updated weight of points contribution. --- src/geode/mesh/helpers/gradient_computation.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/geode/mesh/helpers/gradient_computation.cpp b/src/geode/mesh/helpers/gradient_computation.cpp index 65d74673c..d78194ccc 100644 --- a/src/geode/mesh/helpers/gradient_computation.cpp +++ b/src/geode/mesh/helpers/gradient_computation.cpp @@ -87,16 +87,19 @@ namespace const auto value_diff = function_value - scalar_function->value( vertex_around ); - const auto dist = position_diff.length(); - if( std::fabs( dist ) < geode::global_epsilon - || std::fabs( position_diff.value( d ) ) - < geode::global_epsilon ) + const auto dist2 = position_diff.length2(); + if( std::fabs( dist2 ) < geode::global_epsilon + || std::fabs( + position_diff.value( d ) / std::sqrt( dist2 ) ) + < 0.1 ) { continue; } - contribution_sum += - value_diff / position_diff.value( d ) / dist; - inverse_dist_sum += 1 / dist; + const double diff_sign{ position_diff.value( d ) < 0 ? -1. + : 1. }; + contribution_sum += value_diff * diff_sign / dist2; + inverse_dist_sum += + diff_sign * position_diff.value( d ) / dist2; } OPENGEODE_EXCEPTION( std::fabs( inverse_dist_sum ) > geode::global_epsilon,