Flutter Engine
The Flutter Engine
Classes | Macros | Typedefs | Functions | Variables
smallpaths.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include <tuple>

Go to the source code of this file.

Classes

class  SmallPathsGM
 

Macros

#define N   std::size(gProcs)
 

Typedefs

typedef PathDY(* MakePathProc) ()
 

Functions

static PathDY make_triangle ()
 
static PathDY make_rect ()
 
static PathDY make_oval ()
 
static PathDY make_star (int n)
 
static PathDY make_star_5 ()
 
static PathDY make_star_13 ()
 
static PathDY make_three_line ()
 
static PathDY make_arrow ()
 
static PathDY make_curve ()
 
static PathDY make_battery ()
 
static PathDY make_battery2 ()
 
static PathDY make_ring ()
 

Variables

constexpr MakePathProc gProcs []
 
constexpr SkScalar gWidths []
 
constexpr SkScalar gMiters []
 
constexpr SkScalar gXTranslate []
 

Macro Definition Documentation

◆ N

#define N   std::size(gProcs)

Definition at line 317 of file smallpaths.cpp.

Typedef Documentation

◆ MakePathProc

typedef PathDY(* MakePathProc) ()

Definition at line 26 of file smallpaths.cpp.

Function Documentation

◆ make_arrow()

static PathDY make_arrow ( )
static

Definition at line 100 of file smallpaths.cpp.

100 {
101 static SkScalar xOffset = 34.f;
102 static SkScalar yOffset = 40.f;
104 b.moveTo(-26.f + xOffset, 0.0f + yOffset);
105 b.lineTo(26.f + xOffset, 0.0f + yOffset);
106
107 b.moveTo(-28.f + xOffset, -2.4748745f + yOffset);
108 b.lineTo(0 + xOffset, 25.525126f + yOffset);
109
110 b.moveTo(-28.f + xOffset, 2.4748745f + yOffset);
111 b.lineTo(0 + xOffset, -25.525126f + yOffset);
112 b.lineTo(-28.f + xOffset, 2.4748745f + yOffset);
113
114 b.close();
115
116 return { b.detach(), 70 };
117}
float SkScalar
Definition: extension.cpp:12
static bool b

◆ make_battery()

static PathDY make_battery ( )
static

Definition at line 131 of file smallpaths.cpp.

131 {
132 static SkScalar xOffset = 5.0f;
133
135 b.moveTo(24.67f + xOffset, 0.33000004f);
136 b.lineTo(8.3299999f + xOffset, 0.33000004f);
137 b.lineTo(8.3299999f + xOffset, 5.3299999f);
138 b.lineTo(0.33000004f + xOffset, 5.3299999f);
139 b.lineTo(0.33000004f + xOffset, 50.669998f);
140 b.lineTo(32.669998f + xOffset, 50.669998f);
141 b.lineTo(32.669998f + xOffset, 5.3299999f);
142 b.lineTo(24.67f + xOffset, 5.3299999f);
143 b.lineTo(24.67f + xOffset, 0.33000004f);
144 b.close();
145
146 b.moveTo(25.727224f + xOffset, 12.886665f);
147 b.lineTo(10.907918f + xOffset, 12.886665f);
148 b.lineTo(7.5166659f + xOffset, 28.683645f);
149 b.lineTo(14.810181f + xOffset, 28.683645f);
150 b.lineTo(7.7024879f + xOffset, 46.135998f);
151 b.lineTo(28.049999f + xOffset, 25.136419f);
152 b.lineTo(16.854223f + xOffset, 25.136419f);
153 b.lineTo(25.727224f + xOffset, 12.886665f);
154 b.close();
155 return { b.detach(), 50 };
156}

◆ make_battery2()

static PathDY make_battery2 ( )
static

Definition at line 158 of file smallpaths.cpp.

158 {
159 static SkScalar xOffset = 225.625f;
160
162 b.moveTo(32.669998f + xOffset, 9.8640003f);
163 b.lineTo(0.33000004f + xOffset, 9.8640003f);
164 b.lineTo(0.33000004f + xOffset, 50.669998f);
165 b.lineTo(32.669998f + xOffset, 50.669998f);
166 b.lineTo(32.669998f + xOffset, 9.8640003f);
167 b.close();
168
169 b.moveTo(10.907918f + xOffset, 12.886665f);
170 b.lineTo(25.727224f + xOffset, 12.886665f);
171 b.lineTo(16.854223f + xOffset, 25.136419f);
172 b.lineTo(28.049999f + xOffset, 25.136419f);
173 b.lineTo(7.7024879f + xOffset, 46.135998f);
174 b.lineTo(14.810181f + xOffset, 28.683645f);
175 b.lineTo(7.5166659f + xOffset, 28.683645f);
176 b.lineTo(10.907918f + xOffset, 12.886665f);
177 b.close();
178
179 return { b.detach(), 60 };
180}

◆ make_curve()

static PathDY make_curve ( )
static

Definition at line 119 of file smallpaths.cpp.

119 {
120 static SkScalar xOffset = -382.f;
121 static SkScalar yOffset = -50.f;
123 b.moveTo(491 + xOffset, 56 + yOffset);
124 b.conicTo(435.93292f + xOffset, 56.000031f + yOffset,
125 382.61078f + xOffset, 69.752716f + yOffset,
126 0.9920463f);
127
128 return { b.detach(), 40 };
129}

◆ make_oval()

static PathDY make_oval ( )
static

Definition at line 52 of file smallpaths.cpp.

52 {
53 SkRect r = { SkIntToScalar(10), SkIntToScalar(10),
55 return {
56 SkPath::Oval(r.makeOffset(10, 0)),
57 30
58 };
59}
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition: SkPath.cpp:3590
constexpr SkRect makeOffset(float dx, float dy) const
Definition: SkRect.h:965

◆ make_rect()

static PathDY make_rect ( )
static

Definition at line 43 of file smallpaths.cpp.

43 {
44 SkRect r = { SkIntToScalar(10), SkIntToScalar(10),
46 return {
47 SkPath::Rect(r.makeOffset(10, 0)),
48 30
49 };
50}
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition: SkPath.cpp:3586

◆ make_ring()

static PathDY make_ring ( )
static

Definition at line 182 of file smallpaths.cpp.

182 {
183 static SkScalar xOffset = 120;
184 static SkScalar yOffset = -270.f;
185
187 b.setFillType(SkPathFillType::kWinding);
188 b.moveTo(xOffset + 144.859f, yOffset + 285.172f);
189 b.lineTo(xOffset + 144.859f, yOffset + 285.172f);
190 b.lineTo(xOffset + 144.859f, yOffset + 285.172f);
191 b.lineTo(xOffset + 143.132f, yOffset + 284.617f);
192 b.lineTo(xOffset + 144.859f, yOffset + 285.172f);
193 b.close();
194 b.moveTo(xOffset + 135.922f, yOffset + 286.844f);
195 b.lineTo(xOffset + 135.922f, yOffset + 286.844f);
196 b.lineTo(xOffset + 135.922f, yOffset + 286.844f);
197 b.lineTo(xOffset + 135.367f, yOffset + 288.571f);
198 b.lineTo(xOffset + 135.922f, yOffset + 286.844f);
199 b.close();
200 b.moveTo(xOffset + 135.922f, yOffset + 286.844f);
201 b.cubicTo(xOffset + 137.07f, yOffset + 287.219f, xOffset + 138.242f, yOffset + 287.086f,
202 xOffset + 139.242f, yOffset + 286.578f);
203 b.cubicTo(xOffset + 140.234f, yOffset + 286.078f, xOffset + 141.031f, yOffset + 285.203f,
204 xOffset + 141.406f, yOffset + 284.055f);
205 b.lineTo(xOffset + 144.859f, yOffset + 285.172f);
206 b.cubicTo(xOffset + 143.492f, yOffset + 289.375f, xOffset + 138.992f, yOffset + 291.656f,
207 xOffset + 134.797f, yOffset + 290.297f);
208 b.lineTo(xOffset + 135.922f, yOffset + 286.844f);
209 b.close();
210 b.moveTo(xOffset + 129.68f, yOffset + 280.242f);
211 b.lineTo(xOffset + 129.68f, yOffset + 280.242f);
212 b.lineTo(xOffset + 129.68f, yOffset + 280.242f);
213 b.lineTo(xOffset + 131.407f, yOffset + 280.804f);
214 b.lineTo(xOffset + 129.68f, yOffset + 280.242f);
215 b.close();
216 b.moveTo(xOffset + 133.133f, yOffset + 281.367f);
217 b.cubicTo(xOffset + 132.758f, yOffset + 282.508f, xOffset + 132.883f, yOffset + 283.687f,
218 xOffset + 133.391f, yOffset + 284.679f);
219 b.cubicTo(xOffset + 133.907f, yOffset + 285.679f, xOffset + 134.774f, yOffset + 286.468f,
220 xOffset + 135.922f, yOffset + 286.843f);
221 b.lineTo(xOffset + 134.797f, yOffset + 290.296f);
222 b.cubicTo(xOffset + 130.602f, yOffset + 288.929f, xOffset + 128.313f, yOffset + 284.437f,
223 xOffset + 129.68f, yOffset + 280.241f);
224 b.lineTo(xOffset + 133.133f, yOffset + 281.367f);
225 b.close();
226 b.moveTo(xOffset + 139.742f, yOffset + 275.117f);
227 b.lineTo(xOffset + 139.742f, yOffset + 275.117f);
228 b.lineTo(xOffset + 139.18f, yOffset + 276.844f);
229 b.lineTo(xOffset + 139.742f, yOffset + 275.117f);
230 b.close();
231 b.moveTo(xOffset + 138.609f, yOffset + 278.57f);
232 b.cubicTo(xOffset + 137.461f, yOffset + 278.203f, xOffset + 136.297f, yOffset + 278.328f,
233 xOffset + 135.297f, yOffset + 278.836f);
234 b.cubicTo(xOffset + 134.297f, yOffset + 279.344f, xOffset + 133.508f, yOffset + 280.219f,
235 xOffset + 133.133f, yOffset + 281.367f);
236 b.lineTo(xOffset + 129.68f, yOffset + 280.242f);
237 b.cubicTo(xOffset + 131.047f, yOffset + 276.039f, xOffset + 135.539f, yOffset + 273.758f,
238 xOffset + 139.742f, yOffset + 275.117f);
239 b.lineTo(xOffset + 138.609f, yOffset + 278.57f);
240 b.close();
241 b.moveTo(xOffset + 141.406f, yOffset + 284.055f);
242 b.cubicTo(xOffset + 141.773f, yOffset + 282.907f, xOffset + 141.648f, yOffset + 281.735f,
243 xOffset + 141.148f, yOffset + 280.735f);
244 b.cubicTo(xOffset + 140.625f, yOffset + 279.735f, xOffset + 139.757f, yOffset + 278.946f,
245 xOffset + 138.609f, yOffset + 278.571f);
246 b.lineTo(xOffset + 139.742f, yOffset + 275.118f);
247 b.cubicTo(xOffset + 143.937f, yOffset + 276.493f, xOffset + 146.219f, yOffset + 280.977f,
248 xOffset + 144.859f, yOffset + 285.173f);
249 b.lineTo(xOffset + 141.406f, yOffset + 284.055f);
250 b.close();
251
252 // uncomment to reveal PathOps bug, see https://bugs.chromium.org/p/skia/issues/detail?id=9732
253 // (void) Simplify(*path, path);
254
255 return { b.detach(), 15 };
256}

◆ make_star()

static PathDY make_star ( int  n)
static

Definition at line 61 of file smallpaths.cpp.

61 {
62 const SkScalar c = SkIntToScalar(45);
63 const SkScalar r = SkIntToScalar(20);
64
65 SkScalar rad = -SK_ScalarPI / 2;
66 const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n;
67
69 b.moveTo(c, c - r);
70 for (int i = 1; i < n; i++) {
71 rad += drad;
72 b.lineTo(c + SkScalarCos(rad) * r, c + SkScalarSin(rad) * r);
73 }
74 b.close();
75 return { b.detach(), r * 2 * 6 / 5 };
76}
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21

◆ make_star_13()

static PathDY make_star_13 ( )
static

Definition at line 79 of file smallpaths.cpp.

79{ return make_star(13); }
static PathDY make_star(int n)
Definition: smallpaths.cpp:61

◆ make_star_5()

static PathDY make_star_5 ( )
static

Definition at line 78 of file smallpaths.cpp.

78{ return make_star(5); }

◆ make_three_line()

static PathDY make_three_line ( )
static

Definition at line 81 of file smallpaths.cpp.

81 {
82 static SkScalar xOffset = 34.f;
83 static SkScalar yOffset = 50.f;
85 b.moveTo(-32.5f + xOffset, 0.0f + yOffset);
86 b.lineTo(32.5f + xOffset, 0.0f + yOffset);
87
88 b.moveTo(-32.5f + xOffset, 19 + yOffset);
89 b.lineTo(32.5f + xOffset, 19 + yOffset);
90
91 b.moveTo(-32.5f + xOffset, -19 + yOffset);
92 b.lineTo(32.5f + xOffset, -19 + yOffset);
93 b.lineTo(-32.5f + xOffset, -19 + yOffset);
94
95 b.close();
96
97 return { b.detach(), 70 };
98}

◆ make_triangle()

static PathDY make_triangle ( )
static

Definition at line 28 of file smallpaths.cpp.

28 {
29 constexpr int gCoord[] = {
30 10, 20, 15, 5, 30, 30
31 };
32 return {
33 SkPathBuilder().moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1]))
34 .lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3]))
35 .lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5]))
36 .close()
37 .offset(10, 0)
38 .detach(),
39 30
40 };
41}
SkPathBuilder & close()
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & moveTo(SkPoint pt)
SkPathBuilder & offset(SkScalar dx, SkScalar dy)

Variable Documentation

◆ gMiters

constexpr SkScalar gMiters[]
constexpr
Initial value:
= {
2.0f,
3.0f,
3.0f,
3.0f,
4.0f,
4.0f,
4.0f,
4.0f,
4.0f,
4.0f,
4.0f,
}

Definition at line 287 of file smallpaths.cpp.

◆ gProcs

constexpr MakePathProc gProcs[]
constexpr
Initial value:
= {
}
static PathDY make_curve()
Definition: smallpaths.cpp:119
static PathDY make_battery2()
Definition: smallpaths.cpp:158
static PathDY make_arrow()
Definition: smallpaths.cpp:100
static PathDY make_star_13()
Definition: smallpaths.cpp:79
static PathDY make_ring()
Definition: smallpaths.cpp:182
static PathDY make_star_5()
Definition: smallpaths.cpp:78
static PathDY make_triangle()
Definition: smallpaths.cpp:28
static PathDY make_rect()
Definition: smallpaths.cpp:43
static PathDY make_battery()
Definition: smallpaths.cpp:131
static PathDY make_three_line()
Definition: smallpaths.cpp:81
static PathDY make_oval()
Definition: smallpaths.cpp:52

Definition at line 258 of file smallpaths.cpp.

◆ gWidths

constexpr SkScalar gWidths[]
constexpr
Initial value:
= {
2.0f,
3.0f,
4.0f,
5.0f,
6.0f,
7.0f,
7.0f,
14.0f,
0.0f,
0.0f,
0.0f
}

Definition at line 272 of file smallpaths.cpp.

◆ gXTranslate

constexpr SkScalar gXTranslate[]
constexpr
Initial value:
= {
0.0f,
0.0f,
0.0f,
0.0f,
0.0f,
0.0f,
0.0f,
0.0f,
-220.625f,
0.0f,
0.0f,
}

Definition at line 302 of file smallpaths.cpp.