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