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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 // a is the first control point of the cubic. | 358 // a is the first control point of the cubic. |
359 // ab is the vector from a to the second control point. | 359 // ab is the vector from a to the second control point. |
360 // dc is the vector from the fourth to the third control point. | 360 // dc is the vector from the fourth to the third control point. |
361 // d is the fourth control point. | 361 // d is the fourth control point. |
362 // p is the candidate quadratic control point. | 362 // p is the candidate quadratic control point. |
363 // this assumes that the cubic doesn't inflect and is simple | 363 // this assumes that the cubic doesn't inflect and is simple |
364 bool is_point_within_cubic_tangents(const SkPoint& a, | 364 bool is_point_within_cubic_tangents(const SkPoint& a, |
365 const SkVector& ab, | 365 const SkVector& ab, |
366 const SkVector& dc, | 366 const SkVector& dc, |
367 const SkPoint& d, | 367 const SkPoint& d, |
368 SkPath::Direction dir, | 368 SkPathPriv::FirstDirection dir, |
369 const SkPoint p) { | 369 const SkPoint p) { |
370 SkVector ap = p - a; | 370 SkVector ap = p - a; |
371 SkScalar apXab = ap.cross(ab); | 371 SkScalar apXab = ap.cross(ab); |
372 if (SkPath::kCW_Direction == dir) { | 372 if (SkPathPriv::kCW_FirstDirection == dir) { |
373 if (apXab > 0) { | 373 if (apXab > 0) { |
374 return false; | 374 return false; |
375 } | 375 } |
376 } else { | 376 } else { |
377 SkASSERT(SkPath::kCCW_Direction == dir); | 377 SkASSERT(SkPathPriv::kCCW_FirstDirection == dir); |
378 if (apXab < 0) { | 378 if (apXab < 0) { |
379 return false; | 379 return false; |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 SkVector dp = p - d; | 383 SkVector dp = p - d; |
384 SkScalar dpXdc = dp.cross(dc); | 384 SkScalar dpXdc = dp.cross(dc); |
385 if (SkPath::kCW_Direction == dir) { | 385 if (SkPathPriv::kCW_FirstDirection == dir) { |
386 if (dpXdc < 0) { | 386 if (dpXdc < 0) { |
387 return false; | 387 return false; |
388 } | 388 } |
389 } else { | 389 } else { |
390 SkASSERT(SkPath::kCCW_Direction == dir); | 390 SkASSERT(SkPathPriv::kCCW_FirstDirection == dir); |
391 if (dpXdc > 0) { | 391 if (dpXdc > 0) { |
392 return false; | 392 return false; |
393 } | 393 } |
394 } | 394 } |
395 return true; | 395 return true; |
396 } | 396 } |
397 | 397 |
398 void convert_noninflect_cubic_to_quads(const SkPoint p[4], | 398 void convert_noninflect_cubic_to_quads(const SkPoint p[4], |
399 SkScalar toleranceSqd, | 399 SkScalar toleranceSqd, |
400 bool constrainWithinTangents, | 400 bool constrainWithinTangents, |
401 SkPath::Direction dir, | 401 SkPathPriv::FirstDirection dir, |
402 SkTArray<SkPoint, true>* quads, | 402 SkTArray<SkPoint, true>* quads, |
403 int sublevel = 0) { | 403 int sublevel = 0) { |
404 | 404 |
405 // Notation: Point a is always p[0]. Point b is p[1] unless p[1] == p[0], in
which case it is | 405 // Notation: Point a is always p[0]. Point b is p[1] unless p[1] == p[0], in
which case it is |
406 // p[2]. Point d is always p[3]. Point c is p[2] unless p[2] == p[3], in whi
ch case it is p[1]. | 406 // p[2]. Point d is always p[3]. Point c is p[2] unless p[2] == p[3], in whi
ch case it is p[1]. |
407 | 407 |
408 SkVector ab = p[1] - p[0]; | 408 SkVector ab = p[1] - p[0]; |
409 SkVector dc = p[2] - p[3]; | 409 SkVector dc = p[2] - p[3]; |
410 | 410 |
411 if (ab.isZero()) { | 411 if (ab.isZero()) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, | 548 bool constrainWithinTangents, |
549 SkPath::Direction dir, | 549 SkPathPriv::FirstDirection dir, |
550 SkTArray<SkPoint, true>* quads) { | 550 SkTArray<SkPoint, true>* quads) { |
551 SkPoint chopped[10]; | 551 SkPoint chopped[10]; |
552 int count = SkChopCubicAtInflections(p, chopped); | 552 int count = SkChopCubicAtInflections(p, chopped); |
553 | 553 |
554 // base tolerance is 1 pixel. | 554 // base tolerance is 1 pixel. |
555 static const SkScalar kTolerance = SK_Scalar1; | 555 static const SkScalar kTolerance = SK_Scalar1; |
556 const SkScalar tolSqd = SkScalarSquare(SkScalarMul(tolScale, kTolerance)); | 556 const SkScalar tolSqd = SkScalarSquare(SkScalarMul(tolScale, kTolerance)); |
557 | 557 |
558 for (int i = 0; i < count; ++i) { | 558 for (int i = 0; i < count; ++i) { |
559 SkPoint* cubic = chopped + 3*i; | 559 SkPoint* cubic = chopped + 3*i; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 set_loop_klm(d, controlK, controlL, controlM); | 807 set_loop_klm(d, controlK, controlL, controlM); |
808 } else if (kCusp_SkCubicType == cType) { | 808 } else if (kCusp_SkCubicType == cType) { |
809 SkASSERT(0.f == d[0]); | 809 SkASSERT(0.f == d[0]); |
810 set_cusp_klm(d, controlK, controlL, controlM); | 810 set_cusp_klm(d, controlK, controlL, controlM); |
811 } else if (kQuadratic_SkCubicType == cType) { | 811 } else if (kQuadratic_SkCubicType == cType) { |
812 set_quadratic_klm(d, controlK, controlL, controlM); | 812 set_quadratic_klm(d, controlK, controlL, controlM); |
813 } | 813 } |
814 | 814 |
815 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); | 815 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); |
816 } | 816 } |
OLD | NEW |