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) noexcept;
108 friend
bool operator== (const CurveOptions &a, const CurveOptions &b);
111 static constexpr auto kCurvinessKey =
"curviness"sv;
112 static constexpr auto kAlgorithmKey =
"algorithm"sv;
113 friend
void to_json (nlohmann::json &j, const CurveOptions &opts);
114 friend
void from_json (const nlohmann::json &j, CurveOptions &opts);
130class CurveOptionsQmlAdapter :
public QObject
134 double curviness READ curviness WRITE setCurviness NOTIFY curvinessChanged)
137 setAlgorithm NOTIFY algorithmChanged)
142 CurveOptionsQmlAdapter (
CurveOptions &options, QObject * parent =
nullptr)
143 : QObject (parent), options_ (options)
151 double curviness ()
const {
return options_.curviness_; }
152 void setCurviness (
double curviness);
153 Q_SIGNAL
void curvinessChanged (
double curviness);
157 return options_.algo_;
163 Q_INVOKABLE
double normalizedY (
double x,
bool startHigher)
const
165 return options_.get_normalized_y (x, startHigher);
194 double ratio)
noexcept [[clang::nonblocking]];
201DEFINE_ENUM_FORMATTER (
203 CurveOptions_Algorithm,
204 QT_TR_NOOP_UTF8 (
"Exponent"),
205 QT_TR_NOOP_UTF8 (
"Superellipse"),
207 QT_TR_NOOP_UTF8 (
"Pulse"),
208 QT_TR_NOOP_UTF8 (
"Logarithmic"));
Algorithm algo_
Curve algorithm to use.
double get_normalized_y(double x, bool start_higher) const noexcept
Returns the Y value on a curve.
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 curviness_
Curviness between -1 and 1, where < 0 tils downwards, > 0 tilts upwards and 0 is a straight line.