• 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 POINT_H
17 #define POINT_H
18 
19 #include "offset.h"
20 #include "utils.h"
21 
22 namespace OHOS::uitest {
23 class Point {
24 public:
25     Point() = default;
26     ~Point() = default;
Point(double x,double y)27     Point(double x, double y) : x_(x), y_(y) {}
28 
GetX()29     double GetX() const
30     {
31         return x_;
32     }
33 
GetY()34     double GetY() const
35     {
36         return y_;
37     }
38 
SetX(double x)39     void SetX(double x)
40     {
41         x_ = x;
42     }
43 
SetY(double y)44     void SetY(double y)
45     {
46         y_ = y;
47     }
48 
49     Point operator-(const Offset& offset) const
50     {
51         return Point(x_ - offset.GetX(), y_ - offset.GetY());
52     }
53 
54     Point operator+(const Offset& offset) const
55     {
56         return Point(x_ + offset.GetX(), y_ + offset.GetY());
57     }
58 
59     Offset operator-(const Point& point) const
60     {
61         return Offset(x_ - point.x_, y_ - point.y_);
62     }
63 
64     bool operator==(const Point& point) const
65     {
66         return NearEqual(x_, point.x_) && NearEqual(y_, point.y_);
67     }
68 
69     bool operator!=(const Point& point) const
70     {
71         return !operator==(point);
72     }
73 
74 private:
75     double x_ = 0.0;
76     double y_ = 0.0;
77 };
78 } // namespace OHOS::uitest
79 #endif // POINT_H
80