Bezier interpolation code is now in a dedicated function and can be
used to either find a Y from a known X or a X from a known Y, with a
given allowed error.
Using switch allows (some) compilers to emit a warning if a possible
enum value for the interpolation type has been forgotten. This is not
the case now, but might guard against future errors (e.g. adding an
interpolation type)
- GetValue() calculates the value at the given position now ondemand,
without caching values as previously. First, it uses binary search
to find the segment (start and end point) containing the given
position. Constant and linear interpolation are straightforward,
bezier curves are calculating by binary search between the end
points until a point on the curve is found with a X coordinate close
enough to the given position. That points Y coordinate is returned.
- IsIncreasing(), GetRepeatFraction(), GetDelta() use GetValue()
instead of accessing the (removed) Values vector.
- Removed now unused private functions, and the unused public
Process().
First test results show good performance improvements for the
"rendering case" (setting up the keyframe points at once, then getting
all values) and drastic performance improvements for the "preview
case" (changing keyframe points, mixed with getting values).
Returning a non constant reference is not possible; this allows
outside code to invalidate internal invariants (sorted order of
points) by modifying the returned point. To make updates the current
best approach is to remove the point by index, and then add it again.
AddPoint() now searches (binary search) for the best place to insert a
new point, thus always maintaining the order of Points. Therefore,
ReorderPoints() is no longer needed.
CAVEAT: This breaks if some outside code changes (the public member)
Points!
With few points the performance doesn't differ that much; using
std::sort removes the possibility of introducing bugs into the
handmade sorting algorithm, though.
GetInt(), GetLong() are exactly the same as GetValue() except that
their result is rounded and converted to the repsective data type.
Thus avoid code duplication and use GetValue().
The previous values do not influence the return value of the function
nor does looping over them have any side effect.
The next_repeats value is not used in any way, thus it doesn't need to
be calculated.