1 #ifndef GRAIL_POWER_FUNCTION_H
2 #define GRAIL_POWER_FUNCTION_H
12 template <
typename ContextType>
28 float slope,
float intercept,
float exponent)
29 :
Curve<ContextType>{childEvaluator}, slope(slope), intercept(intercept), exponent(exponent)
41 std::pair<float, float> firstPoint, std::pair<float, float> secondPoint,
43 :
Curve<ContextType>{childEvaluator}, exponent{exponent}
45 if (firstPoint.first > secondPoint.first)
47 float x = firstPoint.first;
48 float y = firstPoint.second;
49 firstPoint.first = secondPoint.first;
50 firstPoint.second = secondPoint.second;
51 secondPoint.first = x;
52 secondPoint.second = y;
54 slope = (std::pow(secondPoint.second, 1 / exponent) - std::pow(firstPoint.second, 1 / exponent)) / (secondPoint.first - firstPoint.first);
55 intercept = std::pow(firstPoint.second, 1 / exponent) - (slope * firstPoint.first);
58 virtual float Sample(
float argument)
const override final
60 float linearPart = slope * argument + intercept;
61 if (linearPart < 0.0f)
63 int intExponent =
static_cast<int>(exponent);
64 if (exponent - intExponent > 0.0f)
70 return std::pow(linearPart, exponent);
89 EvaluatorType GetEvaluatorType() const override final {
return EvaluatorType::CURVE_POWER; }
93 float intercept = 0.0f;
94 float exponent = 0.0f;
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:21
The PowerFunction class - Power function.
Definition: PowerFunction.hh:18
float GetExponent() const
GetExponent.
Definition: PowerFunction.hh:87
PowerFunction(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float slope, float intercept, float exponent)
PowerFunction - Constructor.
Definition: PowerFunction.hh:27
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: PowerFunction.hh:58
float GetSlope() const
GetSlope.
Definition: PowerFunction.hh:77
PowerFunction(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, std::pair< float, float > firstPoint, std::pair< float, float > secondPoint, float exponent)
PowerFunction - Constructor.
Definition: PowerFunction.hh:40
float GetIntercept() const
GetIntercept.
Definition: PowerFunction.hh:82
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:21