MinMax< T > Class Template Reference

A min/max value pair with additional methods. In addition to conveniently storing values, it can be used for logic operations or to modify data. A few global functions and functors are also provided. More...

Inheritance diagram for MinMax< T >:
[legend]
Collaboration diagram for MinMax< T >:
[legend]

Public Types

typedef T value_type
 The value type the MinMax represents. More...
 
typedef pTraits< T >::cmptType cmptType
 Component type. More...
 
- Public Types inherited from Tuple2< T, T >
typedef T first_type
 Type of member first, the first template parameter (T1) More...
 
typedef T second_type
 Type of member second, the second template parameter (T2) More...
 

Public Member Functions

 MinMax ()
 Construct inverted range. More...
 
 MinMax (const T &minVal, const T &maxVal)
 Copy construct from components. More...
 
 MinMax (const std::pair< T, T > &range)
 Copy construct from components. More...
 
 MinMax (const Pair< T > &range)
 Copy construct from components. More...
 
 MinMax (const Foam::zero)
 Construct with a single zero value. More...
 
 MinMax (const T &val)
 Construct with a single initial value. More...
 
 MinMax (const UList< T > &vals)
 Construct from list of values. More...
 
const Tmin () const noexcept
 The min value (first) More...
 
Tmin () noexcept
 The min value (first) More...
 
const Tmax () const noexcept
 The max value (second) More...
 
Tmax () noexcept
 The max value (second) More...
 
T centre () const
 The min/max average value. More...
 
T span () const
 The min to max span. Zero if the range is invalid. More...
 
scalar mag () const
 The magnitude of the min to max span. Zero if the range is invalid. More...
 
bool empty () const
 Range is empty if it is inverted. More...
 
bool valid () const
 Range is valid if it is not inverted. More...
 
void clear ()
 Reset to an invalid, inverted range. More...
 
bool intersect (const MinMax< T > &b)
 Intersect (union) with the second range. More...
 
bool overlaps (const MinMax< T > &b) const
 Test if the ranges overlap. More...
 
int compare (const T &val) const
 Compares the min/max range with the specified value. More...
 
bool contains (const T &val) const
 True if the value is within the range. More...
 
const Tclip (const T &val) const
 
bool inplaceClip (T &val) const
 Inplace clip value by the min/max limits. More...
 
MinMax< T > & add (const MinMax &other)
 Extend the range to include the other min/max range. More...
 
MinMax< T > & add (const T &val)
 Include the value into the range. More...
 
MinMax< T > & add (const UList< T > &vals)
 Include the values into the range. More...
 
bool operator() (const T &val) const
 Identical to contains(), for use as a predicate. More...
 
MinMax< T > & operator+= (const MinMax< T > &b)
 Extend min/max range to include other range. More...
 
MinMax< T > & operator+= (const T &val)
 Extend min/max range to include value. More...
 
MinMax< T > & operator+= (const UList< T > &vals)
 Extend min/max range to include all values. More...
 
MinMax< T > & operator*= (const scalar &s)
 Multiply range by scalar factor. More...
 
MinMax< T > & operator/= (const scalar &s)
 Divide range by scalar factor. More...
 
- Public Member Functions inherited from Tuple2< T, T >
 Tuple2 ()=default
 Default construct. More...
 
 Tuple2 (const T &f, const T &s)
 Copy construct from components. More...
 
 Tuple2 (T &&f, T &&s)
 Move construct from components. More...
 
 Tuple2 (const std::pair< T, T > &vals)
 Copy construct from std::pair. More...
 
 Tuple2 (std::pair< T, T > &&vals)
 Move construct from std::pair. More...
 
 Tuple2 (Istream &is)
 Construct from Istream. More...
 
const Tfirst () const noexcept
 Return first. More...
 
Tfirst () noexcept
 Return first. More...
 
const Tsecond () const noexcept
 Return second. More...
 
Tsecond () noexcept
 Return second. More...
 

Static Public Member Functions

static MinMax< Tge (const T &minVal)
 A semi-infinite range from minVal to the type max. More...
 
static MinMax< Tle (const T &maxVal)
 A semi-infinite range from type min to maxVal. More...
 
static MinMax< Tzero_one ()
 A 0-1 range corresponding to the pTraits zero, one. More...
 

Detailed Description

template<class T>
class Foam::MinMax< T >

A min/max value pair with additional methods. In addition to conveniently storing values, it can be used for logic operations or to modify data. A few global functions and functors are also provided.

Examples of use.

Determine min/max limits from a List of values:

List<scalar> values = ...;

// on construction
MinMax<scalar> range(values);

range.clear();

range += val;

// global minMax() function
Info<< minMax(values) << nl;

General comparison operations

scalar val;
if (val < range) ... value is below range min
if (range.contains(val)) ... value within range
if (range.compare(val) > 0) ... value is above range max
if (range(val)) ... value within range - as predicate

Since the range has a predicate form, it can be used as a filter method. For example,

Info<< "values in range: " << subsetList(values, range) << nl;

boolList mask = ListOps::create<bool>(values, range);
Info<< "values values in range " << mask << nl;

One particular advantage offered by MinMax is to clip or limit values to a particular range. For example,

scalarMinMax range(lower, upper);

scalar val;
val = range.clip(val)    .. return clip values

// vs.
val = min(max(value, lower, upper))

Or when working on lists, the values can be limited in a single pass of the data without intermediate memory allocation.

scalarField values = ...;

for (scalar& val : values)
{
    range.inplaceClip(val);
}

// vs.
values = min(max(values, lower, upper))

Definition at line 125 of file MinMax.H.

Member Typedef Documentation

◆ value_type

typedef T value_type

The value type the MinMax represents.

Definition at line 134 of file MinMax.H.

◆ cmptType

typedef pTraits<T>::cmptType cmptType

Component type.

Definition at line 137 of file MinMax.H.

Constructor & Destructor Documentation

◆ MinMax() [1/7]

MinMax
inline

Construct inverted range.

Definition at line 54 of file MinMaxI.H.

References Foam::min().

Here is the call graph for this function:

◆ MinMax() [2/7]

MinMax ( const T minVal,
const T maxVal 
)
inline

Copy construct from components.

Definition at line 61 of file MinMaxI.H.

◆ MinMax() [3/7]

MinMax ( const std::pair< T, T > &  range)
inline

Copy construct from components.

Definition at line 68 of file MinMaxI.H.

◆ MinMax() [4/7]

MinMax ( const Pair< T > &  range)
inline

Copy construct from components.

Definition at line 75 of file MinMaxI.H.

◆ MinMax() [5/7]

MinMax ( const Foam::zero  )
inlineexplicit

Construct with a single zero value.

Definition at line 82 of file MinMaxI.H.

◆ MinMax() [6/7]

MinMax ( const T val)
inlineexplicit

Construct with a single initial value.

Definition at line 89 of file MinMaxI.H.

◆ MinMax() [7/7]

MinMax ( const UList< T > &  vals)
inlineexplicit

Construct from list of values.

Definition at line 96 of file MinMaxI.H.

References MinMax< T >::add().

Here is the call graph for this function:

Member Function Documentation

◆ ge()

Foam::MinMax< T > ge ( const T minVal)
inlinestatic

A semi-infinite range from minVal to the type max.

Definition at line 31 of file MinMaxI.H.

Referenced by singleDirectionUniformBin::read(), STDMD::read(), externalCoupled::read(), and writeFile::read().

Here is the caller graph for this function:

◆ le()

Foam::MinMax< T > le ( const T maxVal)
inlinestatic

A semi-infinite range from type min to maxVal.

Definition at line 38 of file MinMaxI.H.

◆ zero_one()

Foam::MinMax< T > zero_one
inlinestatic

A 0-1 range corresponding to the pTraits zero, one.

Definition at line 45 of file MinMaxI.H.

◆ min() [1/2]

const T & min
inlinenoexcept

The min value (first)

Definition at line 107 of file MinMaxI.H.

Referenced by Foam::getAnimationColour(), MinMax< scalar >::max(), probes::storeResults(), GeometricField< Type, PatchField, GeoMesh >::writeMinMax(), and gltfWriter::writeTemplate().

Here is the caller graph for this function:

◆ min() [2/2]

T & min
inlinenoexcept

The min value (first)

Definition at line 114 of file MinMaxI.H.

◆ max() [1/2]

const T & max
inlinenoexcept

The max value (second)

Definition at line 121 of file MinMaxI.H.

Referenced by Foam::getAnimationColour(), MinMax< scalar >::max(), probes::storeResults(), and gltfWriter::writeTemplate().

Here is the caller graph for this function:

◆ max() [2/2]

T & max
inlinenoexcept

The max value (second)

Definition at line 128 of file MinMaxI.H.

◆ centre()

T centre
inline

The min/max average value.

Definition at line 135 of file MinMaxI.H.

References Foam::max(), and Foam::min().

Here is the call graph for this function:

◆ span()

T span
inline

The min to max span. Zero if the range is invalid.

Definition at line 143 of file MinMaxI.H.

◆ mag()

Foam::scalar mag
inline

The magnitude of the min to max span. Zero if the range is invalid.

Definition at line 150 of file MinMaxI.H.

◆ empty()

bool empty
inline

Range is empty if it is inverted.

Definition at line 157 of file MinMaxI.H.

◆ valid()

bool valid
inline

Range is valid if it is not inverted.

Definition at line 164 of file MinMaxI.H.

References Foam::max(), and Foam::min().

Referenced by x3dWriter::x3dWriter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void clear
inline

Reset to an invalid, inverted range.

Definition at line 171 of file MinMaxI.H.

◆ intersect()

bool intersect ( const MinMax< T > &  b)
inline

Intersect (union) with the second range.

Returns
True if the resulting intersection is non-empty.

Definition at line 179 of file MinMaxI.H.

◆ overlaps()

bool overlaps ( const MinMax< T > &  b) const
inline

Test if the ranges overlap.

Definition at line 189 of file MinMaxI.H.

◆ compare()

int compare ( const T val) const
inline

Compares the min/max range with the specified value.

Returns
  • 0: value is within the range, or range is invalid
  • -1: range (max) is less than the value
  • +1: range (min) is greater than value

Definition at line 197 of file MinMaxI.H.

◆ contains()

bool contains ( const T val) const
inline

True if the value is within the range.

Definition at line 216 of file MinMaxI.H.

◆ clip()

const T & clip ( const T val) const
inline

If out of range, return the respective min/max limits, otherwise return the value itself.

If the range is invalid, always return the value.

Definition at line 223 of file MinMaxI.H.

◆ inplaceClip()

bool inplaceClip ( T val) const
inline

Inplace clip value by the min/max limits.

Returns
True if clipping was applied.

Definition at line 242 of file MinMaxI.H.

◆ add() [1/3]

Foam::MinMax< T > & add ( const MinMax< T > &  other)
inline

Extend the range to include the other min/max range.

Definition at line 263 of file MinMaxI.H.

Referenced by PDRblock::location::edgeLimits(), Foam::minMax(), MinMax< T >::MinMax(), Foam::minMaxMag(), minMaxOp< T >::operator()(), and Foam::operator+().

Here is the caller graph for this function:

◆ add() [2/3]

Foam::MinMax< T > & add ( const T val)
inline

Include the value into the range.

Definition at line 272 of file MinMaxI.H.

References Foam::max(), and Foam::min().

Here is the call graph for this function:

◆ add() [3/3]

Foam::MinMax< T > & add ( const UList< T > &  vals)
inline

Include the values into the range.

Definition at line 281 of file MinMaxI.H.

References Foam::add(), and T.

Here is the call graph for this function:

◆ operator()()

bool operator() ( const T val) const
inline

Identical to contains(), for use as a predicate.

Definition at line 294 of file MinMaxI.H.

◆ operator+=() [1/3]

Foam::MinMax< T > & operator+= ( const MinMax< T > &  b)
inline

Extend min/max range to include other range.

Can be used in a reduction operation.

Definition at line 332 of file MinMaxI.H.

References Foam::add(), and b.

Here is the call graph for this function:

◆ operator+=() [2/3]

Foam::MinMax< T > & operator+= ( const T val)
inline

Extend min/max range to include value.

Definition at line 339 of file MinMaxI.H.

References Foam::add().

Here is the call graph for this function:

◆ operator+=() [3/3]

Foam::MinMax< T > & operator+= ( const UList< T > &  vals)
inline

Extend min/max range to include all values.

Definition at line 346 of file MinMaxI.H.

References Foam::add().

Here is the call graph for this function:

◆ operator*=()

Foam::MinMax< T > & operator*= ( const scalar &  s)
inline

Multiply range by scalar factor.

Definition at line 353 of file MinMaxI.H.

References Foam::max(), Foam::min(), and s().

Here is the call graph for this function:

◆ operator/=()

Foam::MinMax< T > & operator/= ( const scalar &  s)
inline

Divide range by scalar factor.

Definition at line 362 of file MinMaxI.H.

References Foam::max(), Foam::min(), and s().

Here is the call graph for this function:

The documentation for this class was generated from the following files: