diff --git a/applications/test/minMax1/Test-minMax1.C b/applications/test/minMax1/Test-minMax1.C index a33b3a31342aa21b763f1546694aaa4c256b0e23..26e43aecf0aeb6e392927e80a86f1d71ff2cfcbd 100644 --- a/applications/test/minMax1/Test-minMax1.C +++ b/applications/test/minMax1/Test-minMax1.C @@ -42,7 +42,7 @@ using namespace Foam; template<class T> Ostream& printInfo(const MinMax<T>& range) { - Info<< range << " valid=" << range.valid(); + Info<< range << " valid=" << range.valid() << " span=" << range.span(); return Info; } @@ -84,6 +84,12 @@ int main(int argc, char *argv[]) Info<<"Construct range : "; printInfo(MinMax<scalar>(1, 20)) << nl; + Info<<"A 0-1 scalar range : "; + printInfo(scalarMinMax::zero_one()) << nl; + + Info<<"A 0-1 vector range : "; + printInfo(MinMax<vector>::zero_one()) << nl; + { scalarMinMax range1(10, 20); diff --git a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H index 1cd02430753cc8a9ffa4c1e13a5c800a2ac0dedb..59b1f16201068dc9d0fac04724837ef87e9a10a9 100644 --- a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H +++ b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H @@ -159,6 +159,12 @@ public: inline explicit MinMax(const UList<T>& vals); + // Static Member Functions + + //- A 0-1 range corresponding to the pTraits zero, one + inline static MinMax<T> zero_one(); + + // Member Functions // Access @@ -178,6 +184,9 @@ public: //- The min/max average value inline T centre() const; + //- The min to max span. Zero if the range is invalid. + inline T span() const; + //- The magnitude of the min to max span. Zero if the range is invalid. inline scalar mag() const; @@ -195,10 +204,10 @@ public: //- Intersect (union) with the second range. // \return True if the resulting intersection is non-empty. - bool intersect(const MinMax<T>& b); + inline bool intersect(const MinMax<T>& b); //- Test if the ranges overlap - bool overlaps(const MinMax<T>& b) const; + inline bool overlaps(const MinMax<T>& b) const; //- Compares the min/max range with the specified value. // \return diff --git a/src/OpenFOAM/primitives/ranges/MinMax/MinMaxI.H b/src/OpenFOAM/primitives/ranges/MinMax/MinMaxI.H index 83033baf1443a0398b48887b0493cc99d3a43813..afdf34916d467a36443c04fe7a86b6ecf1f8f350 100644 --- a/src/OpenFOAM/primitives/ranges/MinMax/MinMaxI.H +++ b/src/OpenFOAM/primitives/ranges/MinMax/MinMaxI.H @@ -23,6 +23,15 @@ License \*---------------------------------------------------------------------------*/ +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +template<class T> +inline Foam::MinMax<T> Foam::MinMax<T>::zero_one() +{ + return MinMax<T>(pTraits<T>::zero, pTraits<T>::one); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class T> @@ -114,10 +123,17 @@ inline T Foam::MinMax<T>::centre() const } +template<class T> +inline T Foam::MinMax<T>::span() const +{ + return (empty() ? Zero : (max() - min())); +} + + template<class T> inline Foam::scalar Foam::MinMax<T>::mag() const { - return (empty() ? Zero : ::Foam::mag(max() - min())); + return ::Foam::mag(span()); }