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 #ifndef SkGeometry_DEFINED | 8 #ifndef SkGeometry_DEFINED |
9 #define SkGeometry_DEFINED | 9 #define SkGeometry_DEFINED |
10 | 10 |
11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
12 #include "SkNx.h" | 12 #include "SkNx.h" |
13 | 13 |
14 static inline Sk2s from_point(const SkPoint& point) { | 14 static inline Sk2s from_point(const SkPoint& point) { |
15 return Sk2s::Load(&point.fX); | 15 return Sk2s::Load(&point.fX); |
16 } | 16 } |
17 | 17 |
18 static inline SkPoint to_point(const Sk2s& x) { | 18 static inline SkPoint to_point(const Sk2s& x) { |
19 SkPoint point; | 19 SkPoint point; |
20 x.store(&point.fX); | 20 x.store(&point.fX); |
21 return point; | 21 return point; |
22 } | 22 } |
23 | 23 |
24 static inline Sk2s sk2s_cubic_eval(const Sk2s& A, const Sk2s& B, const Sk2s& C,
const Sk2s& D, | |
25 const Sk2s& t) { | |
26 return ((A * t + B) * t + C) * t + D; | |
27 } | |
28 | |
29 static Sk2s times_2(const Sk2s& value) { | 24 static Sk2s times_2(const Sk2s& value) { |
30 return value + value; | 25 return value + value; |
31 } | 26 } |
32 | 27 |
33 /** Given a quadratic equation Ax^2 + Bx + C = 0, return 0, 1, 2 roots for the | 28 /** Given a quadratic equation Ax^2 + Bx + C = 0, return 0, 1, 2 roots for the |
34 equation. | 29 equation. |
35 */ | 30 */ |
36 int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]); | 31 int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]); |
37 | 32 |
38 /////////////////////////////////////////////////////////////////////////////// | 33 /////////////////////////////////////////////////////////////////////////////// |
39 | 34 |
40 SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t); | 35 SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t); |
41 SkPoint SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t); | 36 SkPoint SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t); |
42 | 37 |
43 /** Set pt to the point on the src quadratic specified by t. t must be | 38 /** Set pt to the point on the src quadratic specified by t. t must be |
44 0 <= t <= 1.0 | 39 0 <= t <= 1.0 |
45 */ | 40 */ |
46 void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt, SkVector* tange
nt = nullptr); | 41 void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt, SkVector* tange
nt = nullptr); |
47 | 42 |
48 /** | |
49 * output is : eval(t) == coeff[0] * t^2 + coeff[1] * t + coeff[2] | |
50 */ | |
51 void SkQuadToCoeff(const SkPoint pts[3], SkPoint coeff[3]); | |
52 | |
53 /** | |
54 * output is : eval(t) == coeff[0] * t^3 + coeff[1] * t^2 + coeff[2] * t + coef
f[3] | |
55 */ | |
56 void SkCubicToCoeff(const SkPoint pts[4], SkPoint coeff[4]); | |
57 | |
58 /** Given a src quadratic bezier, chop it at the specified t value, | 43 /** Given a src quadratic bezier, chop it at the specified t value, |
59 where 0 < t < 1, and return the two new quadratics in dst: | 44 where 0 < t < 1, and return the two new quadratics in dst: |
60 dst[0..2] and dst[2..4] | 45 dst[0..2] and dst[2..4] |
61 */ | 46 */ |
62 void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t); | 47 void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t); |
63 | 48 |
64 /** Given a src quadratic bezier, chop it at the specified t == 1/2, | 49 /** Given a src quadratic bezier, chop it at the specified t == 1/2, |
65 The new quads are returned in dst[0..2] and dst[2..4] | 50 The new quads are returned in dst[0..2] and dst[2..4] |
66 */ | 51 */ |
67 void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]); | 52 void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 private: | 400 private: |
416 enum { | 401 enum { |
417 kQuadCount = 8, // should handle most conics | 402 kQuadCount = 8, // should handle most conics |
418 kPointCount = 1 + 2 * kQuadCount, | 403 kPointCount = 1 + 2 * kQuadCount, |
419 }; | 404 }; |
420 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; | 405 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; |
421 int fQuadCount; // #quads for current usage | 406 int fQuadCount; // #quads for current usage |
422 }; | 407 }; |
423 | 408 |
424 #endif | 409 #endif |
OLD | NEW |