3 #ifndef GRAIL_LINEAR_FUNCTION_H
4 #define GRAIL_LINEAR_FUNCTION_H
12 template <
typename ContextType>
29 :
Curve<ContextType>{childEvaluator}, slope{slope}, intercept{intercept}
40 std::pair<float, float> firstPoint,
41 std::pair<float, float> secondPoint)
42 :
Curve<ContextType>{childEvaluator}
44 assert(firstPoint.first != secondPoint.first);
45 if(firstPoint.second == secondPoint.second)
48 intercept = firstPoint.second;
52 if(firstPoint.first > secondPoint.first)
54 float x = firstPoint.first;
55 float y = firstPoint.second;
56 firstPoint.first = secondPoint.first;
57 firstPoint.second = secondPoint.second;
58 secondPoint.first = x;
59 secondPoint.second = y;
61 slope = (secondPoint.second - firstPoint.second) / (secondPoint.first - firstPoint.first);
62 intercept = firstPoint.second - (slope * firstPoint.first);
66 virtual float Sample(
float argument)
const override final
68 return slope * argument + intercept;
82 virtual data::EvaluatorType GetEvaluatorType() const override final {
return data::EvaluatorType::CURVE_LINEAR; }
86 float intercept = 0.0f;
91 #endif // GRAIL_LINEAR_FUNCTION_H