Interpolators

Inherits: Object

Tracks interpolation functions for various data types

Description

The interpolation system can be used to interpolate arbitrary values, regardless of their types. This is done by keeping a list of interpolators, with each handling a specific data type. These can be registered using register().

Later on, these values can either be interpolated using interpolate(), or getting the interpolation function using find_for() and calling it.

By default, this class supports most built-in data types, aside from objects, arrays, and dictionaries. Custom interpolators can be registered, and will take precedence over built-in ones.

Tutorials

Properties

Type Name Default
Interpolators.Interpolator DEFAULT_INTERPOLATOR make(...)
Interpolators.Interpolator[] interpolators
Callable default_apply <unknown>

Methods

Return Type Name
void register(Callable is_applicable, Callable apply) static
Callable find_for(Variant value) static
Interpolators.Interpolator find_interpolator_for(Variant value) static
Variant interpolate(Variant a, Variant b, float f) static

Property Descriptions

Interpolators.Interpolator DEFAULT_INTERPOLATOR = make(...)

Fallback interpolator.

Returns the starting value in the first half of the tick, and the target value in the other half.


Interpolators.Interpolator[] interpolators

List of known interpolators.

This list is used to look up interpolators in find_for() and find_interpolator_for(). The list is ordered - the earlier an interpolator is in the list, the higher its precedence.

Do not modify - use register() instead.


Callable default_apply = <unknown>

Default interpolation function


Method Descriptions

void register ( Callable is_applicable, Callable apply ) static

Register an interpolator.

New interpolators are pushed to the front of the list, making them have precedence over existing ones. This can be useful in case you want to override the built-in interpolators.


Callable find_for ( Variant value ) static

Find the appropriate interpolator for the given value.

If none was found, returns the default interpolator.


Interpolators.Interpolator find_interpolator_for ( Variant value ) static

Find the appropriate interpolator instance for the given value.

If none was found, returns the default interpolator.


Variant interpolate ( Variant a, Variant b, float f ) static

Interpolate between two values.

Note that this method looks up the appropriate interpolator using find_for() on every call. It is faster to call find_for() once, and call the resulting Callable repeatedly.