1 #ifndef GRAIL_LINEAR_FUNCTION_H
2 #define GRAIL_LINEAR_FUNCTION_H
11 template <
typename ContextType>
26 float slope,
float intercept)
27 :
Curve<ContextType>{childEvaluator}, slope{slope}, intercept{intercept}
38 std::pair<float, float> firstPoint, std::pair<float, float> secondPoint)
39 :
Curve<ContextType>{childEvaluator}
41 assert(firstPoint.first != secondPoint.first);
42 if (firstPoint.second == secondPoint.second)
45 intercept = firstPoint.second;
49 if (firstPoint.first > secondPoint.first)
51 float x = firstPoint.first;
52 float y = firstPoint.second;
53 firstPoint.first = secondPoint.first;
54 firstPoint.second = secondPoint.second;
55 secondPoint.first = x;
56 secondPoint.second = y;
58 slope = (secondPoint.second - firstPoint.second) / (secondPoint.first - firstPoint.first);
59 intercept = firstPoint.second - (slope * firstPoint.first);
63 virtual float Sample(
float argument)
const override final
65 return slope * argument + intercept;
79 EvaluatorType GetEvaluatorType() const override final {
return EvaluatorType::CURVE_LINEAR; }
83 float intercept = 0.0f;
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:21
The LinearFunction class - Linear Function.
Definition: LinearFunction.hh:17
LinearFunction(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, std::pair< float, float > firstPoint, std::pair< float, float > secondPoint)
LinearFunction - Constructor.
Definition: LinearFunction.hh:37
LinearFunction(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float slope, float intercept)
LinearFunction - Constructor.
Definition: LinearFunction.hh:25
float GetIntercept() const
GetIntercept.
Definition: LinearFunction.hh:77
float GetSlope() const
GetSlope.
Definition: LinearFunction.hh:72
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: LinearFunction.hh:63
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:21