1 #ifndef GRAIL_LINEAR_FUNCTION_H
2 #define GRAIL_LINEAR_FUNCTION_H
10 template <
typename ContextType>
27 :
Curve<ContextType>{childEvaluator}, slope{slope}, intercept{intercept}
38 std::pair<float, float> firstPoint,
39 std::pair<float, float> secondPoint)
40 :
Curve<ContextType>{childEvaluator}
42 assert(firstPoint.first != secondPoint.first);
43 if(firstPoint.second == secondPoint.second)
46 intercept = firstPoint.second;
50 if(firstPoint.first > secondPoint.first)
52 float x = firstPoint.first;
53 float y = firstPoint.second;
54 firstPoint.first = secondPoint.first;
55 firstPoint.second = secondPoint.second;
56 secondPoint.first = x;
57 secondPoint.second = y;
59 slope = (secondPoint.second - firstPoint.second) / (secondPoint.first - firstPoint.first);
60 intercept = firstPoint.second - (slope * firstPoint.first);
64 virtual float Sample(
float argument)
const override final
66 return slope * argument + intercept;
80 virtual EvaluatorType GetEvaluatorType() const override final {
return EvaluatorType::CURVE_LINEAR; }
84 float intercept = 0.0f;
89 #endif // GRAIL_LINEAR_FUNCTION_H