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 | |
13 static Sk2s from_point(const SkPoint& point) { | |
14 return Sk2s::Load(&point.fX); | |
15 } | |
16 | |
17 static SkPoint to_point(const Sk2s& x) { | |
18 SkPoint point; | |
19 x.store(&point.fX); | |
20 return point; | |
21 } | |
22 #endif | |
23 | |
24 static SkVector to_vector(const Sk2s& x) { | 12 static SkVector to_vector(const Sk2s& x) { |
25 SkVector vector; | 13 SkVector vector; |
26 x.store(&vector.fX); | 14 x.store(&vector.fX); |
27 return vector; | 15 return vector; |
28 } | 16 } |
29 | 17 |
30 /** If defined, this makes eval_quad and eval_cubic do more setup (sometimes | 18 /** If defined, this makes eval_quad and eval_cubic do more setup (sometimes |
31 involving integer multiplies by 2 or 3, but fewer calls to SkScalarMul. | 19 involving integer multiplies by 2 or 3, but fewer calls to SkScalarMul. |
32 May also introduce overflow of fixed when we compute our setup. | 20 May also introduce overflow of fixed when we compute our setup. |
33 */ | 21 */ |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 Sk2s p12 = interp(p1, p2, tt); | 201 Sk2s p12 = interp(p1, p2, tt); |
214 | 202 |
215 dst[0] = to_point(p0); | 203 dst[0] = to_point(p0); |
216 dst[1] = to_point(p01); | 204 dst[1] = to_point(p01); |
217 dst[2] = to_point(interp(p01, p12, tt)); | 205 dst[2] = to_point(interp(p01, p12, tt)); |
218 dst[3] = to_point(p12); | 206 dst[3] = to_point(p12); |
219 dst[4] = to_point(p2); | 207 dst[4] = to_point(p2); |
220 } | 208 } |
221 | 209 |
222 void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]) { | 210 void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]) { |
223 SkChopQuadAt(src, dst, 0.5f); return; | 211 SkChopQuadAt(src, dst, 0.5f); |
224 } | 212 } |
225 | 213 |
226 /** Quad'(t) = At + B, where | 214 /** Quad'(t) = At + B, where |
227 A = 2(a - 2b + c) | 215 A = 2(a - 2b + c) |
228 B = 2(b - a) | 216 B = 2(b - a) |
229 Solve for t, only if it fits between 0 < t < 1 | 217 Solve for t, only if it fits between 0 < t < 1 |
230 */ | 218 */ |
231 int SkFindQuadExtrema(SkScalar a, SkScalar b, SkScalar c, SkScalar tValue[1]) { | 219 int SkFindQuadExtrema(SkScalar a, SkScalar b, SkScalar c, SkScalar tValue[1]) { |
232 /* At + B == 0 | 220 /* At + B == 0 |
233 t = -B / A | 221 t = -B / A |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 // w1 /= sqrt(w0*w2) | 1227 // w1 /= sqrt(w0*w2) |
1240 // | 1228 // |
1241 // However, in our case, we know that for dst[0]: | 1229 // However, in our case, we know that for dst[0]: |
1242 // w0 == 1, and for dst[1], w2 == 1 | 1230 // w0 == 1, and for dst[1], w2 == 1 |
1243 // | 1231 // |
1244 SkScalar root = SkScalarSqrt(tmp2[1].fZ); | 1232 SkScalar root = SkScalarSqrt(tmp2[1].fZ); |
1245 dst[0].fW = tmp2[0].fZ / root; | 1233 dst[0].fW = tmp2[0].fZ / root; |
1246 dst[1].fW = tmp2[2].fZ / root; | 1234 dst[1].fW = tmp2[2].fZ / root; |
1247 } | 1235 } |
1248 | 1236 |
1249 static Sk2s times_2(const Sk2s& value) { | 1237 void SkConic::chopAt(SkScalar t1, SkScalar t2, SkConic* dst) const { |
1250 return value + value; | 1238 if (0 == t1 || 1 == t2) { |
| 1239 if (0 == t1 && 1 == t2) { |
| 1240 *dst = *this; |
| 1241 } else { |
| 1242 SkConic pair[2]; |
| 1243 this->chopAt(t1 ? t1 : t2, pair); |
| 1244 *dst = pair[SkToBool(t1)]; |
| 1245 } |
| 1246 return; |
| 1247 } |
| 1248 SkConicCoeff coeff(*this); |
| 1249 Sk2s tt1(t1); |
| 1250 Sk2s aXY = coeff.fNumer.eval(tt1); |
| 1251 Sk2s aZZ = coeff.fDenom.eval(tt1); |
| 1252 Sk2s midTT((t1 + t2) / 2); |
| 1253 Sk2s dXY = coeff.fNumer.eval(midTT); |
| 1254 Sk2s dZZ = coeff.fDenom.eval(midTT); |
| 1255 Sk2s tt2(t2); |
| 1256 Sk2s cXY = coeff.fNumer.eval(tt2); |
| 1257 Sk2s cZZ = coeff.fDenom.eval(tt2); |
| 1258 Sk2s bXY = times_2(dXY) - (aXY + cXY) * Sk2s(0.5f); |
| 1259 Sk2s bZZ = times_2(dZZ) - (aZZ + cZZ) * Sk2s(0.5f); |
| 1260 dst->fPts[0] = to_point(aXY / aZZ); |
| 1261 dst->fPts[1] = to_point(bXY / bZZ); |
| 1262 dst->fPts[2] = to_point(cXY / cZZ); |
| 1263 Sk2s ww = bZZ / (aZZ * cZZ).sqrt(); |
| 1264 dst->fW = ww.kth<0>(); |
1251 } | 1265 } |
1252 | 1266 |
1253 SkPoint SkConic::evalAt(SkScalar t) const { | 1267 SkPoint SkConic::evalAt(SkScalar t) const { |
1254 Sk2s p0 = from_point(fPts[0]); | 1268 Sk2s p0 = from_point(fPts[0]); |
1255 Sk2s p1 = from_point(fPts[1]); | 1269 Sk2s p1 = from_point(fPts[1]); |
1256 Sk2s p2 = from_point(fPts[2]); | 1270 Sk2s p2 = from_point(fPts[2]); |
1257 Sk2s tt(t); | 1271 Sk2s tt(t); |
1258 Sk2s ww(fW); | 1272 Sk2s ww(fW); |
1259 Sk2s one(1); | 1273 Sk2s one(1); |
1260 | 1274 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1591 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
1578 } | 1592 } |
1579 if (userMatrix) { | 1593 if (userMatrix) { |
1580 matrix.postConcat(*userMatrix); | 1594 matrix.postConcat(*userMatrix); |
1581 } | 1595 } |
1582 for (int i = 0; i < conicCount; ++i) { | 1596 for (int i = 0; i < conicCount; ++i) { |
1583 matrix.mapPoints(dst[i].fPts, 3); | 1597 matrix.mapPoints(dst[i].fPts, 3); |
1584 } | 1598 } |
1585 return conicCount; | 1599 return conicCount; |
1586 } | 1600 } |
OLD | NEW |