3 #ifndef GRAIL_POWER_FUNCTION_H
4 #define GRAIL_POWER_FUNCTION_H
13 template <
typename ContextType>
32 :
Curve<ContextType>{childEvaluator}, slope(slope), intercept(intercept), exponent(exponent)
44 std::pair<float, float> firstPoint,
45 std::pair<float, float> secondPoint,
47 :
Curve<ContextType>{childEvaluator}, exponent{exponent}
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 = (std::pow(secondPoint.second, 1 / exponent) - std::pow(firstPoint.second, 1 / exponent)) / (
59 secondPoint.first - firstPoint.first);
60 intercept = std::pow(firstPoint.second, 1 / exponent) - (slope * firstPoint.first);
63 virtual float Sample(
float argument)
const override final
65 float linearPart = slope * argument + intercept;
68 int intExponent =
static_cast<int>(exponent);
69 if(exponent - intExponent > 0.0f)
75 return std::pow(linearPart, exponent);
94 virtual data::EvaluatorType GetEvaluatorType() const override final {
return data::EvaluatorType::CURVE_POWER; }
98 float intercept = 0.0f;
99 float exponent = 0.0f;
104 #endif // GRAIL_POWER_FUNCTION_H