| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 "SkGeometry.h" | 8 #include "SkGeometry.h" |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkNx.h" | 10 #include "SkNx.h" |
| 11 | 11 |
| 12 #if 0 |
| 12 static Sk2s from_point(const SkPoint& point) { | 13 static Sk2s from_point(const SkPoint& point) { |
| 13 return Sk2s::Load(&point.fX); | 14 return Sk2s::Load(&point.fX); |
| 14 } | 15 } |
| 15 | 16 |
| 16 static SkPoint to_point(const Sk2s& x) { | 17 static SkPoint to_point(const Sk2s& x) { |
| 17 SkPoint point; | 18 SkPoint point; |
| 18 x.store(&point.fX); | 19 x.store(&point.fX); |
| 19 return point; | 20 return point; |
| 20 } | 21 } |
| 22 #endif |
| 21 | 23 |
| 22 static SkVector to_vector(const Sk2s& x) { | 24 static SkVector to_vector(const Sk2s& x) { |
| 23 SkVector vector; | 25 SkVector vector; |
| 24 x.store(&vector.fX); | 26 x.store(&vector.fX); |
| 25 return vector; | 27 return vector; |
| 26 } | 28 } |
| 27 | 29 |
| 28 /** If defined, this makes eval_quad and eval_cubic do more setup (sometimes | 30 /** If defined, this makes eval_quad and eval_cubic do more setup (sometimes |
| 29 involving integer multiplies by 2 or 3, but fewer calls to SkScalarMul. | 31 involving integer multiplies by 2 or 3, but fewer calls to SkScalarMul. |
| 30 May also introduce overflow of fixed when we compute our setup. | 32 May also introduce overflow of fixed when we compute our setup. |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 447 |
| 446 dst[0] = src[0]; | 448 dst[0] = src[0]; |
| 447 dst[1] = to_point(ab); | 449 dst[1] = to_point(ab); |
| 448 dst[2] = to_point(abc); | 450 dst[2] = to_point(abc); |
| 449 dst[3] = to_point(abcd); | 451 dst[3] = to_point(abcd); |
| 450 dst[4] = to_point(bcd); | 452 dst[4] = to_point(bcd); |
| 451 dst[5] = to_point(cd); | 453 dst[5] = to_point(cd); |
| 452 dst[6] = src[3]; | 454 dst[6] = src[3]; |
| 453 } | 455 } |
| 454 | 456 |
| 457 void SkCubicToPoly(const SkPoint pts[4], SkPoint coeff[4]) { |
| 458 Sk2s p0 = from_point(pts[0]); |
| 459 Sk2s p1 = from_point(pts[1]); |
| 460 Sk2s p2 = from_point(pts[2]); |
| 461 Sk2s p3 = from_point(pts[3]); |
| 462 |
| 463 const Sk2s three(3); |
| 464 Sk2s p1minusp2 = p1 - p2; |
| 465 |
| 466 Sk2s D = p0; |
| 467 Sk2s A = p3 + three * p1minusp2 - D; |
| 468 Sk2s B = three * (D - p1minusp2 - p1); |
| 469 Sk2s C = three * (p1 - D); |
| 470 |
| 471 coeff[0] = to_point(A); |
| 472 coeff[1] = to_point(B); |
| 473 coeff[2] = to_point(C); |
| 474 coeff[3] = to_point(D); |
| 475 } |
| 476 |
| 477 SkPoint SkEvalCubicPolyAt(const SkPoint coeff[4], SkScalar t) { |
| 478 Sk2s pt = sk2s_cubic_eval(from_point(coeff[0]), from_point(coeff[1]), |
| 479 from_point(coeff[2]), from_point(coeff[3]), Sk2s(t
)); |
| 480 return to_point(pt); |
| 481 } |
| 482 |
| 455 /* http://code.google.com/p/skia/issues/detail?id=32 | 483 /* http://code.google.com/p/skia/issues/detail?id=32 |
| 456 | 484 |
| 457 This test code would fail when we didn't check the return result of | 485 This test code would fail when we didn't check the return result of |
| 458 valid_unit_divide in SkChopCubicAt(... tValues[], int roots). The reason is | 486 valid_unit_divide in SkChopCubicAt(... tValues[], int roots). The reason is |
| 459 that after the first chop, the parameters to valid_unit_divide are equal | 487 that after the first chop, the parameters to valid_unit_divide are equal |
| 460 (thanks to finite float precision and rounding in the subtracts). Thus | 488 (thanks to finite float precision and rounding in the subtracts). Thus |
| 461 even though the 2nd tValue looks < 1.0, after we renormalize it, we end | 489 even though the 2nd tValue looks < 1.0, after we renormalize it, we end |
| 462 up with 1.0, hence the need to check and just return the last cubic as | 490 up with 1.0, hence the need to check and just return the last cubic as |
| 463 a degenerate clump of 4 points in the sampe place. | 491 a degenerate clump of 4 points in the sampe place. |
| 464 | 492 |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1562 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
| 1535 } | 1563 } |
| 1536 if (userMatrix) { | 1564 if (userMatrix) { |
| 1537 matrix.postConcat(*userMatrix); | 1565 matrix.postConcat(*userMatrix); |
| 1538 } | 1566 } |
| 1539 for (int i = 0; i < conicCount; ++i) { | 1567 for (int i = 0; i < conicCount; ++i) { |
| 1540 matrix.mapPoints(dst[i].fPts, 3); | 1568 matrix.mapPoints(dst[i].fPts, 3); |
| 1541 } | 1569 } |
| 1542 return conicCount; | 1570 return conicCount; |
| 1543 } | 1571 } |
| OLD | NEW |