Commit 3f8c99c8 authored by Mark Olesen's avatar Mark Olesen

ENH: additional MinMax span() and zero_one() methods

parent 9d8899ca
......@@ -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);
......
......@@ -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
......
......@@ -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());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment