1 /*
2  * Copyright (c) 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 GRAPHIC_LITE_GEOMETRY_ARC_H
17 #define GRAPHIC_LITE_GEOMETRY_ARC_H
18 
19 #include "gfx_utils/diagram/common/common_basics.h"
20 #include "gfx_utils/heap_base.h"
21 namespace OHOS {
22 /**
23  * @file graphic_geometry_arc.h
24  *
25  * @brief Defines Arc class.
26  *
27  * @since 1.0
28  * @version 1.0
29  */
30 class GeometryArc : public HeapBase {
31 #if defined(GRAPHIC_ENABLE_ARC_FLAG) && GRAPHIC_ENABLE_ARC_FLAG
32 public:
GeometryArc()33     GeometryArc() : initialized_(false), pathCommand_(0.0f), centerX_(0.0f),
34                     centerY_(0.0f), radiusX_(0.0f), radiusY_(0.0f),
35                     currentAngle_(0.0f), beginAngle_(0.0f), endAngle_(0.0f),
36                     expansionRatio_(1.0f), deltaAngle_(0.0f), isClockwise_(false) {}
37 
38     /**
39      * @brief Constructor arc.
40      * @param centerX,centerY Arc Center.
41      * @param rx Ellipse Arc Transverse Axis Radius.
42      * @param ry Ellipse Arc Vertical Axis Radius.
43      * @param angle1,angle2 Starting angle.
44      * @param isClockwise Is the arc clockwise.
45      * @since 1.0
46      * @version 1.0
47      */
48     GeometryArc(float centerX, float centerY,
49         float rx, float ry,
50         float angle1, float angle2,
51         bool isClockwise = true);
52     /**
53      * @brief Set as Initial Step.
54      *
55      * @since 1.0
56      * @version 1.0
57      */
58     void Rewind(uint32_t);
59 
60     /**
61      * @brief Adjust approximation level correctly.
62      * @param scale Is the ratio between viewport coordinates and logical coordinates.
63      * @return void
64      * @since 1.0
65      * @version 1.0
66      */
67     void SetApproximationScale(float scale);
68 
69     /**
70      * @brief Get Approximation Level.
71      * @param scale Is the ratio between viewport coordinates and logical coordinates.
72      * @return void
73      * @since 1.0
74      * @version 1.0
75      */
GetApproximationScale()76     float GetApproximationScale() const
77     {
78         return expansionRatio_;
79     }
80 
81     /**
82      * @brief Called during the sampling phase.
83      * @param x Pointer to the value of point coordinate X£¬y A pointer to the value of the point coordinate y
84      * @return void
85      * @since 1.0
86      * @version 1.0
87      */
88     uint32_t GenerateVertex(float* y, float* x);
89     /**
90      * @brief Initialize an arc.
91      *
92      * @since 1.0
93      * @version 1.0
94      */
95     void Init(float centerX, float centerY, float rx, float ry,
96               float angle1, float angle2, bool isClockwise = true);
97 
98 private:
99     /**
100      * @brief Normalized arcs.
101      *
102      * @since 1.0
103      * @version 1.0
104      */
105     void Normalize(float angle1, float angle2, bool isClockwise);
106     bool initialized_;      // Is it Init
107     uint32_t pathCommand_;  // Connection Command
108     float centerX_;        // Center X-coordinate
109     float centerY_;        // Center Y-coordinate
110     float radiusX_;        // X Short semiaxis
111     float radiusY_;        // Y Long axis
112     float currentAngle_;   // Current Angle
113     float beginAngle_;     // Starting angle
114     float endAngle_;       // End angle
115     float expansionRatio_; // Scaling ratio
116     float deltaAngle_;     // Rate of radian change
117     bool isClockwise_;      // direction
118 #endif
119 };
120 } // namespace OHOS
121 
122 #endif
123