From: Denis Davydov Date: Mon, 24 Apr 2017 12:03:44 +0000 (+0200) Subject: add Point::squared_distance() X-Git-Tag: v9.0.0-rc1~1659^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64472339c1ce893be79122677689af1524846d2c;p=dealii.git add Point::squared_distance() --- diff --git a/doc/news/changes/minor/20170424DenisDavydov b/doc/news/changes/minor/20170424DenisDavydov new file mode 100644 index 0000000000..36a57f5f44 --- /dev/null +++ b/doc/news/changes/minor/20170424DenisDavydov @@ -0,0 +1,4 @@ +New: add Point::squared_distance() which calculates the squared +Euclidean distance. +
+(Denis Davydov, 2017/04/24) diff --git a/include/deal.II/base/point.h b/include/deal.II/base/point.h index 0149994d48..0f2369b512 100644 --- a/include/deal.II/base/point.h +++ b/include/deal.II/base/point.h @@ -227,6 +227,12 @@ public: */ typename numbers::NumberTraits::real_type distance (const Point &p) const; + /** + * Return the squared Euclidean distance of this point to the point + * p. + */ + typename numbers::NumberTraits::real_type squared_distance (const Point &p) const; + /** * @} */ @@ -475,6 +481,16 @@ template inline typename numbers::NumberTraits::real_type Point::distance (const Point &p) const +{ + return std::sqrt(squared_distance(p)); +} + + + +template +inline +typename numbers::NumberTraits::real_type +Point::squared_distance (const Point &p) const { Number sum = Number(); for (unsigned int i=0; i::distance (const Point &p) const sum += numbers::NumberTraits::abs_square (diff); } - return std::sqrt(sum); + return sum; }