RFR: 8372203: Piecewise linear easing function

Michael Strauß mstrauss at openjdk.org
Sat Nov 22 08:51:40 UTC 2025


On Fri, 21 Nov 2025 21:40:57 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

>> Implementation of the [linear](https://www.w3.org/TR/css-easing-2/#the-linear-easing-function) easing function, which is now widely supported by all browsers, but still missing in JavaFX.
>> 
>> It allows developers to approximate arbitrary easing functions with linear segments:
>> 
>> 
>> linear(
>>     /* Start to 1st bounce */
>>     0, 0.063, 0.25, 0.563, 1 36.4%,
>>     /* 1st to 2nd bounce */
>>     0.812, 0.75, 0.813, 1 72.7%,
>>     /* 2nd to 3rd bounce */
>>     0.953, 0.938, 0.953, 1 90.9%,
>>     /* 3rd bounce to end */
>>     0.984, 1 100% 100%
>>   )
>> 
>> 
>> <img src="https://github.com/user-attachments/assets/73aac0d4-0185-47c5-8791-bdb247eb69c8" width="400"/>
>
> modules/javafx.graphics/src/main/java/com/sun/scenario/animation/LinearInterpolator.java line 76:
> 
>> 74:         // Ensure that the input progress value of each control point is greater than or equal to the
>> 75:         // input progress values of all preceding control points (monotonically non-decreasing).
>> 76:         double largestX = controlPoints[0];
> 
> Question: what happens when a esquence is specified which is somehow invalid?  Will it throw an exception, write to stderr, or silently ignore?
> 
> (I can't think of an invalid sequence, maybe `0, 0 0% 0%, 0 -10%, NaN` ?)

The sequence will always be successfully canonicalized, so there's never a log output or exception. In your example, the canonicalized easing function will be 0 for t=0, and NaN for t>0. If you use this function in an animation, you may get weird values and undefined things may happen. This is not unique to easing functions: we almost never handle NaNs in JavaFX. For example, you can construct a `Color` with NaN components (which is what would happen if you used your easing function in a color transition).

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1977#discussion_r2552633277


More information about the openjfx-dev mailing list