Grail (C++)  1.1.1
A multi-platform, modular, universal engine for embedding advanced AI in games.
UnitStepFunction.hh
1 #ifndef GRAIL_SINGLE_STEP_FUNCTION_H
2 #define GRAIL_SINGLE_STEP_FUNCTION_H
3 
4 #include "Curve.hh"
5 
6 namespace grail
7 {
8  namespace curves
9  {
10  template <typename ContextType>
15  class UnitStepFunction final : public Curve<ContextType>
16  {
17  public:
25  UnitStepFunction(std::shared_ptr<utility::Evaluator<ContextType>> childEvaluator,
26  float threshold,
27  float beforeThresholdValue,
28  float afterThresholdValue)
29  : Curve<ContextType>{childEvaluator},
30  threshold{threshold},
31  beforeThresholdValue{beforeThresholdValue},
32  afterThresholdValue{afterThresholdValue}
33  {
34  }
35 
36  virtual float Sample(float argument) const override final
37  {
38  return argument > threshold ? afterThresholdValue : beforeThresholdValue;
39  }
40 
45  float GetThreshold() const { return threshold; }
50  float GetBeforeThresholdValue() const { return beforeThresholdValue; }
55  float GetAfterThresholdValue() const { return afterThresholdValue; }
56 
57  virtual EvaluatorType GetEvaluatorType() const override final { return EvaluatorType::CURVE_UNIT_STEP; }
58 
59  private:
60  float threshold = 0.0f;
61  float beforeThresholdValue = 0.0f;
62  float afterThresholdValue = 0.0f;
63  };
64  }
65 }
66 
67 #endif // GRAIL_SINGLE_STEP_FUNCTION_H
grail::curves::Curve
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:19
grail::curves::UnitStepFunction::UnitStepFunction
UnitStepFunction(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float threshold, float beforeThresholdValue, float afterThresholdValue)
UnitStepFunction - Constructor.
Definition: UnitStepFunction.hh:25
grail::curves::UnitStepFunction
The UnitStepFunction class - Unit Step Function.
Definition: UnitStepFunction.hh:15
grail::curves::UnitStepFunction::GetAfterThresholdValue
float GetAfterThresholdValue() const
GetAfterThresholdValue.
Definition: UnitStepFunction.hh:55
grail::curves::UnitStepFunction::GetBeforeThresholdValue
float GetBeforeThresholdValue() const
GetBeforeThresholdValue.
Definition: UnitStepFunction.hh:50
grail::utility::Evaluator
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:20
grail::curves::UnitStepFunction::Sample
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: UnitStepFunction.hh:36
grail::curves::UnitStepFunction::GetThreshold
float GetThreshold() const
GetThreshold.
Definition: UnitStepFunction.hh:45