• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "animation/rs_spring_interpolator.h"
17 
18 #include <algorithm>
19 #include <cmath>
20 
21 #include "platform/common/rs_log.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 
RSSpringInterpolator(float response,float dampingRatio,float initialVelocity)26 RSSpringInterpolator::RSSpringInterpolator(float response, float dampingRatio, float initialVelocity)
27     // initialOffset: 1, minimumAmplitude: 0.0001
28     : RSSpringModel<float>(response, dampingRatio, -1, initialVelocity, 0.0001)
29 {
30     estimatedDuration_ = EstimateDuration();
31 }
32 
RSSpringInterpolator(uint64_t id,float response,float dampingRatio,float initialVelocity)33 RSSpringInterpolator::RSSpringInterpolator(uint64_t id, float response, float dampingRatio, float initialVelocity)
34     // initialOffset: 1, minimumAmplitude: 0.0001
35     : RSSpringModel<float>(response, dampingRatio, -1, initialVelocity, 0.0001), RSInterpolator(id)
36 {
37     estimatedDuration_ = EstimateDuration();
38 }
39 
InterpolateImpl(float fraction) const40 float RSSpringInterpolator::InterpolateImpl(float fraction) const
41 {
42     if (fraction <= 0) {
43         return 0;
44     } else if (fraction >= 1.0f) {
45         return 1.0f;
46     }
47     // map [0, 1] to [0, duration], and calculate the output value
48     double mappedTime = fraction * estimatedDuration_;
49     return 1.0f + CalculateDisplacement(mappedTime);
50 }
51 } // namespace Rosen
52 } // namespace OHOS
53