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); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 dst[0..3],dst[3..6],...,dst[3*t_count..3*(t_count+1)] | 116 dst[0..3],dst[3..6],...,dst[3*t_count..3*(t_count+1)] |
101 */ | 117 */ |
102 void SkChopCubicAt(const SkPoint src[4], SkPoint dst[], const SkScalar t[], | 118 void SkChopCubicAt(const SkPoint src[4], SkPoint dst[], const SkScalar t[], |
103 int t_count); | 119 int t_count); |
104 | 120 |
105 /** Given a src cubic bezier, chop it at the specified t == 1/2, | 121 /** Given a src cubic bezier, chop it at the specified t == 1/2, |
106 The new cubics are returned in dst[0..3] and dst[3..6] | 122 The new cubics are returned in dst[0..3] and dst[3..6] |
107 */ | 123 */ |
108 void SkChopCubicAtHalf(const SkPoint src[4], SkPoint dst[7]); | 124 void SkChopCubicAtHalf(const SkPoint src[4], SkPoint dst[7]); |
109 | 125 |
| 126 void SkCubicToPoly(const SkPoint pts[4], SkPoint coeff[4]); |
| 127 SkPoint SkEvalCubicPolyAt(const SkPoint coeff[4], SkScalar t); |
| 128 |
110 /** Given the 4 coefficients for a cubic bezier (either X or Y values), look | 129 /** Given the 4 coefficients for a cubic bezier (either X or Y values), look |
111 for extrema, and return the number of t-values that are found that represent | 130 for extrema, and return the number of t-values that are found that represent |
112 these extrema. If the cubic has no extrema betwee (0..1) exclusive, the | 131 these extrema. If the cubic has no extrema betwee (0..1) exclusive, the |
113 function returns 0. | 132 function returns 0. |
114 Returned count tValues[] | 133 Returned count tValues[] |
115 0 ignored | 134 0 ignored |
116 1 0 < tValues[0] < 1 | 135 1 0 < tValues[0] < 1 |
117 2 0 < tValues[0] < tValues[1] < 1 | 136 2 0 < tValues[0] < tValues[1] < 1 |
118 */ | 137 */ |
119 int SkFindCubicExtrema(SkScalar a, SkScalar b, SkScalar c, SkScalar d, | 138 int SkFindCubicExtrema(SkScalar a, SkScalar b, SkScalar c, SkScalar d, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 private: | 323 private: |
305 enum { | 324 enum { |
306 kQuadCount = 8, // should handle most conics | 325 kQuadCount = 8, // should handle most conics |
307 kPointCount = 1 + 2 * kQuadCount, | 326 kPointCount = 1 + 2 * kQuadCount, |
308 }; | 327 }; |
309 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; | 328 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; |
310 int fQuadCount; // #quads for current usage | 329 int fQuadCount; // #quads for current usage |
311 }; | 330 }; |
312 | 331 |
313 #endif | 332 #endif |
OLD | NEW |