Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Contour.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
11
12#include <algorithm>
13#include <vector>
14
15namespace contour {
17 SkPoint pts[4];
18 SkPath::Iter iter(path, false);
19 SkPath::Verb verb;
20 Contours contours;
21 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
22 switch (verb) {
24 SK_ABORT("Not implemented");
25 break;
26 }
28 contours.closeContourIfNeeded();
29 contours.moveToStartOfContour(pts[0]);
30 break;
31 case SkPath::kLine_Verb: {
32 contours.addPointToCurrentContour(pts[1]);
33 break;
34 }
35 case SkPath::kQuad_Verb: {
36 SK_ABORT("Not implemented");
37 break;
38 }
40 SK_ABORT("Not implemented");
41 break;
42 }
44 contours.closeContourIfNeeded();
45 break;
46 }
48 SK_ABORT("The while loop above failed.");
49 }
50 }
51
52 // Close the remaining contour.
53 contours.closeContourIfNeeded();
54
55 return contours;
56}
57
58std::vector<myers::Segment> Contours::segments() const {
59 SK_ABORT("Not implemented");
60}
61
63 int32_t left = std::min(p.x, r.fLeft),
64 top = std::min(p.y, r.fTop),
65 right = std::max(p.x, r.fRight),
66 bottom = std::max(p.y, r.fBottom);
67 return {left, top, right, bottom};
68}
69
70Point Contours::RoundSkPoint(SkPoint p) {
72}
73
74bool Contours::currentContourIsEmpty() const {
75 int32_t lastEnd = fContours.empty() ? 0 : fContours.back().end;
76 return lastEnd == SkToS32(fPoints.size());
77}
78
79void Contours::addPointToCurrentContour(SkPoint p) {
80 if (this->currentContourIsEmpty()) {
81 fPoints.push_back(fContourStart);
82 fContourBounds = extend_rect(fContourBounds, fContourStart);
83 }
84 Point point = RoundSkPoint(p);
85 fPoints.push_back(point);
86 fContourBounds = extend_rect(fContourBounds, point);
87}
88
89void Contours::moveToStartOfContour(SkPoint p) {
90 fContourStart = RoundSkPoint(p);
91}
92
93void Contours::closeContourIfNeeded() {
94 if (this->currentContourIsEmpty()) {
95 // The current contour is empty. Don't record it.
96 return;
97 }
98 fContours.push_back({fContourBounds, SkToS32(fPoints.size())});
99 fContourBounds = kEmptyRect;
100}
101} // namespace contour
#define SK_ABORT(message,...)
Definition SkAssert.h:70
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define SkScalarRoundToInt(x)
Definition SkScalar.h:37
constexpr int32_t SkToS32(S x)
Definition SkTo.h:25
Verb next(SkPoint pts[4])
Definition SkPath.cpp:1837
@ kClose_Verb
Definition SkPath.h:1463
@ kMove_Verb
Definition SkPath.h:1458
@ kConic_Verb
Definition SkPath.h:1461
@ kDone_Verb
Definition SkPath.h:1464
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459
std::vector< myers::Segment > segments() const
Definition Contour.cpp:58
static constexpr double kScaleFactor
Definition Contour.h:59
static Contours Make(SkPath path)
Definition Contour.cpp:16
static SkIRect extend_rect(SkIRect r, Point p)
Definition Contour.cpp:62
TPoint< Scalar > Point
Definition point.h:316
int32_t fBottom
larger y-axis bounds
Definition SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition SkRect.h:35