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" |
| 13 |
| 14 static inline Sk2s from_point(const SkPoint& point) { |
| 15 return Sk2s::Load(&point.fX); |
| 16 } |
| 17 |
| 18 static inline SkPoint to_point(const Sk2s& x) { |
| 19 SkPoint point; |
| 20 x.store(&point.fX); |
| 21 return point; |
| 22 } |
| 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 } |
12 | 28 |
13 /** Given a quadratic equation Ax^2 + Bx + C = 0, return 0, 1, 2 roots for the | 29 /** Given a quadratic equation Ax^2 + Bx + C = 0, return 0, 1, 2 roots for the |
14 equation. | 30 equation. |
15 */ | 31 */ |
16 int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]); | 32 int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]); |
17 | 33 |
18 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
19 | 35 |
20 SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t); | 36 SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t); |
21 SkPoint SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t); | 37 SkPoint SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t); |
22 | 38 |
23 /** Set pt to the point on the src quadratic specified by t. t must be | 39 /** Set pt to the point on the src quadratic specified by t. t must be |
24 0 <= t <= 1.0 | 40 0 <= t <= 1.0 |
25 */ | 41 */ |
26 void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt, SkVector* tange
nt = NULL); | 42 void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt, SkVector* tange
nt = NULL); |
27 | 43 |
| 44 /** |
| 45 * output is : eval(t) == coeff[0] * t^2 + coeff[1] * t + coeff[2] |
| 46 */ |
| 47 void SkQuadToCoeff(const SkPoint pts[3], SkPoint coeff[3]); |
| 48 |
| 49 /** |
| 50 * output is : eval(t) == coeff[0] * t^3 + coeff[1] * t^2 + coeff[2] * t + coef
f[3] |
| 51 */ |
| 52 void SkCubicToCoeff(const SkPoint pts[4], SkPoint coeff[4]); |
| 53 |
28 /** Given a src quadratic bezier, chop it at the specified t value, | 54 /** Given a src quadratic bezier, chop it at the specified t value, |
29 where 0 < t < 1, and return the two new quadratics in dst: | 55 where 0 < t < 1, and return the two new quadratics in dst: |
30 dst[0..2] and dst[2..4] | 56 dst[0..2] and dst[2..4] |
31 */ | 57 */ |
32 void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t); | 58 void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t); |
33 | 59 |
34 /** Given a src quadratic bezier, chop it at the specified t == 1/2, | 60 /** Given a src quadratic bezier, chop it at the specified t == 1/2, |
35 The new quads are returned in dst[0..2] and dst[2..4] | 61 The new quads are returned in dst[0..2] and dst[2..4] |
36 */ | 62 */ |
37 void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]); | 63 void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 private: | 330 private: |
305 enum { | 331 enum { |
306 kQuadCount = 8, // should handle most conics | 332 kQuadCount = 8, // should handle most conics |
307 kPointCount = 1 + 2 * kQuadCount, | 333 kPointCount = 1 + 2 * kQuadCount, |
308 }; | 334 }; |
309 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; | 335 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; |
310 int fQuadCount; // #quads for current usage | 336 int fQuadCount; // #quads for current usage |
311 }; | 337 }; |
312 | 338 |
313 #endif | 339 #endif |
OLD | NEW |