From 64472339c1ce893be79122677689af1524846d2c Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Mon, 24 Apr 2017 14:03:44 +0200 Subject: [PATCH] add Point::squared_distance() --- doc/news/changes/minor/20170424DenisDavydov | 4 ++++ include/deal.II/base/point.h | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 doc/news/changes/minor/20170424DenisDavydov 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; } -- 2.39.5