• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /** Provide a bouncing Easing function */
19 public class ElasticOutCurve extends Easing {
20     private static final float F_PI = (float) Math.PI;
21     private static final float C4 = 2 * F_PI / 3;
22     private static final float TWENTY_PI = 20 * F_PI;
23     private static final float LOG_8 = (float) Math.log(8.0f);
24 
25     @Override
get(float x)26     public float get(float x) {
27         if (x <= 0) {
28             return 0.0f;
29         }
30         if (x >= 1) {
31             return 1.0f;
32         } else return (float) (Math.pow(2.0f, -10 * x) * Math.sin((x * 10 - 0.75f) * C4) + 1);
33     }
34 
35     @Override
getDiff(float x)36     public float getDiff(float x) {
37         if (x < 0 || x > 1) {
38             return 0.0f;
39         } else
40             return (float)
41                     (5
42                             * Math.pow(2.0f, 1 - 10 * x)
43                             * (LOG_8 * Math.cos(TWENTY_PI * x / 3)
44                                     + 2 * F_PI * Math.sin(TWENTY_PI * x / 3))
45                             / 3);
46     }
47 }
48