Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SkReduceOrder Union Reference

#include <SkReduceOrder.h>

Public Types

enum  Quadratics { kNo_Quadratics , kAllow_Quadratics }
 

Public Member Functions

int reduce (const SkDCubic &cubic, Quadratics)
 
int reduce (const SkDLine &line)
 
int reduce (const SkDQuad &quad)
 

Static Public Member Functions

static SkPath::Verb Conic (const SkConic &conic, SkPoint *reducePts)
 
static SkPath::Verb Cubic (const SkPoint pts[4], SkPoint *reducePts)
 
static SkPath::Verb Quad (const SkPoint pts[3], SkPoint *reducePts)
 

Public Attributes

SkDLine fLine
 
SkDQuad fQuad
 
SkDCubic fCubic
 

Detailed Description

Definition at line 18 of file SkReduceOrder.h.

Member Enumeration Documentation

◆ Quadratics

Enumerator
kNo_Quadratics 
kAllow_Quadratics 

Definition at line 19 of file SkReduceOrder.h.

Member Function Documentation

◆ Conic()

SkPath::Verb SkReduceOrder::Conic ( const SkConic conic,
SkPoint reducePts 
)
static

Definition at line 266 of file SkReduceOrder.cpp.

266 {
267 SkPath::Verb verb = SkReduceOrder::Quad(c.fPts, reducePts);
268 if (verb > SkPath::kLine_Verb && c.fW == 1) {
269 return SkPath::kQuad_Verb;
270 }
271 return verb == SkPath::kQuad_Verb ? SkPath::kConic_Verb : verb;
272}
@ kConic_Verb
Definition: SkPath.h:1469
@ kQuad_Verb
Definition: SkPath.h:1468
@ kLine_Verb
Definition: SkPath.h:1467
static SkPath::Verb Quad(const SkPoint pts[3], SkPoint *reducePts)

◆ Cubic()

SkPath::Verb SkReduceOrder::Cubic ( const SkPoint  pts[4],
SkPoint reducePts 
)
static

Definition at line 274 of file SkReduceOrder.cpp.

274 {
276 && SkDPoint::ApproximatelyEqual(a[0], a[3])) {
277 reducePts[0] = a[0];
278 return SkPath::kMove_Verb;
279 }
281 cubic.set(a);
282 SkReduceOrder reducer;
283 int order = reducer.reduce(cubic, kAllow_Quadratics);
284 if (order == 2 || order == 3) { // cubic became line or quad
285 for (int index = 0; index < order; ++index) {
286 *reducePts++ = reducer.fQuad[index].asSkPoint();
287 }
288 }
289 return SkPathOpsPointsToVerb(order - 1);
290}
SkPath::Verb SkPathOpsPointsToVerb(int points)
@ kMove_Verb
Definition: SkPath.h:1466
struct MyStruct a[10]
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:195
static bool ApproximatelyEqual(const SkPoint &a, const SkPoint &b)
int reduce(const SkDCubic &cubic, Quadratics)

◆ Quad()

SkPath::Verb SkReduceOrder::Quad ( const SkPoint  pts[3],
SkPoint reducePts 
)
static

Definition at line 253 of file SkReduceOrder.cpp.

253 {
254 SkDQuad quad;
255 quad.set(a);
256 SkReduceOrder reducer;
257 int order = reducer.reduce(quad);
258 if (order == 2) { // quad became line
259 for (int index = 0; index < order; ++index) {
260 *reducePts++ = reducer.fLine[index].asSkPoint();
261 }
262 }
263 return SkPathOpsPointsToVerb(order - 1);
264}
const SkDQuad & set(const SkPoint pts[kPointCount] SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
Definition: SkPathOpsQuad.h:65

◆ reduce() [1/3]

int SkReduceOrder::reduce ( const SkDCubic cubic,
Quadratics  allowQuadratics 
)

Definition at line 195 of file SkReduceOrder.cpp.

195 {
196 int index, minX, maxX, minY, maxY;
197 int minXSet, minYSet;
198 minX = maxX = minY = maxY = 0;
199 minXSet = minYSet = 0;
200 for (index = 1; index < 4; ++index) {
201 if (cubic[minX].fX > cubic[index].fX) {
202 minX = index;
203 }
204 if (cubic[minY].fY > cubic[index].fY) {
205 minY = index;
206 }
207 if (cubic[maxX].fX < cubic[index].fX) {
208 maxX = index;
209 }
210 if (cubic[maxY].fY < cubic[index].fY) {
211 maxY = index;
212 }
213 }
214 for (index = 0; index < 4; ++index) {
215 double cx = cubic[index].fX;
216 double cy = cubic[index].fY;
217 double denom = std::max(fabs(cx), std::max(fabs(cy),
218 std::max(fabs(cubic[minX].fX), fabs(cubic[minY].fY))));
219 if (denom == 0) {
220 minXSet |= 1 << index;
221 minYSet |= 1 << index;
222 continue;
223 }
224 double inv = 1 / denom;
225 if (approximately_equal_half(cx * inv, cubic[minX].fX * inv)) {
226 minXSet |= 1 << index;
227 }
228 if (approximately_equal_half(cy * inv, cubic[minY].fY * inv)) {
229 minYSet |= 1 << index;
230 }
231 }
232 if (minXSet == 0xF) { // test for vertical line
233 if (minYSet == 0xF) { // return 1 if all four are coincident
235 }
236 return vertical_line(cubic, fCubic);
237 }
238 if (minYSet == 0xF) { // test for horizontal line
240 }
241 int result = check_linear(cubic, minX, maxX, minY, maxY, fCubic);
242 if (result) {
243 return result;
244 }
245 if (allowQuadratics == SkReduceOrder::kAllow_Quadratics
247 return result;
248 }
249 fCubic = cubic;
250 return 4;
251}
static SkM44 inv(const SkM44 &m)
Definition: 3d.cpp:26
bool approximately_equal_half(double x, double y)
static int coincident_line(const SkDQuad &quad, SkDQuad &reduction)
static int check_linear(const SkDQuad &quad, int minX, int maxX, int minY, int maxY, SkDQuad &reduction)
static int horizontal_line(const SkDQuad &quad, SkDQuad &reduction)
static int check_quadratic(const SkDCubic &cubic, SkDCubic &reduction)
static int vertical_line(const SkDQuad &quad, SkDQuad &reduction)
GAsyncResult * result
static float max(float r, float g, float b)
Definition: hsl.cpp:49
SkDCubic fCubic
Definition: SkReduceOrder.h:34

◆ reduce() [2/3]

int SkReduceOrder::reduce ( const SkDLine line)

Definition at line 17 of file SkReduceOrder.cpp.

17 {
18 fLine[0] = line[0];
19 int different = line[0] != line[1];
20 fLine[1] = line[different];
21 return 1 + different;
22}

◆ reduce() [3/3]

int SkReduceOrder::reduce ( const SkDQuad quad)

Definition at line 62 of file SkReduceOrder.cpp.

62 {
63 int index, minX, maxX, minY, maxY;
64 int minXSet, minYSet;
65 minX = maxX = minY = maxY = 0;
66 minXSet = minYSet = 0;
67 for (index = 1; index < 3; ++index) {
68 if (quad[minX].fX > quad[index].fX) {
69 minX = index;
70 }
71 if (quad[minY].fY > quad[index].fY) {
72 minY = index;
73 }
74 if (quad[maxX].fX < quad[index].fX) {
75 maxX = index;
76 }
77 if (quad[maxY].fY < quad[index].fY) {
78 maxY = index;
79 }
80 }
81 for (index = 0; index < 3; ++index) {
82 if (AlmostEqualUlps(quad[index].fX, quad[minX].fX)) {
83 minXSet |= 1 << index;
84 }
85 if (AlmostEqualUlps(quad[index].fY, quad[minY].fY)) {
86 minYSet |= 1 << index;
87 }
88 }
89 if ((minXSet & 0x05) == 0x5 && (minYSet & 0x05) == 0x5) { // test for degenerate
90 // this quad starts and ends at the same place, so never contributes
91 // to the fill
92 return coincident_line(quad, fQuad);
93 }
94 if (minXSet == 0x7) { // test for vertical line
95 return vertical_line(quad, fQuad);
96 }
97 if (minYSet == 0x7) { // test for horizontal line
98 return horizontal_line(quad, fQuad);
99 }
100 int result = check_linear(quad, minX, maxX, minY, maxY, fQuad);
101 if (result) {
102 return result;
103 }
104 fQuad = quad;
105 return 3;
106}
bool AlmostEqualUlps(const SkPoint &pt1, const SkPoint &pt2)

Member Data Documentation

◆ fCubic

SkDCubic SkReduceOrder::fCubic

Definition at line 34 of file SkReduceOrder.h.

◆ fLine

SkDLine SkReduceOrder::fLine

Definition at line 32 of file SkReduceOrder.h.

◆ fQuad

SkDQuad SkReduceOrder::fQuad

Definition at line 33 of file SkReduceOrder.h.


The documentation for this union was generated from the following files: