OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkGeometry.h" | 10 #include "SkGeometry.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 // if we get here, we need to force dst to be monotonic, even though | 375 // if we get here, we need to force dst to be monotonic, even though |
376 // we couldn't compute a unit_divide value (probably underflow). | 376 // we couldn't compute a unit_divide value (probably underflow). |
377 b = SkScalarAbs(a - b) < SkScalarAbs(b - c) ? a : c; | 377 b = SkScalarAbs(a - b) < SkScalarAbs(b - c) ? a : c; |
378 } | 378 } |
379 dst[0].set(a, src[0].fY); | 379 dst[0].set(a, src[0].fY); |
380 dst[1].set(b, src[1].fY); | 380 dst[1].set(b, src[1].fY); |
381 dst[2].set(c, src[2].fY); | 381 dst[2].set(c, src[2].fY); |
382 return 0; | 382 return 0; |
383 } | 383 } |
384 | 384 |
385 // F(t) = a (1 - t) ^ 2 + 2 b t (1 - t) + c t ^ 2 | 385 float SkGetTQuadAtMaxCurvature(const SkPoint src[3]) { |
386 // F'(t) = 2 (b - a) + 2 (a - 2b + c) t | 386 |
387 // F''(t) = 2 (a - 2b + c) | |
388 // | |
389 // A = 2 (b - a) | |
390 // B = 2 (a - 2b + c) | |
391 // | |
392 // Maximum curvature for a quadratic means solving | |
393 // Fx' Fx'' + Fy' Fy'' = 0 | |
394 // | |
395 // t = - (Ax Bx + Ay By) / (Bx ^ 2 + By ^ 2) | |
396 // | |
397 int SkChopQuadAtMaxCurvature(const SkPoint src[3], SkPoint dst[5]) | |
398 { | |
399 SkScalar Ax = src[1].fX - src[0].fX; | 387 SkScalar Ax = src[1].fX - src[0].fX; |
400 SkScalar Ay = src[1].fY - src[0].fY; | 388 SkScalar Ay = src[1].fY - src[0].fY; |
401 SkScalar Bx = src[0].fX - src[1].fX - src[1].fX + src[2].fX; | 389 SkScalar Bx = src[0].fX - src[1].fX - src[1].fX + src[2].fX; |
402 SkScalar By = src[0].fY - src[1].fY - src[1].fY + src[2].fY; | 390 SkScalar By = src[0].fY - src[1].fY - src[1].fY + src[2].fY; |
403 SkScalar t = 0; // 0 means don't chop | 391 SkScalar t = 0; // 0 means don't chop |
404 | 392 |
405 #ifdef SK_SCALAR_IS_FLOAT | 393 #ifdef SK_SCALAR_IS_FLOAT |
406 (void)valid_unit_divide(-(Ax * Bx + Ay * By), Bx * Bx + By * By, &t); | 394 (void)valid_unit_divide(-(Ax * Bx + Ay * By), Bx * Bx + By * By, &t); |
407 #else | 395 #else |
408 // !!! should I use SkFloat here? seems like it | 396 // !!! should I use SkFloat here? seems like it |
(...skipping 11 matching lines...) Expand all Loading... | |
420 SkASSERT(!denom.isNeg()); | 408 SkASSERT(!denom.isNeg()); |
421 if (numer < denom) | 409 if (numer < denom) |
422 { | 410 { |
423 t = numer.getFixedDiv(denom); | 411 t = numer.getFixedDiv(denom); |
424 SkASSERT(t >= 0 && t <= SK_Fixed1); // assert that we're numeric ally stable (ha!) | 412 SkASSERT(t >= 0 && t <= SK_Fixed1); // assert that we're numeric ally stable (ha!) |
425 if ((unsigned)t >= SK_Fixed1) // runtime check for numeric al stability | 413 if ((unsigned)t >= SK_Fixed1) // runtime check for numeric al stability |
426 t = 0; // ignore the chop | 414 t = 0; // ignore the chop |
427 } | 415 } |
428 } | 416 } |
429 #endif | 417 #endif |
418 return t; | |
419 } | |
430 | 420 |
421 // F(t) = a (1 - t) ^ 2 + 2 b t (1 - t) + c t ^ 2 | |
bsalomon
2013/07/10 15:14:36
Maybe these comments belong with the new function
| |
422 // F'(t) = 2 (b - a) + 2 (a - 2b + c) t | |
423 // F''(t) = 2 (a - 2b + c) | |
424 // | |
425 // A = 2 (b - a) | |
426 // B = 2 (a - 2b + c) | |
427 // | |
428 // Maximum curvature for a quadratic means solving | |
429 // Fx' Fx'' + Fy' Fy'' = 0 | |
430 // | |
431 // t = - (Ax Bx + Ay By) / (Bx ^ 2 + By ^ 2) | |
432 // | |
433 int SkChopQuadAtMaxCurvature(const SkPoint src[3], SkPoint dst[5]) | |
434 { | |
435 SkScalar t = SkGetTQuadAtMaxCurvature(src); | |
431 if (t == 0) | 436 if (t == 0) |
432 { | 437 { |
433 memcpy(dst, src, 3 * sizeof(SkPoint)); | 438 memcpy(dst, src, 3 * sizeof(SkPoint)); |
434 return 1; | 439 return 1; |
435 } | 440 } |
436 else | 441 else |
437 { | 442 { |
438 SkChopQuadAt(src, dst, t); | 443 SkChopQuadAt(src, dst, t); |
439 return 2; | 444 return 2; |
440 } | 445 } |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1658 } | 1663 } |
1659 if (this->findYExtrema(&t)) { | 1664 if (this->findYExtrema(&t)) { |
1660 this->evalAt(t, &pts[count++]); | 1665 this->evalAt(t, &pts[count++]); |
1661 } | 1666 } |
1662 bounds->set(pts, count); | 1667 bounds->set(pts, count); |
1663 } | 1668 } |
1664 | 1669 |
1665 void SkConic::computeFastBounds(SkRect* bounds) const { | 1670 void SkConic::computeFastBounds(SkRect* bounds) const { |
1666 bounds->set(fPts, 3); | 1671 bounds->set(fPts, 3); |
1667 } | 1672 } |
OLD | NEW |