19 for (
size_t i = 0; i + 1 < data.size(); i += 2) {
20 keys.emplace_back(data[i], data[i + 1]);
40 _eval = std::make_unique<CurveEvaluator>(
this);
45 :
keys(std::move(other.keys)),
type(other.type),
tension(other.tension), _eval(std::make_unique<CurveEvaluator>(
this))
55 keys = std::move(other.keys);
58 _eval = std::make_unique<CurveEvaluator>(
this);
66 const auto key = std::make_pair(time,
value);
67 const size_t len =
keys.size();
70 for (; i < len; i++) {
71 if (
keys[i].first > time) {
76 keys.insert(
keys.begin() +
static_cast<std::ptrdiff_t
>(i), key);
80 std::pair<float, float>
Curve::get(
const size_t index)
const
87 std::sort(
keys.begin(),
keys.end(), [](
const auto& a,
const auto& b) {
88 return a.first < b.first;
94 return _eval->evaluate(time,
true);
99 const size_t len =
keys.size();
105 std::pair<float, float> result =
keys.front();
107 for (
size_t i = 0; i < len; i++) {
108 const float diff = std::abs(time -
keys[i].first);
131 precision = std::max<size_t>(precision, 2);
133 std::vector<float> values(precision, 0.0f);
134 const float step = 1.0f /
static_cast<float>(precision - 1);
136 values[0] = _eval->evaluate(0.0f,
true);
137 for (
size_t i = 1; i < precision; ++i) {
138 values[i] = _eval->evaluate(step *
static_cast<float>(i));
147 for (
auto& v : result) {
148 v = std::min(max, std::max(min, v));
std::vector< float > quantizeClamped(size_t precision, float min, float max)
std::pair< float, float > add(float time, float value)
std::vector< std::pair< float, float > > keys
Curve & operator=(const Curve &other)
std::pair< float, float > get(size_t index) const
std::vector< float > quantize(size_t precision)
std::pair< float, float > closest(float time) const