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_INTERFACES_INNER_API_ACE_KIT_INCLUDE_BASE_GEOMETRY_POINT_H 17 #define FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_BASE_GEOMETRY_POINT_H 18 19 #include "ui/base/geometry/offset.h" 20 #include "ui/base/macros.h" 21 #include "ui/base/utils/utils.h" 22 23 #include "core/event/ace_events.h" 24 25 namespace OHOS::Ace { 26 27 class ACE_EXPORT Point { 28 public: 29 Point() = default; 30 ~Point() = default; Point(double x,double y)31 Point(double x, double y) : x_(x), y_(y) {} Point(double x,double y,SourceType sourceType)32 Point(double x, double y, SourceType sourceType) : x_(x), y_(y), sourceType_(sourceType) {} Point(double x,double y,double screenX,double screenY)33 Point(double x, double y, double screenX, double screenY) : x_(x), y_(y), screenX_(screenX), screenY_(screenY) {} Point(double x,double y,double screenX,double screenY,SourceType sourceType)34 Point(double x, double y, double screenX, double screenY, SourceType sourceType) 35 : x_(x), y_(y), screenX_(screenX), screenY_(screenY), sourceType_(sourceType) 36 {} 37 Point(double x,double y,double screenX,double screenY,double globalDisplayX,double globalDisplayY)38 Point(double x, double y, double screenX, double screenY, double globalDisplayX, double globalDisplayY) 39 : x_(x), y_(y), screenX_(screenX), screenY_(screenY), globalDisplayX_(globalDisplayX), 40 globalDisplayY_(globalDisplayY) 41 {} Point(double x,double y,double screenX,double screenY,double globalDisplayX,double globalDisplayY,SourceType sourceType)42 Point(double x, double y, double screenX, double screenY, double globalDisplayX, double globalDisplayY, 43 SourceType sourceType) 44 : x_(x), y_(y), screenX_(screenX), screenY_(screenY), globalDisplayX_(globalDisplayX), 45 globalDisplayY_(globalDisplayY), sourceType_(sourceType) 46 {} 47 GetX()48 double GetX() const 49 { 50 return x_; 51 } 52 GetY()53 double GetY() const 54 { 55 return y_; 56 } 57 SetX(double x)58 void SetX(double x) 59 { 60 x_ = x; 61 } 62 SetY(double y)63 void SetY(double y) 64 { 65 y_ = y; 66 } 67 GetScreenX()68 double GetScreenX() const 69 { 70 return screenX_; 71 } 72 GetScreenY()73 double GetScreenY() const 74 { 75 return screenY_; 76 } 77 SetScreenX(double x)78 void SetScreenX(double x) 79 { 80 screenX_ = x; 81 } 82 SetScreenY(double y)83 void SetScreenY(double y) 84 { 85 screenY_ = y; 86 } 87 GetGlobalDisplayX()88 double GetGlobalDisplayX() const 89 { 90 return globalDisplayX_; 91 } 92 GetGlobalDisplayY()93 double GetGlobalDisplayY() const 94 { 95 return globalDisplayY_; 96 } 97 SetGlobalDisplayX(double x)98 void SetGlobalDisplayX(double x) 99 { 100 globalDisplayX_ = x; 101 } 102 SetGlobalDisplayY(double y)103 void SetGlobalDisplayY(double y) 104 { 105 globalDisplayY_ = y; 106 } 107 SetSourceType(SourceType sourceType)108 void SetSourceType(SourceType sourceType) 109 { 110 sourceType_ = sourceType; 111 } 112 GetSourceType()113 SourceType GetSourceType() const 114 { 115 return sourceType_; 116 } 117 Rotate(const Point & center,double angle)118 void Rotate(const Point& center, double angle) 119 { 120 double x = (x_ - center.GetX()) * std::cos(angle) - (y_ - center.GetY()) * std::sin(angle) + center.GetX(); 121 double y = (x_ - center.GetX()) * std::sin(angle) + (y_ - center.GetY()) * std::cos(angle) + center.GetY(); 122 x_ = x; 123 y_ = y; 124 } 125 126 Point operator-(const Offset& offset) const 127 { 128 return Point(x_ - offset.GetX(), y_ - offset.GetY()); 129 } 130 131 Point operator+(const Offset& offset) const 132 { 133 return Point(x_ + offset.GetX(), y_ + offset.GetY()); 134 } 135 136 Offset operator-(const Point& point) const 137 { 138 return Offset(x_ - point.x_, y_ - point.y_); 139 } 140 141 bool operator==(const Point& point) const 142 { 143 return NearEqual(x_, point.x_) && NearEqual(y_, point.y_); 144 } 145 146 bool operator!=(const Point& point) const 147 { 148 return !operator==(point); 149 } 150 151 private: 152 double x_ = 0.0; 153 double y_ = 0.0; 154 double screenX_ = 0.0; 155 double screenY_ = 0.0; 156 double globalDisplayX_ = 0.0; 157 double globalDisplayY_ = 0.0; 158 SourceType sourceType_ = SourceType::NONE; 159 }; 160 161 } // namespace OHOS::Ace 162 163 #endif // FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_BASE_GEOMETRY_POINT_H 164