6 #include "../Evaluator.hh"
7 #include "../../libs/vector2/vector2.h"
20 template <
typename ContextType>
29 : childEvaluator{childEvaluator}
33 Curve(
const Curve<ContextType>& other) =
default;
34 Curve(Curve<ContextType>&& other) =
default;
35 virtual ~
Curve() =
default;
42 virtual float Sample(
float argument)
const = 0;
47 return Sample(childEvaluator->EvaluateContext(context, snapshot));
52 childEvaluator->GetDependentConsiderations(considerations);
56 virtual void DebugDump(
const std::map<const void*, unsigned int>& nodeMapping,
59 debugData.AddChildNode(nodeMapping.at(childEvaluator.get()));
63 std::shared_ptr<Evaluator<ContextType>> childEvaluator{};
66 template <
typename ContextType>
80 :
Curve<ContextType>(childEvaluator), lowerBound{lowerBound}
84 virtual float Sample(
float argument)
const override final
86 return std::max(lowerBound, argument);
89 virtual data::EvaluatorType GetEvaluatorType() const override final {
return data::EvaluatorType::CURVE_LOWER_BOUND; }
92 float lowerBound = 0.0f;
95 template <
typename ContextType>
109 :
Curve<ContextType>(childEvaluator), upperBound{upperBound}
113 virtual float Sample(
float argument)
const override final
115 return std::min(upperBound, argument);
118 virtual data::EvaluatorType GetEvaluatorType() const override final {
return data::EvaluatorType::CURVE_UPPER_BOUND; }
121 float upperBound = 0.0f;
124 template <
typename ContextType>
141 :
Curve<ContextType>{childEvaluator}, lowerBound{lowerBound}, upperBound{upperBound}
145 virtual float Sample(
float argument)
const override final
147 return std::min(upperBound, std::max(lowerBound, argument));
150 virtual data::EvaluatorType GetEvaluatorType() const override final
152 return data::EvaluatorType::CURVE_DOUBLE_SIDED_BOUND;
156 float lowerBound = 0.0f;
157 float upperBound = 0.0f;
160 template <
typename ContextType>
167 std::vector<Vector2> DiscretizeCurve(
const Curve<ContextType>& curve, std::size_t samplesQuantity)
169 std::vector<Vector2> controlPoints;
170 float increment = 1.0f / (samplesQuantity - 1);
171 for(
float i = 0; i <= 1; i += increment)
173 controlPoints.push_back({i, curve.Sample(i)});
175 return controlPoints;
179 #endif //GRAIL_CURVE_H