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