4 #include "../../libs/vector2/vector2.h"
5 #include "../Evaluator.hh"
19 template <
typename ContextType>
28 : childEvaluator{childEvaluator}
34 virtual ~
Curve() =
default;
41 virtual float Sample(
float argument)
const = 0;
45 return Sample(childEvaluator->EvaluateContext(context, snapshot));
51 debugData.AddChildNode(nodeMapping.at(childEvaluator.get()));
55 std::shared_ptr<utility::Evaluator<ContextType>> childEvaluator{};
58 template <
typename ContextType>
72 :
Curve<ContextType>(childEvaluator), lowerBound{ lowerBound }
76 virtual float Sample(
float argument)
const override final
78 return std::max(lowerBound, argument);
81 EvaluatorType GetEvaluatorType() const override final {
return EvaluatorType::CURVE_LOWER_BOUND; }
84 float lowerBound = 0.0f;
87 template <
typename ContextType>
101 :
Curve<ContextType>(childEvaluator), upperBound{ upperBound }
105 virtual float Sample(
float argument)
const override final
107 return std::min(upperBound, argument);
110 EvaluatorType GetEvaluatorType() const override final {
return EvaluatorType::CURVE_UPPER_BOUND; }
113 float upperBound = 0.0f;
116 template <
typename ContextType>
133 :
Curve<ContextType>{childEvaluator}, lowerBound{lowerBound}, upperBound{upperBound}
137 virtual float Sample(
float argument)
const override final
139 return std::min(upperBound, std::max(lowerBound, argument));
142 EvaluatorType GetEvaluatorType() const override final {
return EvaluatorType::CURVE_DOUBLE_SIDED_BOUND; }
145 float lowerBound = 0.0f;
146 float upperBound = 0.0f;
149 template<
typename ContextType>
156 std::vector<Vector2> DiscretizeCurve(
const Curve<ContextType>& curve, std::size_t samplesQuantity)
158 std::vector<Vector2> controlPoints;
159 float increment = 1.0f / (samplesQuantity - 1);
160 for (
float i = 0; i <= 1; i += increment)
162 controlPoints.push_back({ i, curve.Sample(i) });
164 return controlPoints;
The EvaluationDebugData class - debug data describing singular evaluator.
Definition: EvaluationDebugData.h:20
The UtilityEvaluatorSnapshot class - debug snapshot of whole evaluator tree assigned to evaluated obj...
Definition: UtilityEvaluatorSnapshot.h:22
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:21
virtual float Evaluate(const ContextType &context, UtilityEvaluatorSnapshot *const snapshot) const override final
Evaluate - Called from EvaluateContext which also evaluates context, but without automatically fillin...
Definition: Curve.hh:43
virtual float Sample(float argument) const =0
Sample - Transforms argument into output value depending on the type of Curve.
Curve(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator)
Curve - Constructor.
Definition: Curve.hh:27
virtual void DebugDump(const std::map< const void *, std::size_t > &nodeMapping, EvaluationDebugData &debugData) const override final
DebugDump - Called from EvaluateContext, which generates additional debug data for each evaluator....
Definition: Curve.hh:49
The DoubleSidedBound class - Bounds output of provided Evaluator from both sides.
Definition: Curve.hh:122
DoubleSidedBound(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float lowerBound, float upperBound)
DoubleSidedBound - Constructor.
Definition: Curve.hh:130
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: Curve.hh:137
The LowerBound class - Lower-bounds output of provided Evaluator.
Definition: Curve.hh:64
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: Curve.hh:76
LowerBound(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float lowerBound)
LowerBound - Constructor.
Definition: Curve.hh:71
The UpperBound class - Upper-bounds output of provided Evaluator.
Definition: Curve.hh:93
UpperBound(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float upperBound)
UpperBound - Constructor.
Definition: Curve.hh:100
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: Curve.hh:105
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:21