Flutter Engine
The Flutter Engine
ContourTest.cpp
Go to the documentation of this file.
1// Copyright 2023 Google LLC
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
5
8#include "tests/Test.h"
9
10using namespace contour;
11
12DEF_TEST(CFC_Contours_Basic, r) {
13 {
14 // No contours basic
15 SkPath p;
16 Contours contours = Contours::Make(p);
17 REPORTER_ASSERT(r, contours.empty());
18 }
19 {
20 // Path with just a close.
22 b.close();
23 SkPath p = b.detach();
24 Contours contours = Contours::Make(p);
25 REPORTER_ASSERT(r, contours.empty());
26 }
27 {
28 // Path with a bunch of moves.
30 b.moveTo(10, 10);
31 b.moveTo(20, 20);
32 b.close();
33 SkPath p = b.detach();
34 Contours contours = Contours::Make(p);
35 REPORTER_ASSERT(r, contours.empty());
36 }
37 {
38 // LineTo, but no close.
40 b.moveTo(10, 10);
41 b.moveTo(20, 20);
42 b.lineTo(30, 30);
43 SkPath p = b.detach();
44 Contours contours = Contours::Make(p);
45 REPORTER_ASSERT(r, contours.size() == 1);
46 Contour c = *contours.begin();
47 REPORTER_ASSERT(r, c.points.size() == 2);
48 REPORTER_ASSERT(r, c.points[0].x == 20 * Contours::kScaleFactor);
49 REPORTER_ASSERT(r, c.points[1].x == 30 * Contours::kScaleFactor);
50 REPORTER_ASSERT(r, c.bounds == SkIRect::MakeLTRB(20 * Contours::kScaleFactor,
51 20 * Contours::kScaleFactor,
52 30 * Contours::kScaleFactor,
53 30 * Contours::kScaleFactor));
54 }
55 {
56 // LineTo with close.
58 b.moveTo(10, 10);
59 b.moveTo(20, 20);
60 b.lineTo(30, 30);
61 b.close();
62 SkPath p = b.detach();
63 Contours contours = Contours::Make(p);
64 REPORTER_ASSERT(r, contours.size() == 1);
65 Contour c = *contours.begin();
66 REPORTER_ASSERT(r, c.points.size() == 3);
67 REPORTER_ASSERT(r, c.points[0].x == 20 * Contours::kScaleFactor);
68 REPORTER_ASSERT(r, c.points[1].x == 30 * Contours::kScaleFactor);
69 // Extra point added by close.
70 REPORTER_ASSERT(r, c.points[2].x == 20 * Contours::kScaleFactor);
71 REPORTER_ASSERT(r, c.bounds == SkIRect::MakeLTRB(20 * Contours::kScaleFactor,
72 20 * Contours::kScaleFactor,
73 30 * Contours::kScaleFactor,
74 30 * Contours::kScaleFactor));
75 }
76 {
77 // LineTo with close and extra moves.
79 b.moveTo(10, 10);
80 b.moveTo(20, 20);
81 b.lineTo(30, 30);
82 b.close();
83 b.moveTo(100, 100);
84 SkPath p = b.detach();
85 Contours contours = Contours::Make(p);
86 REPORTER_ASSERT(r, contours.size() == 1);
87 Contour c = *contours.begin();
88 REPORTER_ASSERT(r, c.points.size() == 3);
89 REPORTER_ASSERT(r, c.points[0].x == 20 * Contours::kScaleFactor);
90 REPORTER_ASSERT(r, c.points[1].x == 30 * Contours::kScaleFactor);
91 // Extra point added by close.
92 REPORTER_ASSERT(r, c.points[2].x == 20 * Contours::kScaleFactor);
93 REPORTER_ASSERT(r, c.bounds == SkIRect::MakeLTRB(20 * Contours::kScaleFactor,
94 20 * Contours::kScaleFactor,
95 30 * Contours::kScaleFactor,
96 30 * Contours::kScaleFactor));
97 }
98}
DEF_TEST(CFC_Contours_Basic, r)
Definition: ContourTest.cpp:12
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
Definition: SkPath.h:59
SkIRect bounds
Definition: Contour.h:30
SkSpan< const Point > points
Definition: Contour.h:29
size_t size() const
Definition: Contour.h:78
Iterator begin() const
Definition: Contour.h:70
bool empty() const
Definition: Contour.h:82
static bool b
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91