Flutter Engine
The Flutter Engine
Classes | Functions
PathOpsTestCommon.h File Reference
#include "include/core/SkScalar.h"
#include "include/private/base/SkTArray.h"
#include "src/pathops/SkPathOpsPoint.h"

Go to the source code of this file.

Classes

struct  QuadPts
 
struct  ConicPts
 
struct  CubicPts
 

Functions

void CubicPathToQuads (const SkPath &cubicPath, SkPath *quadPath)
 
void CubicPathToSimple (const SkPath &cubicPath, SkPath *simplePath)
 
void CubicToQuads (const SkDCubic &cubic, double precision, skia_private::TArray< SkDQuad, true > &quads)
 
bool ValidBounds (const SkPathOpsBounds &)
 
bool ValidConic (const SkDConic &cubic)
 
bool ValidCubic (const SkDCubic &cubic)
 
bool ValidLine (const SkDLine &line)
 
bool ValidPoint (const SkDPoint &pt)
 
bool ValidPoints (const SkPoint *pts, int count)
 
bool ValidQuad (const SkDQuad &quad)
 
bool ValidVector (const SkDVector &v)
 

Function Documentation

◆ CubicPathToQuads()

void CubicPathToQuads ( const SkPath cubicPath,
SkPath quadPath 
)

Definition at line 178 of file PathOpsTestCommon.cpp.

178 {
179 quadPath->reset();
182 for (auto [verb, pts, w] : SkPathPriv::Iterate(cubicPath)) {
183 switch (verb) {
185 quadPath->moveTo(pts[0].fX, pts[0].fY);
186 continue;
188 quadPath->lineTo(pts[1].fX, pts[1].fY);
189 break;
191 quadPath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
192 break;
194 quads.clear();
195 cubic.set(pts);
196 CubicToQuads(cubic, cubic.calcPrecision(), quads);
197 for (int index = 0; index < quads.size(); ++index) {
198 SkPoint qPts[2] = {
199 quads[index][1].asSkPoint(),
200 quads[index][2].asSkPoint()
201 };
202 quadPath->quadTo(qPts[0].fX, qPts[0].fY, qPts[1].fX, qPts[1].fY);
203 }
204 break;
206 quadPath->close();
207 break;
208 default:
209 SkDEBUGFAIL("bad verb");
210 return;
211 }
212 }
213}
void CubicToQuads(const SkDCubic &cubic, double precision, TArray< SkDQuad, true > &quads)
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
@ kClose
SkPath::RawIter returns 0 points.
@ kCubic
SkPath::RawIter returns 4 points.
@ kQuad
SkPath::RawIter returns 3 points.
@ kMove
SkPath::RawIter returns 1 point.
@ kLine
SkPath::RawIter returns 2 points.
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & reset()
Definition: SkPath.cpp:370
SkPath & quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Definition: SkPath.cpp:746
SkPath & close()
Definition: SkPath.cpp:823
int size() const
Definition: SkTArray.h:421
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:195
SkScalar w

◆ CubicPathToSimple()

void CubicPathToSimple ( const SkPath cubicPath,
SkPath simplePath 
)

Definition at line 215 of file PathOpsTestCommon.cpp.

215 {
216 simplePath->reset();
218 for (auto [verb, pts, w] : SkPathPriv::Iterate(cubicPath)) {
219 switch (verb) {
221 simplePath->moveTo(pts[0].fX, pts[0].fY);
222 continue;
224 simplePath->lineTo(pts[1].fX, pts[1].fY);
225 break;
227 simplePath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
228 break;
229 case SkPathVerb::kCubic: {
230 cubic.set(pts);
231 double tInflects[2];
232 int inflections = cubic.findInflections(tInflects);
233 if (inflections > 1 && tInflects[0] > tInflects[1]) {
234 using std::swap;
235 swap(tInflects[0], tInflects[1]);
236 }
237 double lo = 0;
238 for (int index = 0; index <= inflections; ++index) {
239 double hi = index < inflections ? tInflects[index] : 1;
240 SkDCubic part = cubic.subDivide(lo, hi);
241 SkPoint cPts[3];
242 cPts[0] = part[1].asSkPoint();
243 cPts[1] = part[2].asSkPoint();
244 cPts[2] = part[3].asSkPoint();
245 simplePath->cubicTo(cPts[0].fX, cPts[0].fY, cPts[1].fX, cPts[1].fY,
246 cPts[2].fX, cPts[2].fY);
247 lo = hi;
248 }
249 break;
250 }
252 simplePath->close();
253 break;
254 default:
255 SkDEBUGFAIL("bad verb");
256 return;
257 }
258 }
259}
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition: SkPath.cpp:799

◆ CubicToQuads()

void CubicToQuads ( const SkDCubic cubic,
double  precision,
skia_private::TArray< SkDQuad, true > &  quads 
)

Definition at line 148 of file PathOpsTestCommon.cpp.

148 {
150 toQuadraticTs(&cubic, precision, &ts);
151 if (ts.empty()) {
152 SkDQuad quad = cubic.toQuad();
153 quads.push_back(quad);
154 return;
155 }
156 double tStart = 0;
157 for (int i1 = 0; i1 <= ts.size(); ++i1) {
158 const double tEnd = i1 < ts.size() ? ts[i1] : 1;
160 bounds.setBounds(cubic);
161 SkDCubic part = cubic.subDivide(tStart, tEnd);
162 SkDQuad quad = part.toQuad();
163 if (quad[1].fX < bounds.fLeft) {
164 quad[1].fX = bounds.fLeft;
165 } else if (quad[1].fX > bounds.fRight) {
166 quad[1].fX = bounds.fRight;
167 }
168 if (quad[1].fY < bounds.fTop) {
169 quad[1].fY = bounds.fTop;
170 } else if (quad[1].fY > bounds.fBottom) {
171 quad[1].fY = bounds.fBottom;
172 }
173 quads.push_back(quad);
174 tStart = tEnd;
175 }
176}
static void toQuadraticTs(const SkDCubic *cubic, double precision, TArray< double, true > *ts)
bool empty() const
Definition: SkTArray.h:199
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkDQuad toQuad() const

◆ ValidBounds()

bool ValidBounds ( const SkPathOpsBounds bounds)

Definition at line 261 of file PathOpsTestCommon.cpp.

261 {
262 if (SkIsNaN(bounds.fLeft)) {
263 return false;
264 }
265 if (SkIsNaN(bounds.fTop)) {
266 return false;
267 }
268 if (SkIsNaN(bounds.fRight)) {
269 return false;
270 }
271 return !SkIsNaN(bounds.fBottom);
272}
static constexpr bool SkIsNaN(T x)

◆ ValidConic()

bool ValidConic ( const SkDConic cubic)

Definition at line 274 of file PathOpsTestCommon.cpp.

274 {
275 for (int index = 0; index < SkDConic::kPointCount; ++index) {
276 if (!ValidPoint(conic[index])) {
277 return false;
278 }
279 }
280 if (SkDoubleIsNaN(conic.fWeight)) {
281 return false;
282 }
283 return true;
284}
bool ValidPoint(const SkDPoint &pt)
static bool SkDoubleIsNaN(double x)
AI float conic(float tolerance, const SkPoint pts[], float w, const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:287
static const int kPointCount

◆ ValidCubic()

bool ValidCubic ( const SkDCubic cubic)

Definition at line 286 of file PathOpsTestCommon.cpp.

286 {
287 for (int index = 0; index < 4; ++index) {
288 if (!ValidPoint(cubic[index])) {
289 return false;
290 }
291 }
292 return true;
293}

◆ ValidLine()

bool ValidLine ( const SkDLine line)

Definition at line 295 of file PathOpsTestCommon.cpp.

295 {
296 for (int index = 0; index < 2; ++index) {
297 if (!ValidPoint(line[index])) {
298 return false;
299 }
300 }
301 return true;
302}

◆ ValidPoint()

bool ValidPoint ( const SkDPoint pt)

Definition at line 304 of file PathOpsTestCommon.cpp.

304 {
305 if (SkDoubleIsNaN(pt.fX)) {
306 return false;
307 }
308 return !SkDoubleIsNaN(pt.fY);
309}

◆ ValidPoints()

bool ValidPoints ( const SkPoint pts,
int  count 
)

Definition at line 311 of file PathOpsTestCommon.cpp.

311 {
312 for (int index = 0; index < count; ++index) {
313 if (SkIsNaN(pts[index].fX)) {
314 return false;
315 }
316 if (SkIsNaN(pts[index].fY)) {
317 return false;
318 }
319 }
320 return true;
321}
int count
Definition: FontMgrTest.cpp:50

◆ ValidQuad()

bool ValidQuad ( const SkDQuad quad)

Definition at line 323 of file PathOpsTestCommon.cpp.

323 {
324 for (int index = 0; index < 3; ++index) {
325 if (!ValidPoint(quad[index])) {
326 return false;
327 }
328 }
329 return true;
330}

◆ ValidVector()

bool ValidVector ( const SkDVector v)

Definition at line 332 of file PathOpsTestCommon.cpp.

332 {
333 if (SkDoubleIsNaN(v.fX)) {
334 return false;
335 }
336 return !SkDoubleIsNaN(v.fY);
337}