83TEST(TessellatorTest, TessellateConvex) {
90 std::vector<Point> expected = {{0, 0}, {10, 0}, {0, 10}, {10, 10}};
91 EXPECT_EQ(pts, expected);
102 std::vector<Point> expected = {{0, 0}, {10, 0}, {0, 10}, {10, 10},
103 {10, 10}, {20, 20}, {20, 20}, {30, 20},
105 EXPECT_EQ(pts, expected);
145TEST(TessellatorTest, FilledCircleTessellationVertices) {
146 auto tessellator = std::make_shared<Tessellator>();
153 auto vertex_count = generator.GetVertexCount();
154 auto vertices = std::vector<Point>();
155 generator.GenerateVertices([&vertices](
const Point& p) {
156 vertices.push_back(p);
158 EXPECT_EQ(vertices.size(), vertex_count);
159 ASSERT_EQ(vertex_count % 4, 0u);
161 auto quadrant_count = vertex_count / 4;
162 for (
size_t i = 0; i < quadrant_count; i++) {
163 double angle =
kPiOver2 * i / (quadrant_count - 1);
164 double degrees = angle * 180.0 /
kPi;
165 double rsin = sin(angle) * radius;
167 double rcos = (i == quadrant_count - 1) ? 0.0f : cos(angle) * radius;
170 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
173 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
176 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
179 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
184 test({}, {10, 10}, 2.0);
189TEST(TessellatorTest, StrokedCircleTessellationVertices) {
190 auto tessellator = std::make_shared<Tessellator>();
194 ASSERT_GT(radius, half_width);
199 auto vertex_count = generator.GetVertexCount();
200 auto vertices = std::vector<Point>();
201 generator.GenerateVertices([&vertices](
const Point& p) {
202 vertices.push_back(p);
204 EXPECT_EQ(vertices.size(), vertex_count);
205 ASSERT_EQ(vertex_count % 4, 0u);
207 auto quadrant_count = vertex_count / 8;
210 for (
size_t i = 0; i < quadrant_count; i++) {
211 double angle =
kPiOver2 * i / (quadrant_count - 1);
212 double degrees = angle * 180.0 /
kPi;
213 double rsin = sin(angle) * (radius + half_width);
216 (i == quadrant_count - 1) ? 0.0f : cos(angle) * (radius + half_width);
219 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
222 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
225 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
228 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
232 for (
size_t i = 0; i < quadrant_count; i++) {
233 double angle =
kPiOver2 * i / (quadrant_count - 1);
234 double degrees = angle * 180.0 /
kPi;
235 double rsin = sin(angle) * (radius - half_width);
238 (i == quadrant_count - 1) ? 0.0f : cos(angle) * (radius - half_width);
241 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
244 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
247 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
250 <<
"vertex " << i <<
", angle = " << degrees << std::endl;
254 test({}, {}, 2.0, 1.0);
255 test({}, {}, 2.0, 0.5);
256 test({}, {10, 10}, 2.0, 1.0);
261TEST(TessellatorTest, RoundCapLineTessellationVertices) {
262 auto tessellator = std::make_shared<Tessellator>();
266 auto generator = tessellator->RoundCapLine(
transform, p0, p1, radius);
269 auto vertex_count = generator.GetVertexCount();
270 auto vertices = std::vector<Point>();
271 generator.GenerateVertices([&vertices](
const Point& p) {
272 vertices.push_back(p);
274 EXPECT_EQ(vertices.size(), vertex_count);
275 ASSERT_EQ(vertex_count % 4, 0u);
277 Point along = p1 - p0;
284 Point across = {-along.
y, along.
x};
286 auto quadrant_count = vertex_count / 4;
287 for (
size_t i = 0; i < quadrant_count; i++) {
288 double angle =
kPiOver2 * i / (quadrant_count - 1);
289 double degrees = angle * 180.0 /
kPi;
291 Point relative_along =
292 along * ((i == quadrant_count - 1) ? 0.0f : cos(angle));
293 Point relative_across = across * sin(angle);
295 p0 - relative_along + relative_across)
296 <<
"vertex " << i <<
", angle = " << degrees <<
", "
297 <<
"line = " << p0 <<
" => " << p1 <<
", "
298 <<
"radius = " << radius << std::endl;
300 p0 - relative_along - relative_across)
301 <<
"vertex " << i <<
", angle = " << degrees <<
", "
302 <<
"line = " << p0 <<
" => " << p1 <<
", "
303 <<
"radius = " << radius << std::endl;
305 p1 + relative_along - relative_across)
306 <<
"vertex " << i <<
", angle = " << degrees <<
", "
307 <<
"line = " << p0 <<
" => " << p1 <<
", "
308 <<
"radius = " << radius << std::endl;
310 p1 + relative_along + relative_across)
311 <<
"vertex " << i <<
", angle = " << degrees <<
", "
312 <<
"line = " << p0 <<
" => " << p1 <<
", "
313 <<
"radius = " << radius << std::endl;
319 test({}, {0, 0}, {0, 0}, 10);
321 test({}, {0, 0}, {10, 0}, 2);
322 test({}, {10, 0}, {0, 0}, 2);
323 test({}, {0, 0}, {10, 10}, 2);
334TEST(TessellatorTest, FilledEllipseTessellationVertices) {
335 auto tessellator = std::make_shared<Tessellator>();
338 auto center = bounds.GetCenter();
339 auto half_size = bounds.GetSize() * 0.5f;
341 auto generator = tessellator->FilledEllipse(
transform, bounds);
344 auto vertex_count = generator.GetVertexCount();
345 auto vertices = std::vector<Point>();
346 generator.GenerateVertices([&vertices](
const Point& p) {
347 vertices.push_back(p);
349 EXPECT_EQ(vertices.size(), vertex_count);
350 ASSERT_EQ(vertex_count % 4, 0u);
352 auto quadrant_count = vertex_count / 4;
353 for (
size_t i = 0; i < quadrant_count; i++) {
354 double angle =
kPiOver2 * i / (quadrant_count - 1);
355 double degrees = angle * 180.0 /
kPi;
358 (i == quadrant_count - 1) ? 0.0f : cos(angle) * half_size.width;
359 double rsin = sin(angle) * half_size.height;
362 <<
"vertex " << i <<
", angle = " << degrees <<
", "
363 <<
"bounds = " << bounds << std::endl;
366 <<
"vertex " << i <<
", angle = " << degrees <<
", "
367 <<
"bounds = " << bounds << std::endl;
370 <<
"vertex " << i <<
", angle = " << degrees <<
", "
371 <<
"bounds = " << bounds << std::endl;
374 <<
"vertex " << i <<
", angle = " << degrees <<
", "
375 <<
"bounds = " << bounds << std::endl;
395TEST(TessellatorTest, FilledRoundRectTessellationVertices) {
396 auto tessellator = std::make_shared<Tessellator>();
400 FML_DCHECK(radii.width * 2 <= bounds.GetWidth()) << radii << bounds;
401 FML_DCHECK(radii.height * 2 <= bounds.GetHeight()) << radii << bounds;
403 Scalar middle_left = bounds.GetX() + radii.width;
404 Scalar middle_top = bounds.GetY() + radii.height;
405 Scalar middle_right = bounds.GetX() + bounds.GetWidth() - radii.width;
406 Scalar middle_bottom = bounds.GetY() + bounds.GetHeight() - radii.height;
408 auto generator = tessellator->FilledRoundRect(
transform, bounds, radii);
411 auto vertex_count = generator.GetVertexCount();
412 auto vertices = std::vector<Point>();
413 generator.GenerateVertices([&vertices](
const Point& p) {
414 vertices.push_back(p);
416 EXPECT_EQ(vertices.size(), vertex_count);
417 ASSERT_EQ(vertex_count % 4, 0u);
419 auto quadrant_count = vertex_count / 4;
420 for (
size_t i = 0; i < quadrant_count; i++) {
421 double angle =
kPiOver2 * i / (quadrant_count - 1);
422 double degrees = angle * 180.0 /
kPi;
424 double rcos = (i == quadrant_count - 1) ? 0.0f : cos(angle) * radii.width;
425 double rsin = sin(angle) * radii.height;
427 Point(middle_left - rcos, middle_bottom + rsin))
428 <<
"vertex " << i <<
", angle = " << degrees <<
", "
429 <<
"bounds = " << bounds << std::endl;
431 Point(middle_left - rcos, middle_top - rsin))
432 <<
"vertex " << i <<
", angle = " << degrees <<
", "
433 <<
"bounds = " << bounds << std::endl;
435 Point(middle_right + rcos, middle_top - rsin))
436 <<
"vertex " << i <<
", angle = " << degrees <<
", "
437 <<
"bounds = " << bounds << std::endl;
439 Point(middle_right + rcos, middle_bottom + rsin))
440 <<
"vertex " << i <<
", angle = " << degrees <<
", "
441 <<
"bounds = " << bounds << std::endl;
483TEST(TessellatorTest, ChecksConcurrentPolylineUsage) {
484 auto tessellator = std::make_shared<Tessellator>();
486 builder.AddLine({0, 0}, {100, 100});
487 auto path = builder.TakePath();
489 auto polyline = tessellator->CreateTempPolyline(path, 0.1);
490 EXPECT_DEBUG_DEATH(tessellator->CreateTempPolyline(path, 0.1),