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 /**
17  * @addtogroup GraphicGeometry
18  * @{
19  *
20  * @brief Defines ClippingFlagsE, ClipMovePoint, ClipLineSegment.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  *
28  * @brief Defines Cutting related methods
29  *
30  * @since 1.0
31  * @version 1.0
32  */
33 
34 #ifndef GRAPHIC_LITE_COMMON_CLIP_OPERATE_H
35 #define GRAPHIC_LITE_COMMON_CLIP_OPERATE_H
36 
37 #include "gfx_utils/diagram/common/common_basics.h"
38 
39 #include <gfx_utils/rect.h>
40 
41 namespace OHOS {
42 const int32_t CLIP_LINE_SEGMENT_FULL_VISIB = 0; // Fully visible
43 const int32_t CLIP_LINE_SEGMENT_FULL_CLIP = 4;  // Full clipping
44 /**
45  *   0110  |  0010  | 0011
46  *         |        |
47  *  -------+--------+-------- clipBox.y2
48  *         |        |
49  *   0100  |  0000  | 0001
50  *         |        |
51  *  -------+--------+-------- clipBox.y1
52  *         |        |
53  *   1100  |  1000  | 1001
54  *         |        |
55  * clipBox.x1 clipBox.x2
56  * @brief Determine the position of Y and cut it longitudinally
57  * @param Y vertical position, Clipbox clipping window
58  * @return Return the corresponding area code
59  * @since 1.0
60  * @version 1.0
61  */
62 template <class T>
ClippingFlagsY(T y,const CommonRect<T> & clipBox)63 inline uint32_t ClippingFlagsY(T y, const CommonRect<T>& clipBox)
64 {
65     return ((y < clipBox.GetTop()) << 0x03) | ((y > clipBox.GetBottom()) << 0x01);
66 }
67 
68 /**
69  * @brief Determine the position of X and cut horizontally
70  * @param X horizontal position, Clipbox clipping window
71  * @return Return the corresponding area code
72  * @since 1.0
73  * @version 1.0
74  */
75 template <class T>
ClippingFlagsX(T x,const CommonRect<T> & clipBox)76 inline uint32_t ClippingFlagsX(T x, const CommonRect<T>& clipBox)
77 {
78     return ((x < clipBox.GetLeft()) << 0x02) | (x > clipBox.GetRight());
79 }
80 
81 /**
82  * @brief The clipping of vertices is determined according to the position of vertices
83  * @param x. y vertex position, Clipbox clipping window
84  * @return Return the corresponding area code
85  * @since 1.0
86  * @version 1.0
87  */
88 template <class T>
ClippingFlags(T x,T y,const CommonRect<T> & clipBox)89 inline uint32_t ClippingFlags(T x, T y, const CommonRect<T>& clipBox)
90 {
91     return ((x < clipBox.GetLeft()) << 0x02) | ((y < clipBox.GetTop()) << 0x03) |
92      (x > clipBox.GetRight()) | ((y > clipBox.GetBottom()) << 0x01);
93 }
94 } // namespace OHOS
95 #endif
96