7#include <QtQmlIntegration/qqmlintegration.h>
9#include <boost/describe/class.hpp>
10#include <nlohmann/json_fwd.hpp>
12using namespace std::string_view_literals;
22class CurveOptions final
91 static constexpr
double EXPONENT_CURVINESS_BOUND = 0.95;
92 static constexpr
double VITAL_CURVINESS_BOUND = 1.00;
96 CurveOptions () = default;
97 CurveOptions (
double curviness,
Algorithm algo);
107 friend
bool operator== (const CurveOptions &a, const CurveOptions &b);
110 static constexpr auto kCurvinessKey =
"curviness"sv;
111 static constexpr auto kAlgorithmKey =
"algorithm"sv;
112 friend
void to_json (nlohmann::json &j, const CurveOptions &opts);
113 friend
void from_json (const nlohmann::json &j, CurveOptions &opts);
129class CurveOptionsQmlAdapter :
public QObject
133 double curviness READ curviness WRITE setCurviness NOTIFY curvinessChanged)
136 setAlgorithm NOTIFY algorithmChanged)
141 CurveOptionsQmlAdapter (
CurveOptions &options, QObject * parent =
nullptr)
142 : QObject (parent), options_ (options)
150 double curviness ()
const {
return options_.curviness_; }
151 void setCurviness (
double curviness);
152 Q_SIGNAL
void curvinessChanged (
double curviness);
156 return options_.algo_;
162 Q_INVOKABLE
double normalizedY (
double x,
bool startHigher)
const
164 return options_.get_normalized_y (x, startHigher);
178DEFINE_ENUM_FORMATTER (
180 CurveOptions_Algorithm,
181 QT_TR_NOOP_UTF8 (
"Exponent"),
182 QT_TR_NOOP_UTF8 (
"Superellipse"),
184 QT_TR_NOOP_UTF8 (
"Pulse"),
185 QT_TR_NOOP_UTF8 (
"Logarithmic"));
Algorithm algo_
Curve algorithm to use.
static constexpr double SUPERELLIPSE_CURVINESS_BOUND
Bounds for each algorithm.
Algorithm
The algorithm to use for curves.
@ Vital
(e^(nx) - 1) / (e^n - 1) -10 <= n <= 10 where positive tilts down and negative tilts up (when startin...
@ Logarithmic
a = log (n) b = 1 / (log (1 + (1 / n)))
@ SuperEllipse
y = 1 - (1 - x^n)^(1/n) 0 < n <= 1, where the whole thing is tilting up and 0 is full tilt and 1 is s...
@ Exponent
y = x^n 0 < n <= 1, where the whole thing is tilting up and 0 is full tilt and 1 is straight line (wh...
double get_normalized_y(double x, bool start_higher) const
Returns the Y value on a curve.
double curviness_
Curviness between -1 and 1, where < 0 tils downwards, > 0 tilts upwards and 0 is a straight line.