Loading...
Searching...
No Matches
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...

#include <MinMax.H>

Inheritance diagram for MinMax< T >:

Public Types

typedef T value_type
 The value type the MinMax represents.
typedef pTraits< T >::cmptType cmptType
 Component type.

Public Member Functions

 MinMax ()
 Default construct: an inverted range.
 MinMax (const T &minVal, const T &maxVal)
 Construct from min/max limits.
 MinMax (const std::pair< T, T > &range)
 Implicit construct from min/max limits.
 MinMax (const Pair< T > &range)
 Implicit construct from min/max limits.
 MinMax (const Tuple2< T, T > &range)
 Implicit construct from min/max limits.
 MinMax (Foam::zero)
 Construct with a single zero value.
 MinMax (Foam::zero_one)
 Implicit construct from zero_one as 0-1 range (pTraits zero, one).
 MinMax (const T &val)
 Construct with a single initial value.
 MinMax (const UList< T > &vals)
 Construct from list of values.
const Tmin () const noexcept
 The min value.
Tmin () noexcept
 The min value.
const Tmax () const noexcept
 The max value.
Tmax () noexcept
 The max value.
T centre () const
 The min/max average value.
T span () const
 The min to max span. Zero for invalid range.
scalar mag () const
 The magnitude of the min to max span. Zero for invalid range.
bool empty () const
 Range is empty if it is inverted.
bool good () const
 Range is non-inverted.
void reset ()
 Reset to an inverted (invalid) range.
void reset (const T &val)
 Reset min/max to be identical to the specified value.
void reset (const T &minVal, const T &maxVal)
 Reset min/max to specified values.
void clear ()
 Same as reset() - reset to an inverted (invalid) range.
bool intersects (const MinMax< T > &b) const
 Test if the ranges intersect (exclusive check).
bool overlaps (const MinMax< T > &b) const
 Test if ranges overlap/touch (inclusive check).
int compare (const T &val) const
 Compares the min/max range with the specified value.
bool contains (const T &val) const
 True if the value is within the range (inclusive check).
T clamp (const T &val) const
 Return value clamped component-wise.
MinMax< T > & add (const MinMax &other)
 Extend the range to include the other min/max range.
MinMax< T > & add (const T &val)
 Include the value into the range.
MinMax< T > & add (const UList< T > &vals)
 Include the values into the range.
template<class... Args>
MinMax< T > & add (const T &val0, const T &val1, Args &&... values)
 Include two or more values into the range.
bool operator() (const T &val) const
 Identical to contains(), for use as a predicate.
MinMax< T > & operator&= (const MinMax< T > &b)
 Restrict min/max range to union with other range.
MinMax< T > & operator+= (const MinMax< T > &b)
 Extend min/max range to include other range.
MinMax< T > & operator+= (const T &val)
 Extend min/max range to include value.
MinMax< T > & operator+= (const UList< T > &vals)
 Extend min/max range to include all values.
MinMax< T > & operator*= (scalar s)
 Multiply range by scalar factor.
MinMax< T > & operator/= (scalar s)
 Divide range by scalar factor.
bool valid () const
 Range is non-inverted. Same as good (2022-10).
T clip (const T &val) const
 Old method name. Same as clamp (2023-01).
template<class... Args>
Foam::MinMax< T > & add (const T &val0, const T &val1, Args &&... values)

Static Public Member Functions

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

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.reset();

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 advantage offered by MinMax is to clamp or limit values to a particular range. For example,

scalarMinMax range(lower, upper);

scalar val;
val = range.clamp(val)    .. return clamped values

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

Definition at line 105 of file MinMax.H.

Member Typedef Documentation

◆ value_type

template<class T>
typedef T value_type

The value type the MinMax represents.

Definition at line 126 of file MinMax.H.

◆ cmptType

template<class T>
typedef pTraits<T>::cmptType cmptType

Component type.

Definition at line 131 of file MinMax.H.

Constructor & Destructor Documentation

◆ MinMax() [1/9]

template<class T>
MinMax ( )
inline

Default construct: an inverted range.

Definition at line 47 of file MinMaxI.H.

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

Referenced by add(), ge(), intersects(), le(), MinMax(), operator&=(), overlaps(), and zero_one().

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

◆ MinMax() [2/9]

template<class T>
MinMax ( const T & minVal,
const T & maxVal )
inline

Construct from min/max limits.

Definition at line 56 of file MinMaxI.H.

References Foam::T().

Here is the call graph for this function:

◆ MinMax() [3/9]

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

Implicit construct from min/max limits.

Definition at line 64 of file MinMaxI.H.

References range.

◆ MinMax() [4/9]

template<class T>
MinMax ( const Pair< T > & range)
inline

Implicit construct from min/max limits.

Definition at line 72 of file MinMaxI.H.

References range.

◆ MinMax() [5/9]

template<class T>
MinMax ( const Tuple2< T, T > & range)
inline

Implicit construct from min/max limits.

Definition at line 80 of file MinMaxI.H.

References range.

◆ MinMax() [6/9]

template<class T>
MinMax ( Foam::zero )
inlineexplicit

Construct with a single zero value.

Definition at line 88 of file MinMaxI.H.

References Foam::T().

Here is the call graph for this function:

◆ MinMax() [7/9]

template<class T>
MinMax ( Foam::zero_one )
inline

Implicit construct from zero_one as 0-1 range (pTraits zero, one).

Definition at line 96 of file MinMaxI.H.

References Foam::T().

Here is the call graph for this function:

◆ MinMax() [8/9]

template<class T>
MinMax ( const T & val)
inlineexplicit

Construct with a single initial value.

Definition at line 104 of file MinMaxI.H.

References Foam::T().

Here is the call graph for this function:

◆ MinMax() [9/9]

template<class T>
MinMax ( const UList< T > & vals)
inlineexplicit

Construct from list of values.

Definition at line 112 of file MinMaxI.H.

References add(), MinMax(), and Foam::T().

Here is the call graph for this function:

Member Function Documentation

◆ ge()

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

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

Definition at line 24 of file MinMaxI.H.

References MinMax(), and Foam::T().

Here is the call graph for this function:

◆ le()

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

A semi-infinite range from type min to maxVal.

Definition at line 31 of file MinMaxI.H.

References MinMax(), and Foam::T().

Here is the call graph for this function:

◆ zero_one()

template<class T>
Foam::MinMax< T > zero_one ( )
inlinestatic

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

Definition at line 38 of file MinMaxI.H.

References MinMax().

Here is the call graph for this function:

◆ min() [1/2]

◆ min() [2/2]

template<class T>
T & min ( )
inlinenoexcept

The min value.

Definition at line 212 of file MinMax.H.

◆ max() [1/2]

◆ max() [2/2]

template<class T>
T & max ( )
inlinenoexcept

The max value.

Definition at line 222 of file MinMax.H.

◆ centre()

template<class T>
T centre ( ) const
inline

The min/max average value.

Definition at line 123 of file MinMaxI.H.

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

Here is the call graph for this function:

◆ span()

template<class T>
T span ( ) const
inline

The min to max span. Zero for invalid range.

Definition at line 131 of file MinMaxI.H.

References empty(), Foam::max(), Foam::min(), Foam::T(), and Foam::Zero.

Referenced by singleDirectionUniformBin::initialise(), and equalBinWidth::write().

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

◆ mag()

template<class T>
Foam::scalar mag ( ) const
inline

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

Definition at line 138 of file MinMaxI.H.

◆ empty()

template<class T>
bool empty ( ) const
inline

Range is empty if it is inverted.

Definition at line 145 of file MinMaxI.H.

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

Referenced by span().

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

◆ good()

template<class T>
bool good ( ) const
inline

Range is non-inverted.

Definition at line 153 of file MinMaxI.H.

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

Referenced by compare(), contains(), singleDirectionUniformBin::initialise(), MinMax< label >::valid(), and equalBinWidth::write().

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

◆ reset() [1/3]

template<class T>
void reset ( )
inline

Reset to an inverted (invalid) range.

Definition at line 160 of file MinMaxI.H.

Referenced by MinMax< label >::clear().

Here is the caller graph for this function:

◆ reset() [2/3]

template<class T>
void reset ( const T & val)
inline

Reset min/max to be identical to the specified value.

Definition at line 169 of file MinMaxI.H.

References Foam::T().

Here is the call graph for this function:

◆ reset() [3/3]

template<class T>
void reset ( const T & minVal,
const T & maxVal )
inline

Reset min/max to specified values.

Definition at line 177 of file MinMaxI.H.

References Foam::T().

Here is the call graph for this function:

◆ clear()

template<class T>
void clear ( )
inline

Same as reset() - reset to an inverted (invalid) range.

Definition at line 267 of file MinMax.H.

◆ intersects()

template<class T>
bool intersects ( const MinMax< T > & b) const
inline

Test if the ranges intersect (exclusive check).

Definition at line 185 of file MinMaxI.H.

References b, and MinMax().

Here is the call graph for this function:

◆ overlaps()

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

Test if ranges overlap/touch (inclusive check).

Definition at line 193 of file MinMaxI.H.

References b, max(), min(), and MinMax().

Here is the call graph for this function:

◆ compare()

template<class T>
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 201 of file MinMaxI.H.

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

Here is the call graph for this function:

◆ contains()

template<class T>
bool contains ( const T & val) const
inline

True if the value is within the range (inclusive check).

Definition at line 220 of file MinMaxI.H.

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

Referenced by operator()().

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

◆ clamp()

template<class T>
T clamp ( const T & val) const
inline

Return value clamped component-wise.

If the range is invalid, just returns the value.

Definition at line 227 of file MinMaxI.H.

Referenced by MinMax< label >::clip().

Here is the caller graph for this function:

◆ add() [1/5]

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

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

Definition at line 240 of file MinMaxI.H.

References MinMax().

Referenced by singleDirectionUniformBin::initialise(), MinMax(), Foam::minMax(), Foam::minMax(), Foam::minMaxMag(), Foam::minMaxMag(), Foam::operator+(), and AMIWeights::reportPatch().

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

◆ add() [2/5]

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

Include the value into the range.

Definition at line 250 of file MinMaxI.H.

References Foam::T().

Here is the call graph for this function:

◆ add() [3/5]

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

Include the values into the range.

Definition at line 260 of file MinMaxI.H.

References Foam::add(), and Foam::T().

Here is the call graph for this function:

◆ add() [4/5]

template<class T>
template<class... Args>
MinMax< T > & add ( const T & val0,
const T & val1,
Args &&... values )
inline

Include two or more values into the range.

All values must be similar types

◆ operator()()

template<class T>
bool operator() ( const T & val) const
inline

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

Definition at line 292 of file MinMaxI.H.

References contains(), and Foam::T().

Here is the call graph for this function:

◆ operator&=()

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

Restrict min/max range to union with other range.

Definition at line 330 of file MinMaxI.H.

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

Here is the call graph for this function:

◆ operator+=() [1/3]

template<class T>
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 341 of file MinMaxI.H.

◆ operator+=() [2/3]

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

Extend min/max range to include value.

Definition at line 348 of file MinMaxI.H.

References Foam::add(), and Foam::T().

Here is the call graph for this function:

◆ operator+=() [3/3]

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

Extend min/max range to include all values.

Definition at line 355 of file MinMaxI.H.

References Foam::add().

Here is the call graph for this function:

◆ operator*=()

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

Multiply range by scalar factor.

Definition at line 362 of file MinMaxI.H.

References s().

Here is the call graph for this function:

◆ operator/=()

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

Divide range by scalar factor.

Definition at line 371 of file MinMaxI.H.

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

Here is the call graph for this function:

◆ valid()

template<class T>
bool valid ( ) const
inline

Range is non-inverted. Same as good (2022-10).

Definition at line 376 of file MinMax.H.

◆ clip()

template<class T>
T clip ( const T & val) const
inline

Old method name. Same as clamp (2023-01).

Definition at line 381 of file MinMax.H.

◆ add() [5/5]

template<class T>
template<class... Args>
Foam::MinMax< T > & add ( const T & val0,
const T & val1,
Args &&... values )
inline

Definition at line 272 of file MinMaxI.H.


The documentation for this class was generated from the following files:
  • src/OpenFOAM/containers/HashTables/HashSet/HashSet.H
  • src/OpenFOAM/primitives/ranges/MinMax/MinMax.H
  • src/OpenFOAM/primitives/ranges/MinMax/MinMaxI.H