1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.internal.widget.remotecompose.core.operations.utilities.easing; 17 18 /** 19 * Provide a bouncing Easing function 20 */ 21 public class ElasticOutCurve extends Easing { 22 private static final float F_PI = (float) Math.PI; 23 private static final float C4 = 2 * F_PI / 3; 24 private static final float TWENTY_PI = 20 * F_PI; 25 private static final float LOG_8 = (float) Math.log(8.0f); 26 27 @Override get(float x)28 public float get(float x) { 29 if (x <= 0) { 30 return 0.0f; 31 } 32 if (x >= 1) { 33 return 1.0f; 34 } else 35 return (float) (Math.pow(2.0f, -10 * x) 36 * Math.sin((x * 10 - 0.75f) * C4) + 1); 37 } 38 39 @Override getDiff(float x)40 public float getDiff(float x) { 41 if (x < 0 || x > 1) { 42 return 0.0f; 43 } else 44 return (float) ((5 * Math.pow(2.0f, (1 - 10 * x)) 45 * (LOG_8 * Math.cos(TWENTY_PI * x / 3) + 2 46 * F_PI * Math.sin(TWENTY_PI * x / 3)) 47 / 3)); 48 } 49 } 50