• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SPRING_CURVE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SPRING_CURVE_H
18 
19 #include "core/animation/curve.h"
20 #include "core/animation/spring_motion.h"
21 
22 namespace OHOS::Ace {
23 
24 class ACE_EXPORT SpringCurve : public Curve {
25     DECLARE_ACE_TYPE(SpringCurve, Curve);
26 
27 public:
28     SpringCurve(float velocity, float mass, float stiffness, float damping);
29     ~SpringCurve() override = default;
30 
31     float MoveInternal(float time) override;
32     const std::string ToString() override;
33 
34 private:
35     void SetEndPosition(float endPosition, float startVelocity);
36     void InitEstimateDuration();
37 
38     float estimateDuration_ = 1.0f;
39     float startPosition_ = 0.0f;
40     float endPosition_ = 0.0f;
41     float currentVelocity_ = 0.0f;
42     float currentPosition_ = 0.0f;
43     float velocityThreshold_ = 0.001f;
44     float valueThreshold_ = 0.001f;
45     float velocity_ = 0.0f;
46     float mass_ = 0.0f;
47     float stiffness_ = 0.0f;
48     float damping_ = 0.0f;
49     RefPtr<SpringProperty> property_; // Contain: mass & stiffness & damping
50     RefPtr<SpringModel> solution_; // Maybe: CriticalDamped or Overdamped or Underdamped
51 
52     friend class NativeCurveHelper;
53 };
54 
55 } // // namespace OHOS::Ace
56 
57 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SPRING_CURVE_H