stmm-games-doc  0.32.0
Classes | Public Member Functions | Static Public Member Functions | List of all members
stmg::SegmentedFunction Class Reference

Segmented function: concatenation of "touching" segments. More...

Public Member Functions

 SegmentedFunction () noexcept
 Empty constructor. More...
 
 SegmentedFunction (double fA, double fB) noexcept
 Constructor. More...
 
double eval (double fX) const noexcept
 Evaluate the function for a given x. More...
 
double evalInverse (double fY) const noexcept
 Evaluate the inverse for a given y. More...
 
void mul (double fFactor) noexcept
 Multiply function by a factor. More...
 
bool operator== (const SegmentedFunction &oSF) const noexcept
 
void dump (int32_t nIndentSpaces) const noexcept
 
void dump () const noexcept
 

Static Public Member Functions

static SegmentedFunction add (const SegmentedFunction &oF1, const SegmentedFunction &oF2) noexcept
 Calculate sum of two functions. More...
 
static SegmentedFunction max (const SegmentedFunction &oF1, const SegmentedFunction &oF2) noexcept
 Calculate maximum of two functions. More...
 

Detailed Description

Segmented function: concatenation of "touching" segments.

The function is limited to:

Segment: fA * fX + fB, fFromX   with fA >= 0.0, fB >= 0.0, fFromX >= 0, fX >= 0.

This helper class can be used to calculate layouts.

Constructor & Destructor Documentation

◆ SegmentedFunction() [1/2]

stmg::SegmentedFunction::SegmentedFunction ( )
noexcept

Empty constructor.

Calls SegmentedFunction(0.0, 0.0)

◆ SegmentedFunction() [2/2]

stmg::SegmentedFunction::SegmentedFunction ( double  fA,
double  fB 
)
noexcept

Constructor.

Creates a one segment function with segment y = fA * x + fB. Since this class doesn't check overflows fA and fB shouldn't be too big.

Parameters
fAMust be >= 0.0.
fBMust be >= 0.0.

Member Function Documentation

◆ add()

static SegmentedFunction stmg::SegmentedFunction::add ( const SegmentedFunction oF1,
const SegmentedFunction oF2 
)
staticnoexcept

Calculate sum of two functions.

Parameters
oF1First function.
oF2Second function.
Returns
Result function.

◆ dump() [1/2]

void stmg::SegmentedFunction::dump ( int32_t  nIndentSpaces) const
noexcept

◆ dump() [2/2]

void stmg::SegmentedFunction::dump ( ) const
inlinenoexcept

◆ eval()

double stmg::SegmentedFunction::eval ( double  fX) const
noexcept

Evaluate the function for a given x.

Beware! No overflow check is performed so don't try it with too big or too small numbers.

Parameters
fXMust be >= 0.0.
Returns
The result (fY) of the function. Always >= 0.0.

◆ evalInverse()

double stmg::SegmentedFunction::evalInverse ( double  fY) const
noexcept

Evaluate the inverse for a given y.

Parameters
fYMust be >= 0.0.
Returns
The highest value of fX for which eval(fX) == fY, or -1.0 if there's no inverse.

◆ max()

static SegmentedFunction stmg::SegmentedFunction::max ( const SegmentedFunction oF1,
const SegmentedFunction oF2 
)
staticnoexcept

Calculate maximum of two functions.

Parameters
oF1First function.
oF2Second function.
Returns
Result function.

◆ mul()

void stmg::SegmentedFunction::mul ( double  fFactor)
noexcept

Multiply function by a factor.

Parameters
fFactorMust be >= 0.0.

◆ operator==()

bool stmg::SegmentedFunction::operator== ( const SegmentedFunction oSF) const
inlinenoexcept