Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / utils / SkPolyUtils.h
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #ifndef SkOffsetPolygon_DEFINED
9 #define SkOffsetPolygon_DEFINED
10
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkScalar.h"
13
14 #include <stdint.h>
15
16 struct SkRect;
17 template <typename T> class SkTDArray;
18
19 /**
20  * Generates a polygon that is inset a constant from the boundary of a given convex polygon.
21  * The input polygon is expected to have values clamped to the nearest 1/16th.
22  *
23  * @param inputPolygonVerts  Array of points representing the vertices of the original polygon.
24  *  It should be convex and have no coincident points.
25  * @param inputPolygonSize  Number of vertices in the original polygon.
26  * @param inset  How far we wish to inset the polygon. This should be a positive value.
27  * @param insetPolygon  The resulting inset polygon, if any.
28  * @return true if an inset polygon exists, false otherwise.
29  */
30 bool SkInsetConvexPolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
31                           SkScalar inset, SkTDArray<SkPoint>* insetPolygon);
32
33 /**
34  * Generates a simple polygon (if possible) that is offset a constant distance from the boundary
35  * of a given simple polygon.
36  * The input polygon must be simple, have no coincident vertices or collinear edges, and have
37  * values clamped to the nearest 1/16th.
38  *
39  * @param inputPolygonVerts  Array of points representing the vertices of the original polygon.
40  * @param inputPolygonSize  Number of vertices in the original polygon.
41  * @param bounds Bounding rectangle for the original polygon.
42  * @param offset How far we wish to offset the polygon.
43  *   Positive values indicate insetting, negative values outsetting.
44  * @param offsetPolgon  The resulting offset polygon, if any.
45  * @param polygonIndices  The indices of the original polygon that map to the new one.
46  * @return true if an offset simple polygon exists, false otherwise.
47  */
48 bool SkOffsetSimplePolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
49                            const SkRect& bounds, SkScalar offset, SkTDArray<SkPoint>* offsetPolygon,
50                            SkTDArray<int>* polygonIndices = nullptr);
51
52 /**
53  * Compute the number of points needed for a circular join when offsetting a vertex.
54  * The lengths of offset0 and offset1 don't have to equal |offset| -- only the direction matters.
55  * The segment lengths will be approximately four pixels.
56  *
57  * @param offset0  Starting offset vector direction.
58  * @param offset1  Ending offset vector direction.
59  * @param offset  Offset value (can be negative).
60  * @param rotSin  Sine of rotation delta per step.
61  * @param rotCos  Cosine of rotation delta per step.
62  * @param n  Number of steps to fill out the arc.
63  * @return true for success, false otherwise
64  */
65 bool SkComputeRadialSteps(const SkVector& offset0, const SkVector& offset1, SkScalar offset,
66                           SkScalar* rotSin, SkScalar* rotCos, int* n);
67
68 /**
69  * Determine winding direction for a polygon.
70  * The input polygon must be simple or the result will be meaningless.
71  *
72  * @param polygonVerts  Array of points representing the vertices of the polygon.
73  * @param polygonSize  Number of vertices in the polygon.
74  * @return 1 for cw, -1 for ccw, and 0 if zero signed area (either degenerate or self-intersecting).
75  *         The y-axis is assumed to be pointing down.
76  */
77 int SkGetPolygonWinding(const SkPoint* polygonVerts, int polygonSize);
78
79 /**
80  * Determine whether a polygon is convex or not.
81  *
82  * @param polygonVerts  Array of points representing the vertices of the polygon.
83  * @param polygonSize  Number of vertices in the polygon.
84  * @return true if the polygon is convex, false otherwise.
85  */
86 bool SkIsConvexPolygon(const SkPoint* polygonVerts, int polygonSize);
87
88 /**
89  * Determine whether a polygon is simple (i.e., not self-intersecting) or not.
90  * The input polygon must have no coincident vertices or the test will fail.
91  * The polygon is also expected to have values clamped to the nearest 1/16th.
92  *
93  * @param polygonVerts  Array of points representing the vertices of the polygon.
94  * @param polygonSize  Number of vertices in the polygon.
95  * @return true if the polygon is simple, false otherwise.
96  */
97  bool SkIsSimplePolygon(const SkPoint* polygonVerts, int polygonSize);
98
99  /**
100   * Compute indices to triangulate the given polygon.
101   * The input polygon must be simple (i.e. it is not self-intersecting)
102   * and have no coincident vertices or collinear edges.
103   *
104   * @param polygonVerts  Array of points representing the vertices of the polygon.
105   * @param indexMap Mapping from index in the given array to the final index in the triangulation.
106   * @param polygonSize  Number of vertices in the polygon.
107   * @param triangleIndices  Indices of the resulting triangulation.
108   * @return true if successful, false otherwise.
109   */
110  bool SkTriangulateSimplePolygon(const SkPoint* polygonVerts, uint16_t* indexMap, int polygonSize,
111                                  SkTDArray<uint16_t>* triangleIndices);
112
113 // Experiment: doesn't handle really big floats (returns false), always returns true for count <= 3
114 bool SkIsPolyConvex_experimental(const SkPoint[], int count);
115
116 #endif