uint32_t GrPathUtils::generateCubicPoints(const GrPoint& p0, const GrPoint& p1, const GrPoint& p2, const GrPoint& p3, GrScalar tolSqd, GrPoint** points, uint32_t pointsLeft) { if (pointsLeft < 2 || (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd && p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) { (*points)[0] = p3; *points += 1; return 1; } GrPoint q[] = { { GrScalarAve(p0.fX, p1.fX), GrScalarAve(p0.fY, p1.fY) }, { GrScalarAve(p1.fX, p2.fX), GrScalarAve(p1.fY, p2.fY) }, { GrScalarAve(p2.fX, p3.fX), GrScalarAve(p2.fY, p3.fY) } }; GrPoint r[] = { { GrScalarAve(q[0].fX, q[1].fX), GrScalarAve(q[0].fY, q[1].fY) }, { GrScalarAve(q[1].fX, q[2].fX), GrScalarAve(q[1].fY, q[2].fY) } }; GrPoint s = { GrScalarAve(r[0].fX, r[1].fX), GrScalarAve(r[0].fY, r[1].fY) }; pointsLeft >>= 1; uint32_t a = generateCubicPoints(p0, q[0], r[0], s, tolSqd, points, pointsLeft); uint32_t b = generateCubicPoints(s, r[1], q[2], p3, tolSqd, points, pointsLeft); return a + b; }
uint32_t GrPathUtils::generateQuadraticPoints(const GrPoint& p0, const GrPoint& p1, const GrPoint& p2, GrScalar tolSqd, GrPoint** points, uint32_t pointsLeft) { if (pointsLeft < 2 || (p1.distanceToLineSegmentBetweenSqd(p0, p2)) < tolSqd) { (*points)[0] = p2; *points += 1; return 1; } GrPoint q[] = { { GrScalarAve(p0.fX, p1.fX), GrScalarAve(p0.fY, p1.fY) }, { GrScalarAve(p1.fX, p2.fX), GrScalarAve(p1.fY, p2.fY) }, }; GrPoint r = { GrScalarAve(q[0].fX, q[1].fX), GrScalarAve(q[0].fY, q[1].fY) }; pointsLeft >>= 1; uint32_t a = generateQuadraticPoints(p0, q[0], r, tolSqd, points, pointsLeft); uint32_t b = generateQuadraticPoints(r, q[1], p2, tolSqd, points, pointsLeft); return a + b; }