OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrPathUtils.h" | 8 #include "GrPathUtils.h" |
9 | 9 |
10 #include "GrTypes.h" | 10 #include "GrTypes.h" |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 toleranceSqd, | 538 toleranceSqd, |
539 constrainWithinTangents, | 539 constrainWithinTangents, |
540 dir, | 540 dir, |
541 quads, | 541 quads, |
542 sublevel + 1); | 542 sublevel + 1); |
543 } | 543 } |
544 } | 544 } |
545 | 545 |
546 void GrPathUtils::convertCubicToQuads(const SkPoint p[4], | 546 void GrPathUtils::convertCubicToQuads(const SkPoint p[4], |
547 SkScalar tolScale, | 547 SkScalar tolScale, |
548 bool constrainWithinTangents, | |
549 SkPathPriv::FirstDirection dir, | |
550 SkTArray<SkPoint, true>* quads) { | 548 SkTArray<SkPoint, true>* quads) { |
551 SkPoint chopped[10]; | 549 SkPoint chopped[10]; |
552 int count = SkChopCubicAtInflections(p, chopped); | 550 int count = SkChopCubicAtInflections(p, chopped); |
553 | 551 |
554 // base tolerance is 1 pixel. | 552 const SkScalar tolSqd = SkScalarSquare(tolScale); |
555 static const SkScalar kTolerance = SK_Scalar1; | |
556 const SkScalar tolSqd = SkScalarSquare(SkScalarMul(tolScale, kTolerance)); | |
557 | 553 |
558 for (int i = 0; i < count; ++i) { | 554 for (int i = 0; i < count; ++i) { |
559 SkPoint* cubic = chopped + 3*i; | 555 SkPoint* cubic = chopped + 3*i; |
560 convert_noninflect_cubic_to_quads(cubic, tolSqd, constrainWithinTangents
, dir, quads); | 556 // The direction param is ignored if the third param is false. |
| 557 convert_noninflect_cubic_to_quads(cubic, tolSqd, false, |
| 558 SkPathPriv::kCCW_FirstDirection, quads
); |
561 } | 559 } |
| 560 } |
562 | 561 |
| 562 void GrPathUtils::convertCubicToQuadsConstrainToTangents(const SkPoint p[4], |
| 563 SkScalar tolScale, |
| 564 SkPathPriv::FirstDirect
ion dir, |
| 565 SkTArray<SkPoint, true>
* quads) { |
| 566 SkPoint chopped[10]; |
| 567 int count = SkChopCubicAtInflections(p, chopped); |
| 568 |
| 569 const SkScalar tolSqd = SkScalarSquare(tolScale); |
| 570 |
| 571 for (int i = 0; i < count; ++i) { |
| 572 SkPoint* cubic = chopped + 3*i; |
| 573 convert_noninflect_cubic_to_quads(cubic, tolSqd, true, dir, quads); |
| 574 } |
563 } | 575 } |
564 | 576 |
565 //////////////////////////////////////////////////////////////////////////////// | 577 //////////////////////////////////////////////////////////////////////////////// |
566 | 578 |
567 // Solves linear system to extract klm | 579 // Solves linear system to extract klm |
568 // P.K = k (similarly for l, m) | 580 // P.K = k (similarly for l, m) |
569 // Where P is matrix of control points | 581 // Where P is matrix of control points |
570 // K is coefficients for the line K | 582 // K is coefficients for the line K |
571 // k is vector of values of K evaluated at the control points | 583 // k is vector of values of K evaluated at the control points |
572 // Solving for K, thus K = P^(-1) . k | 584 // Solving for K, thus K = P^(-1) . k |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 set_loop_klm(d, controlK, controlL, controlM); | 819 set_loop_klm(d, controlK, controlL, controlM); |
808 } else if (kCusp_SkCubicType == cType) { | 820 } else if (kCusp_SkCubicType == cType) { |
809 SkASSERT(0.f == d[0]); | 821 SkASSERT(0.f == d[0]); |
810 set_cusp_klm(d, controlK, controlL, controlM); | 822 set_cusp_klm(d, controlK, controlL, controlM); |
811 } else if (kQuadratic_SkCubicType == cType) { | 823 } else if (kQuadratic_SkCubicType == cType) { |
812 set_quadratic_klm(d, controlK, controlL, controlM); | 824 set_quadratic_klm(d, controlK, controlL, controlM); |
813 } | 825 } |
814 | 826 |
815 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); | 827 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); |
816 } | 828 } |
OLD | NEW |