1 /* 2 * Copyright (c) 2021 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_ARC_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_ARC_H 18 19 #include "base/geometry/point.h" 20 #include "base/utils/utils.h" 21 22 #define PI_NUM 3.1415926f 23 24 namespace OHOS::Ace { 25 26 class Arc { 27 public: 28 Arc() = default; 29 ~Arc() = default; 30 GetCenterPoint()31 const Point& GetCenterPoint() const 32 { 33 return centerPoint_; 34 } 35 SetCenterPoint(const Point & point)36 void SetCenterPoint(const Point& point) 37 { 38 centerPoint_ = point; 39 } 40 GetRadius()41 double GetRadius() const 42 { 43 return radius_; 44 } 45 SetRadius(double radius)46 void SetRadius(double radius) 47 { 48 radius_ = radius; 49 } 50 GetStartAngle()51 double GetStartAngle() const 52 { 53 return startAngle_; 54 } 55 SetStartAngle(double angle)56 void SetStartAngle(double angle) 57 { 58 startAngle_ = angle; 59 } 60 GetEndAngle()61 double GetEndAngle() const 62 { 63 return endAngle_; 64 } 65 SetEndAngle(double angle)66 void SetEndAngle(double angle) 67 { 68 endAngle_ = angle; 69 } 70 GetSweepAngle()71 double GetSweepAngle() const 72 { 73 return endAngle_ - startAngle_; 74 } 75 Rotate(const Point & point,double angle)76 void Rotate(const Point& point, double angle) 77 { 78 centerPoint_.Rotate(point, angle); 79 startAngle_ += angle; 80 endAngle_ += angle; 81 } 82 Move(double xOffset,double yOffset)83 void Move(double xOffset, double yOffset) 84 { 85 centerPoint_.SetX(centerPoint_.GetX() + xOffset); 86 centerPoint_.SetY(centerPoint_.GetY() + yOffset); 87 } 88 GetPointByAngle(double angle,Point & out)89 void GetPointByAngle(double angle, Point& out) const 90 { 91 out.SetX(centerPoint_.GetX() + radius_); 92 out.SetY(centerPoint_.GetY()); 93 out.Rotate(centerPoint_, angle); 94 } 95 GetStartPoint(Point & out)96 void GetStartPoint(Point& out) const 97 { 98 GetPointByAngle(startAngle_, out); 99 } 100 GetEndPoint(Point & out)101 void GetEndPoint(Point& out) const 102 { 103 GetPointByAngle(endAngle_, out); 104 } 105 GetStartPoint()106 Point GetStartPoint() const 107 { 108 Point startPoint; 109 GetStartPoint(startPoint); 110 return startPoint; 111 } 112 GetEndPoint()113 Point GetEndPoint() const 114 { 115 Point endPoint; 116 GetEndPoint(endPoint); 117 return endPoint; 118 } 119 GetLeft()120 double GetLeft() const 121 { 122 return centerPoint_.GetX() - radius_; 123 } 124 GetRight()125 double GetRight() const 126 { 127 return centerPoint_.GetX() + radius_; 128 } 129 GetTop()130 double GetTop() const 131 { 132 return centerPoint_.GetY() - radius_; 133 } 134 GetBottom()135 double GetBottom() const 136 { 137 return centerPoint_.GetY() + radius_; 138 } 139 140 private: 141 Point centerPoint_; 142 double radius_ = 0.0; 143 double startAngle_ = 0.0; 144 double endAngle_ = 0.0; 145 }; 146 147 } // namespace OHOS::Ace 148 149 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_ARC_H 150