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) {} Point(double x,double y,double screenX,double screenY)32 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)33 Point(double x, double y, double screenX, double screenY, SourceType sourceType) 34 : x_(x), y_(y), screenX_(screenX), screenY_(screenY), sourceType_(sourceType) 35 {} 36 GetX()37 double GetX() const 38 { 39 return x_; 40 } 41 GetY()42 double GetY() const 43 { 44 return y_; 45 } 46 SetX(double x)47 void SetX(double x) 48 { 49 x_ = x; 50 } 51 SetY(double y)52 void SetY(double y) 53 { 54 y_ = y; 55 } 56 GetScreenX()57 double GetScreenX() const 58 { 59 return screenX_; 60 } 61 GetScreenY()62 double GetScreenY() const 63 { 64 return screenY_; 65 } 66 SetScreenX(double x)67 void SetScreenX(double x) 68 { 69 screenX_ = x; 70 } 71 SetScreenY(double y)72 void SetScreenY(double y) 73 { 74 screenY_ = y; 75 } 76 SetSourceType(SourceType sourceType)77 void SetSourceType(SourceType sourceType) 78 { 79 sourceType_ = sourceType; 80 } 81 GetSourceType()82 SourceType GetSourceType() const 83 { 84 return sourceType_; 85 } 86 Rotate(const Point & center,double angle)87 void Rotate(const Point& center, double angle) 88 { 89 double x = (x_ - center.GetX()) * std::cos(angle) - (y_ - center.GetY()) * std::sin(angle) + center.GetX(); 90 double y = (x_ - center.GetX()) * std::sin(angle) + (y_ - center.GetY()) * std::cos(angle) + center.GetY(); 91 x_ = x; 92 y_ = y; 93 } 94 95 Point operator-(const Offset& offset) const 96 { 97 return Point(x_ - offset.GetX(), y_ - offset.GetY()); 98 } 99 100 Point operator+(const Offset& offset) const 101 { 102 return Point(x_ + offset.GetX(), y_ + offset.GetY()); 103 } 104 105 Offset operator-(const Point& point) const 106 { 107 return Offset(x_ - point.x_, y_ - point.y_); 108 } 109 110 bool operator==(const Point& point) const 111 { 112 return NearEqual(x_, point.x_) && NearEqual(y_, point.y_); 113 } 114 115 bool operator!=(const Point& point) const 116 { 117 return !operator==(point); 118 } 119 120 private: 121 double x_ = 0.0; 122 double y_ = 0.0; 123 double screenX_ = 0.0; 124 double screenY_ = 0.0; 125 SourceType sourceType_ = SourceType::NONE; 126 }; 127 128 } // namespace OHOS::Ace 129 130 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_POINT_H 131