diff --git a/MeshGeoToolsLib/GeoMapper.cpp b/MeshGeoToolsLib/GeoMapper.cpp index 5bd61a27b23deac58eaa7b8ad2bb7ba166549c45..d3ed7fa7098b8b4207d3f353e300e7419751b1c6 100644 --- a/MeshGeoToolsLib/GeoMapper.cpp +++ b/MeshGeoToolsLib/GeoMapper.cpp @@ -458,9 +458,7 @@ static bool snapPointToElementNode(MathLib::Point3d& p, MeshLib::Element const& elem, double rel_eps) { // values will be initialized within computeSqrNodeDistanceRange - double sqr_min; - double sqr_max; - elem.computeSqrNodeDistanceRange(sqr_min, sqr_max); + auto const [sqr_min, sqr_max] = MeshLib::computeSqrNodeDistanceRange(elem); double const sqr_eps(rel_eps*rel_eps * sqr_min); for (std::size_t k(0); k<elem.getNumberOfNodes(); ++k) { diff --git a/MeshGeoToolsLib/HeuristicSearchLength.cpp b/MeshGeoToolsLib/HeuristicSearchLength.cpp index c42a644fc47ab363ecbe8ef82c42cc909b7695e6..c624d2713bb3c3a6c65f93f3018373fef590ed76 100644 --- a/MeshGeoToolsLib/HeuristicSearchLength.cpp +++ b/MeshGeoToolsLib/HeuristicSearchLength.cpp @@ -43,10 +43,10 @@ HeuristicSearchLength::HeuristicSearchLength(MeshLib::Mesh const& mesh, LengthTy n_sampling += n_edges; } } else { - double min = 0; - double max = 0; - for (const MeshLib::Element* e : elements) { - e->computeSqrNodeDistanceRange(min, max, true); + for (const MeshLib::Element* e : elements) + { + auto const [min, max] = + MeshLib::computeSqrNodeDistanceRange(*e, true); sum += std::sqrt(min); sum_of_sqr += min; } diff --git a/MeshLib/Elements/Element.cpp b/MeshLib/Elements/Element.cpp index 28dbf583cc84118f16e165b2f9c0cbc911654676..6b84f46a0046b8b850e62fe7d0e1fbed06a2ec71 100644 --- a/MeshLib/Elements/Element.cpp +++ b/MeshLib/Elements/Element.cpp @@ -99,22 +99,6 @@ MeshLib::Node Element::getCenterOfGravity() const return center; } -void Element::computeSqrNodeDistanceRange(double &min, double &max, bool check_allnodes) const -{ - min = std::numeric_limits<double>::max(); - max = 0; - const unsigned nnodes = check_allnodes ? getNumberOfNodes() : getNumberOfBaseNodes(); - for (unsigned i=0; i<nnodes; i++) - { - for (unsigned j=i+1; j<nnodes; j++) - { - const double dist (MathLib::sqrDist(*getNode(i), *getNode(j))); - min = std::min(dist, min); - max = std::max(dist, max); - } - } -} - const Element* Element::getNeighbor(unsigned i) const { #ifndef NDEBUG @@ -220,6 +204,26 @@ std::ostream& operator<<(std::ostream& os, Element const& e) } #endif // NDEBUG +std::pair<double, double> computeSqrNodeDistanceRange( + MeshLib::Element const& element, bool const check_allnodes) +{ + double min = std::numeric_limits<double>::max(); + double max = 0; + const unsigned nnodes = check_allnodes ? element.getNumberOfNodes() + : element.getNumberOfBaseNodes(); + for (unsigned i = 0; i < nnodes; i++) + { + for (unsigned j = i + 1; j < nnodes; j++) + { + const double dist( + MathLib::sqrDist(*element.getNode(i), *element.getNode(j))); + min = std::min(dist, min); + max = std::max(dist, max); + } + } + return {min, max}; +} + std::pair<double, double> computeSqrEdgeLengthRange(Element const& element) { double min = std::numeric_limits<double>::max(); diff --git a/MeshLib/Elements/Element.h b/MeshLib/Elements/Element.h index 0d8b5d8891c07a80e0fa7bb0178ce04cfa5576a6..50af016b10d234efd06c066c3cc5aecded1944cd 100644 --- a/MeshLib/Elements/Element.h +++ b/MeshLib/Elements/Element.h @@ -36,10 +36,6 @@ class Element friend class Mesh; public: - /// Compute the minimum and maximum node distances for this element. - void computeSqrNodeDistanceRange(double& min, double& max, - bool check_allnodes = true) const; - /** * \brief Tries to add an element e as neighbour to this element. * If the elements really are neighbours, the element is added to the @@ -225,6 +221,10 @@ protected: }; /* class */ +/// Compute the minimum and maximum node distances for this element. +std::pair<double, double> computeSqrNodeDistanceRange( + MeshLib::Element const& element, bool const check_allnodes = true); + /// Compute the minimum and maximum squared edge length for this element std::pair<double, double> computeSqrEdgeLengthRange(Element const& element);