Flutter Engine
The Flutter Engine
Functions
OffsetSimplePolyTest.cpp File Reference
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/private/base/SkTDArray.h"
#include "src/utils/SkPolyUtils.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

 DEF_TEST (OffsetSimplePoly, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( OffsetSimplePoly  ,
reporter   
)

Definition at line 15 of file OffsetSimplePolyTest.cpp.

15 {
16 SkTDArray<SkPoint> rrectPoly;
17
18 ///////////////////////////////////////////////////////////////////////
19 // Try convex tests first
20
21 // round rect
22 *rrectPoly.append() = SkPoint::Make(-100, 55);
23 *rrectPoly.append() = SkPoint::Make(100, 55);
24 *rrectPoly.append() = SkPoint::Make(100 + 2.5f, 50 + 4.330127f);
25 *rrectPoly.append() = SkPoint::Make(100 + 3.535534f, 50 + 3.535534f);
26 *rrectPoly.append() = SkPoint::Make(100 + 4.330127f, 50 + 2.5f);
27 *rrectPoly.append() = SkPoint::Make(105, 50);
28 *rrectPoly.append() = SkPoint::Make(105, -50);
29 *rrectPoly.append() = SkPoint::Make(100 + 4.330127f, -50 - 2.5f);
30 *rrectPoly.append() = SkPoint::Make(100 + 3.535534f, -50 - 3.535534f);
31 *rrectPoly.append() = SkPoint::Make(100 + 2.5f, -50 - 4.330127f);
32 *rrectPoly.append() = SkPoint::Make(100, -55);
33 *rrectPoly.append() = SkPoint::Make(-100, -55);
34 *rrectPoly.append() = SkPoint::Make(-100 - 2.5f, -50 - 4.330127f);
35 *rrectPoly.append() = SkPoint::Make(-100 - 3.535534f, -50 - 3.535534f);
36 *rrectPoly.append() = SkPoint::Make(-100 - 4.330127f, -50 - 2.5f);
37 *rrectPoly.append() = SkPoint::Make(-105, -50);
38 *rrectPoly.append() = SkPoint::Make(-105, 50);
39 *rrectPoly.append() = SkPoint::Make(-100 - 4.330127f, 50 + 2.5f);
40 *rrectPoly.append() = SkPoint::Make(-100 - 3.535534f, 50 + 3.535534f);
41 *rrectPoly.append() = SkPoint::Make(-100 - 2.5f, 50 + 4.330127f);
43 bounds.setBoundsCheck(rrectPoly.begin(), rrectPoly.size());
44
45 REPORTER_ASSERT(reporter, SkIsConvexPolygon(rrectPoly.begin(), rrectPoly.size()));
46
47 // inset a little
48 SkTDArray<SkPoint> offsetPoly;
49 bool result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.size(), bounds, 3,
50 &offsetPoly);
52 REPORTER_ASSERT(reporter, SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.size()));
53
54 // inset to rect
55 result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.size(), bounds, 10, &offsetPoly);
57 REPORTER_ASSERT(reporter, SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.size()));
58 REPORTER_ASSERT(reporter, offsetPoly.size() == 4);
59 if (offsetPoly.size() == 4) {
60 REPORTER_ASSERT(reporter, offsetPoly[0].equals(-95, 45));
61 REPORTER_ASSERT(reporter, offsetPoly[1].equals(95, 45));
62 REPORTER_ASSERT(reporter, offsetPoly[2].equals(95, -45));
63 REPORTER_ASSERT(reporter, offsetPoly[3].equals(-95, -45));
64 }
65
66 // just to full inset
67 // fails, but outputs a line segment
68 result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.size(), bounds, 55, &offsetPoly);
70 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.size()));
71 REPORTER_ASSERT(reporter, offsetPoly.size() == 2);
72 if (offsetPoly.size() == 2) {
73 REPORTER_ASSERT(reporter, offsetPoly[0].equals(-50, 0));
74 REPORTER_ASSERT(reporter, offsetPoly[1].equals(50, 0));
75 }
76
77 // past full inset
78 result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.size(), bounds, 75, &offsetPoly);
80
81 // troublesome case
82 SkTDArray<SkPoint> clippedRRectPoly;
83 *clippedRRectPoly.append() = SkPoint::Make(335.928101f, 428.219055f);
84 *clippedRRectPoly.append() = SkPoint::Make(330.414459f, 423.034912f);
85 *clippedRRectPoly.append() = SkPoint::Make(325.749084f, 417.395508f);
86 *clippedRRectPoly.append() = SkPoint::Make(321.931946f, 411.300842f);
87 *clippedRRectPoly.append() = SkPoint::Make(318.963074f, 404.750977f);
88 *clippedRRectPoly.append() = SkPoint::Make(316.842468f, 397.745850f);
89 *clippedRRectPoly.append() = SkPoint::Make(315.570068f, 390.285522f);
90 *clippedRRectPoly.append() = SkPoint::Make(315.145966f, 382.369965f);
91 *clippedRRectPoly.append() = SkPoint::Make(315.570068f, 374.454346f);
92 *clippedRRectPoly.append() = SkPoint::Make(316.842468f, 366.994019f);
93 *clippedRRectPoly.append() = SkPoint::Make(318.963074f, 359.988892f);
94 *clippedRRectPoly.append() = SkPoint::Make(321.931946f, 353.439056f);
95 *clippedRRectPoly.append() = SkPoint::Make(325.749084f, 347.344421f);
96 *clippedRRectPoly.append() = SkPoint::Make(330.414459f, 341.705017f);
97 *clippedRRectPoly.append() = SkPoint::Make(335.928101f, 336.520813f);
98 *clippedRRectPoly.append() = SkPoint::Make(342.289948f, 331.791901f);
99 *clippedRRectPoly.append() = SkPoint::Make(377.312134f, 331.791901f);
100 *clippedRRectPoly.append() = SkPoint::Make(381.195313f, 332.532593f);
101 *clippedRRectPoly.append() = SkPoint::Make(384.464935f, 334.754700f);
102 *clippedRRectPoly.append() = SkPoint::Make(386.687042f, 338.024292f);
103 *clippedRRectPoly.append() = SkPoint::Make(387.427765f, 341.907532f);
104 *clippedRRectPoly.append() = SkPoint::Make(387.427765f, 422.832367f);
105 *clippedRRectPoly.append() = SkPoint::Make(386.687042f, 426.715576f);
106 *clippedRRectPoly.append() = SkPoint::Make(384.464935f, 429.985168f);
107 *clippedRRectPoly.append() = SkPoint::Make(381.195313f, 432.207275f);
108 *clippedRRectPoly.append() = SkPoint::Make(377.312134f, 432.947998f);
109 *clippedRRectPoly.append() = SkPoint::Make(342.289948f, 432.947998f);
110 bounds.setBoundsCheck(clippedRRectPoly.begin(), clippedRRectPoly.size());
111
113 clippedRRectPoly.size()));
114
115 result = SkOffsetSimplePolygon(clippedRRectPoly.begin(), clippedRRectPoly.size(), bounds,
116 32.3699417f, &offsetPoly);
118 REPORTER_ASSERT(reporter, SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.size()));
119
120 ////////////////////////////////////////////////////////////////////////////////
121 // Concave tests
122
123 SkTDArray<SkPoint> starPoly;
124 *starPoly.append() = SkPoint::Make(0.0f, -50.0f);
125 *starPoly.append() = SkPoint::Make(14.43f, -25.0f);
126 *starPoly.append() = SkPoint::Make(43.30f, -25.0f);
127 *starPoly.append() = SkPoint::Make(28.86f, 0.0f);
128 *starPoly.append() = SkPoint::Make(43.30f, 25.0f);
129 *starPoly.append() = SkPoint::Make(14.43f, 25.0f);
130 *starPoly.append() = SkPoint::Make(0.0f, 50.0f);
131 *starPoly.append() = SkPoint::Make(-14.43f, 25.0f);
132 *starPoly.append() = SkPoint::Make(-43.30f, 25.0f);
133 *starPoly.append() = SkPoint::Make(-28.86f, 0.0f);
134 *starPoly.append() = SkPoint::Make(-43.30f, -25.0f);
135 *starPoly.append() = SkPoint::Make(-14.43f, -25.0f);
136 bounds.setBoundsCheck(starPoly.begin(), starPoly.size());
137
138 REPORTER_ASSERT(reporter, SkIsSimplePolygon(starPoly.begin(), starPoly.size()));
139
140 // try a variety of distances
141 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, 0.1f,
142 &offsetPoly);
144 REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.size()));
145
146 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, 5.665f,
147 &offsetPoly);
149 REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.size()));
150
151 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, 28,
152 &offsetPoly);
154 REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.size()));
155
156 // down to a point
157 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, 28.866f,
158 &offsetPoly);
160
161 // and past
162 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, 50.5f,
163 &offsetPoly);
165
166 // and now out
167 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, -0.1f,
168 &offsetPoly);
170 REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.size()));
171
172 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, -5.6665f,
173 &offsetPoly);
175 REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.size()));
176
177 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, -50,
178 &offsetPoly);
180 REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.size()));
181
182 result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.size(), bounds, -100,
183 &offsetPoly);
185 REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.size()));
186
187 SkTDArray<SkPoint> intersectingPoly;
188 *intersectingPoly.append() = SkPoint::Make(0.0f, -50.0f);
189 *intersectingPoly.append() = SkPoint::Make(14.43f, -25.0f);
190 *intersectingPoly.append() = SkPoint::Make(43.30f, -25.0f);
191 *intersectingPoly.append() = SkPoint::Make(-28.86f, 0.0f);
192 *intersectingPoly.append() = SkPoint::Make(43.30f, 25.0f);
193 *intersectingPoly.append() = SkPoint::Make(14.43f, 25.0f);
194 *intersectingPoly.append() = SkPoint::Make(0.0f, 50.0f);
195 *intersectingPoly.append() = SkPoint::Make(-14.43f, 25.0f);
196 *intersectingPoly.append() = SkPoint::Make(-43.30f, 25.0f);
197 *intersectingPoly.append() = SkPoint::Make(28.86f, 0.0f);
198 *intersectingPoly.append() = SkPoint::Make(-43.30f, -25.0f);
199 *intersectingPoly.append() = SkPoint::Make(-14.43f, -25.0f);
200
201 // SkOffsetSimplePolygon now assumes that the input is simple, so we'll just check for that
202 result = SkIsSimplePolygon(intersectingPoly.begin(), intersectingPoly.size());
204}
reporter
Definition: FontMgrTest.cpp:39
bool equals(SkDrawable *a, SkDrawable *b)
bool SkIsConvexPolygon(const SkPoint *polygonVerts, int polygonSize)
bool SkOffsetSimplePolygon(const SkPoint *inputPolygonVerts, int inputPolygonSize, const SkRect &bounds, SkScalar offset, SkTDArray< SkPoint > *offsetPolygon, SkTDArray< int > *polygonIndices)
bool SkIsSimplePolygon(const SkPoint *polygon, int polygonSize)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
int size() const
Definition: SkTDArray.h:138
T * begin()
Definition: SkTDArray.h:150
T * append()
Definition: SkTDArray.h:191
GAsyncResult * result
Optional< SkRect > bounds
Definition: SkRecords.h:189
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173