Flutter Engine
The Flutter Engine
Contour.h
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
4#ifndef Contour_DEFINED
5#define Contour_DEFINED
6
10
11#include <limits.h>
12#include <cstddef>
13#include <cstdint>
14#include <iterator>
15#include <vector>
16
17class SkPath;
18namespace myers { class Segment; }
19struct SkPoint;
20
21namespace contour {
22struct Point {
23 int32_t x;
24 int32_t y;
25};
26
27class Contour {
28public:
31};
32
33class Contours {
34 class Iterator {
35 public:
36 using value_type = Contour;
37 using difference_type = ptrdiff_t;
38 using pointer = value_type*;
39 using reference = value_type;
40 using iterator_category = std::input_iterator_tag;
41 Iterator(const Contours& contours, size_t index)
42 : fContours{contours}
43 , fIndex{index} { }
44 Iterator(const Iterator& that) : Iterator{ that.fContours, that.fIndex } { }
45 Iterator& operator++() { ++fIndex; return *this; }
46 Iterator operator++(int) { Iterator tmp(*this); operator++(); return tmp; }
47 bool operator==(const Iterator& rhs) const { return fIndex == rhs.fIndex; }
48 bool operator!=(const Iterator& rhs) const { return fIndex != rhs.fIndex; }
49 value_type operator*() { return fContours[fIndex]; }
50 friend difference_type operator-(Iterator lhs, Iterator rhs) {
51 return lhs.fIndex - rhs.fIndex;
52 }
53
54 private:
55 const Contours& fContours;
56 size_t fIndex = 0;
57 };
58public:
59 static constexpr double kScaleFactor = 1024;
60 static Contours Make(SkPath path);
61
62 Contour operator[](size_t i) const {
63 SkASSERT(i < fContours.size());
64 auto& [bounds, end] = fContours[i];
65 int32_t start = i == 0 ? 0 : fContours[i-1].end;
67 return {points, bounds};
68 }
69
70 Iterator begin() const {
71 return Iterator{*this, 0};
72 }
73
74 Iterator end() const {
75 return Iterator{*this, fContours.size()};
76 }
77
78 size_t size() const {
79 return fContours.size();
80 }
81
82 bool empty() const {
83 return fContours.empty();
84 }
85
86 std::vector<myers::Segment> segments() const;
87
88private:
89 static constexpr SkIRect kEmptyRect = SkIRect::MakeLTRB(INT_MAX, INT_MAX, INT_MIN, INT_MIN);
90 struct CompactContour {
92 int32_t end;
93 };
94
95 static Point RoundSkPoint(SkPoint p);
96 bool currentContourIsEmpty() const;
97 void addPointToCurrentContour(SkPoint p);
98 void moveToStartOfContour(SkPoint p);
99 void closeContourIfNeeded();
100
101 Point fContourStart;
102 SkIRect fContourBounds = kEmptyRect;
103
104 std::vector<Point> fPoints;
105 std::vector<CompactContour> fContours;
106};
107} // namespace contour
108
109#endif // Contour_DEFINED
static const int points[]
#define SkASSERT(cond)
Definition: SkAssert.h:116
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 end() const
Definition: Contour.h:74
std::vector< myers::Segment > segments() const
Definition: Contour.cpp:58
static constexpr double kScaleFactor
Definition: Contour.h:59
Contour operator[](size_t i) const
Definition: Contour.h:62
Iterator begin() const
Definition: Contour.h:70
bool empty() const
Definition: Contour.h:82
static Contours Make(SkPath path)
Definition: Contour.cpp:16
Optional< SkRect > bounds
Definition: SkRecords.h:189
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
bool operator==(C p1, const scoped_nsprotocol< C > &p2)
bool operator!=(C p1, const scoped_nsprotocol< C > &p2)
constexpr Color operator-(T value, const Color &c)
Definition: color.h:905
TPoint< Scalar > Point
Definition: point.h:322
constexpr Color operator*(T value, const Color &c)
Definition: color.h:911
Definition: Contour.h:18
Definition: SkRect.h:32
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
int32_t y
Definition: Contour.h:24
int32_t x
Definition: Contour.h:23