16namespace tracktion {
inline namespace core
19inline std::pair<
double ,
double > getBezierPoint (
double x1,
double y1,
double x2,
double y2,
27 auto xc = x1 + run / 2;
28 auto yc =
y1 + rise / 2;
30 auto x = xc - run / 2 * -c;
31 auto y = yc + rise / 2 * -c;
39 auto xc = x1 + run / 2;
40 auto yc = y2 + rise / 2;
42 auto x = xc - run / 2 * -c;
43 auto y = yc - rise / 2 * -c;
48inline void getBezierEnds (
const double x1,
const double y1,
const double x2,
const double y2,
const double c,
49 double& x1out,
double& y1out,
double& x2out,
double& y2out)
noexcept
51 auto minic = (std::abs (c) - 0.5f) * 2.0f;
52 auto run = minic * (x2 - x1);
53 auto rise = minic * ((y2 >
y1) ? (y2 - y1) : (
y1 - y2));
61 y2out = (
float) (y1 < y2 ? (y2 - rise) : (y2 + rise));
66 y1out = (
float) (y1 < y2 ? (y1 + rise) : (
y1 - rise));
73inline double getBezierYFromX (
double x,
double x1,
double y1,
double xb,
double yb,
double x2,
double y2)
noexcept
76 if (x1 == x2 || y1 == y2)
80 if (x <= x1)
return y1;
81 if (x >= x2)
return y2;
87 auto a = x1 - 2 * xb + x2;
88 auto b = -2 * x1 + 2 * xb;
100 t = (-b +
std::sqrt (b * b - 4 * a * c)) / (2 * a);
102 if (t < 0.0f || t > 1.0f)
103 t = (-b -
std::sqrt (b * b - 4 * a * c)) / (2 * a);
106 jassert (t >= 0.0f && t <= 1.0f);