1 /*
2  * Copyright (c) 2021 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_GESTURES_VELOCITY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_VELOCITY_H
18 
19 #include "base/geometry/offset.h"
20 
21 namespace OHOS::Ace {
22 
23 class Velocity final {
24 public:
25     Velocity() = default;
Velocity(const Offset & offsetPerSecond)26     explicit Velocity(const Offset& offsetPerSecond) : offsetPerSecond_(offsetPerSecond) {}
27     ~Velocity() = default;
28 
Reset()29     void Reset()
30     {
31         offsetPerSecond_.Reset();
32     }
33 
SetOffsetPerSecond(const Offset & offsetPerSecond)34     void SetOffsetPerSecond(const Offset& offsetPerSecond)
35     {
36         offsetPerSecond_ = offsetPerSecond;
37     }
38 
39     Velocity operator+(const Velocity& velocity) const
40     {
41         return Velocity(offsetPerSecond_ + velocity.offsetPerSecond_);
42     }
43 
44     Velocity operator-(const Velocity& velocity) const
45     {
46         return Velocity(offsetPerSecond_ - velocity.offsetPerSecond_);
47     }
48 
49     Velocity operator*(double value) const
50     {
51         return Velocity(offsetPerSecond_ * value);
52     }
53 
54     Velocity& operator+=(const Velocity& velocity)
55     {
56         offsetPerSecond_ += velocity.offsetPerSecond_;
57         return *this;
58     }
59 
60     bool operator==(const Velocity& velocity) const
61     {
62         return offsetPerSecond_ == velocity.offsetPerSecond_;
63     }
64 
65     bool operator!=(const Velocity& velocity) const
66     {
67         return !operator==(velocity);
68     }
69 
GetOffsetPerSecond()70     const Offset& GetOffsetPerSecond() const
71     {
72         return offsetPerSecond_;
73     }
74 
GetVelocityX()75     double GetVelocityX() const
76     {
77         return offsetPerSecond_.GetX();
78     }
79 
GetVelocityY()80     double GetVelocityY() const
81     {
82         return offsetPerSecond_.GetY();
83     }
84 
GetVelocityValue()85     double GetVelocityValue() const
86     {
87         return offsetPerSecond_.GetDistance();
88     }
89 
90 private:
91     Offset offsetPerSecond_;
92 };
93 
94 } // namespace OHOS::Ace
95 
96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_GESTURES_VELOCITY_H
97