Class Interpolator
- Direct Known Subclasses:
NumberTangentInterpolator
,SplineInterpolator
interpolate
methods, which are
used to calculate interpolated values. Various built-in implementations of
this class are offered. Applications may choose to implement their own
Interpolator
to get custom interpolation behavior.
A custom Interpolator
has to be defined in terms of a "
curve()
".
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Interpolator
Built-in interpolator that provides discrete time interpolation.static final Interpolator
Built-in interpolator instance that provides ease in/out behavior.static final Interpolator
Built-in interpolator instance that provides ease in behavior.static final Interpolator
Built-in interpolator instance that provides ease out behavior.static final Interpolator
Built-in interpolator that provides linear time interpolation. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract double
curve
(double t) Mapping from [0.0..1.0] to itself.boolean
interpolate
(boolean startValue, boolean endValue, double fraction) This method takes twoboolean
values along with afraction
between0.0
and1.0
and returns the interpolated value.double
interpolate
(double startValue, double endValue, double fraction) This method takes twodouble
values along with afraction
between0.0
and1.0
and returns the interpolated value.int
interpolate
(int startValue, int endValue, double fraction) This method takes twoint
values along with afraction
between0.0
and1.0
and returns the interpolated value.long
interpolate
(long startValue, long endValue, double fraction) This method takes twoint
values along with afraction
between0.0
and1.0
and returns the interpolated value.interpolate
(Object startValue, Object endValue, double fraction) This method takes twoObjects
along with afraction
between0.0
and1.0
and returns the interpolated value.static Interpolator
SPLINE
(double x1, double y1, double x2, double y2) Creates anInterpolator
, whichcurve()
is shaped using the spline control points defined by (x1
,y1
) and (x2
,y2
).
-
Field Details
-
DISCRETE
Built-in interpolator that provides discrete time interpolation. The return value ofinterpolate()
isendValue
only when the inputfraction
is 1.0, andstartValue
otherwise. -
LINEAR
Built-in interpolator that provides linear time interpolation. The return value ofinterpolate()
isstartValue
+ (endValue
-startValue
) *fraction
. -
EASE_BOTH
Built-in interpolator instance that provides ease in/out behavior.An ease-both interpolator will make an animation start slow, then accelerate and slow down again towards the end, all in a smooth manner.
The implementation uses the algorithm for easing defined in SMIL 3.0 with an acceleration and deceleration factor of 0.2, respectively.
-
EASE_IN
Built-in interpolator instance that provides ease in behavior.An ease-in interpolator will make an animation start slow and then accelerate smoothly.
The implementation uses the algorithm for easing defined in SMIL 3.0 with an acceleration factor of 0.2.
-
EASE_OUT
Built-in interpolator instance that provides ease out behavior.An ease-out interpolator will make an animation slow down toward the end smoothly.
The implementation uses the algorithm for easing defined in SMIL 3.0 with an deceleration factor of 0.2.
-
-
Constructor Details
-
Interpolator
protected Interpolator()The constructor ofInterpolator
.
-
-
Method Details
-
SPLINE
Creates anInterpolator
, whichcurve()
is shaped using the spline control points defined by (x1
,y1
) and (x2
,y2
). The anchor points of the spline are implicitly defined as (0.0
,0.0
) and (1.0
,1.0
).- Parameters:
x1
- x coordinate of the first control pointy1
- y coordinate of the first control pointx2
- x coordinate of the second control pointy2
- y coordinate of the second control point- Returns:
- A spline interpolator
-
interpolate
This method takes twoObjects
along with afraction
between0.0
and1.0
and returns the interpolated value.If both
Objects
implementNumber
, their values are interpolated. IfstartValue
implementsInterpolatable
the calculation defined ininterpolate()
is used. If neither of these conditions are met, a discrete interpolation is used, i.e.endValue
is returned if and only iffraction
is1.0
, otherwisestartValue
is returned.Before calculating the interpolated value, the fraction is altered according to the function defined in
curve()
.- Parameters:
startValue
- start valueendValue
- end valuefraction
- a value between 0.0 and 1.0- Returns:
- interpolated value
-
interpolate
public boolean interpolate(boolean startValue, boolean endValue, double fraction) This method takes twoboolean
values along with afraction
between0.0
and1.0
and returns the interpolated value.Before calculating the interpolated value, the fraction is altered according to the function defined in
curve()
.- Parameters:
startValue
- the first data pointendValue
- the second data pointfraction
- the fraction in[0.0...1.0]
-
interpolate
public double interpolate(double startValue, double endValue, double fraction) This method takes twodouble
values along with afraction
between0.0
and1.0
and returns the interpolated value.Before calculating the interpolated value, the fraction is altered according to the function defined in
curve()
.- Parameters:
startValue
- the first data pointendValue
- the second data pointfraction
- the fraction in[0.0...1.0]
-
interpolate
public int interpolate(int startValue, int endValue, double fraction) This method takes twoint
values along with afraction
between0.0
and1.0
and returns the interpolated value.Before calculating the interpolated value, the fraction is altered according to the function defined in
curve()
.- Parameters:
startValue
- the first data pointendValue
- the second data pointfraction
- the fraction in[0.0...1.0]
-
interpolate
public long interpolate(long startValue, long endValue, double fraction) This method takes twoint
values along with afraction
between0.0
and1.0
and returns the interpolated value.Before calculating the interpolated value, the fraction is altered according to the function defined in
curve()
.- Parameters:
startValue
- the first data pointendValue
- the second data pointfraction
- the fraction in[0.0...1.0]
-
curve
protected abstract double curve(double t) Mapping from [0.0..1.0] to itself.- Parameters:
t
- time, but normalized to the range [0.0..1.0], where 0.0 is the start of the current interval, while 1.0 is the end of the current interval. Usually a function that increases monotonically.
-