• 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_BASE_GEOMETRY_POINT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_POINT_H
18 
19 #include "base/geometry/offset.h"
20 #include "base/utils/macros.h"
21 #include "base/utils/utils.h"
22 #include "core/event/ace_events.h"
23 
24 namespace OHOS::Ace {
25 
26 class ACE_EXPORT Point {
27 public:
28     Point() = default;
29     ~Point() = default;
Point(double x,double y)30     Point(double x, double y) : x_(x), y_(y) {}
Point(double x,double y,SourceType sourceType)31     Point(double x, double y, SourceType sourceType) : x_(x), y_(y), sourceType_(sourceType) {}
32 
GetX()33     double GetX() const
34     {
35         return x_;
36     }
37 
GetY()38     double GetY() const
39     {
40         return y_;
41     }
42 
SetX(double x)43     void SetX(double x)
44     {
45         x_ = x;
46     }
47 
SetY(double y)48     void SetY(double y)
49     {
50         y_ = y;
51     }
52 
SetSourceType(SourceType sourceType)53     void SetSourceType(SourceType sourceType)
54     {
55         sourceType_ = sourceType;
56     }
57 
GetSourceType()58     SourceType GetSourceType() const
59     {
60         return sourceType_;
61     }
62 
Rotate(const Point & center,double angle)63     void Rotate(const Point& center, double angle)
64     {
65         double x = (x_ - center.GetX()) * std::cos(angle) - (y_ - center.GetY()) * std::sin(angle) + center.GetX();
66         double y = (x_ - center.GetX()) * std::sin(angle) + (y_ - center.GetY()) * std::cos(angle) + center.GetY();
67         x_ = x;
68         y_ = y;
69     }
70 
71     Point operator-(const Offset& offset) const
72     {
73         return Point(x_ - offset.GetX(), y_ - offset.GetY());
74     }
75 
76     Point operator+(const Offset& offset) const
77     {
78         return Point(x_ + offset.GetX(), y_ + offset.GetY());
79     }
80 
81     Offset operator-(const Point& point) const
82     {
83         return Offset(x_ - point.x_, y_ - point.y_);
84     }
85 
86     bool operator==(const Point& point) const
87     {
88         return NearEqual(x_, point.x_) && NearEqual(y_, point.y_);
89     }
90 
91     bool operator!=(const Point& point) const
92     {
93         return !operator==(point);
94     }
95 
96 private:
97     double x_ = 0.0;
98     double y_ = 0.0;
99     SourceType sourceType_ = SourceType::NONE;
100 };
101 
102 } // namespace OHOS::Ace
103 
104 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_POINT_H
105