MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ breakpoint_curve()

MAYAFLUX_API double MayaFlux::Kinesis::Discrete::breakpoint_curve ( std::span< const double >  window,
std::span< const double >  coefs 
)
noexcept

Piecewise linear curve through (x, y) points.

coefs: pairs (x, y) with ascending x. The input is window[0], held at the first and last y outside the span of x. Uneven spacing is fine; unsorted x is not. An empty array gives zero.

Definition at line 316 of file Kernels.cpp.

317{
318 const size_t points = coefs.size() / 2;
319 if (points == 0)
320 return 0.0;
321
322 const double x = window.empty() ? 0.0 : window.front();
323 if (x <= coefs[0])
324 return coefs[1];
325 if (x >= coefs[2 * (points - 1)])
326 return coefs[2 * (points - 1) + 1];
327
328 size_t i = 0;
329 while (i + 2 < points && x > coefs[2 * (i + 1)])
330 ++i;
331
332 const double x0 = coefs[2 * i];
333 const double x1 = coefs[2 * (i + 1)];
334 const double y0 = coefs[2 * i + 1];
335 const double y1 = coefs[2 * (i + 1) + 1];
336 if (x1 <= x0)
337 return y0;
338 return y0 + (y1 - y0) * (x - x0) / (x1 - x0);
339}
std::vector< glm::vec2 > * points
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23

References points, and window.