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 "Sk2x.h" | 10 #include "Sk2x.h" |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 conic_deriv_coeff(coord, w, coeff); | 1278 conic_deriv_coeff(coord, w, coeff); |
1279 return t * (t * coeff[0] + coeff[1]) + coeff[2]; | 1279 return t * (t * coeff[0] + coeff[1]) + coeff[2]; |
1280 } | 1280 } |
1281 #endif | 1281 #endif |
1282 } | 1282 } |
1283 | 1283 |
1284 static SkScalar subdivide_w_value(SkScalar w) { | 1284 static SkScalar subdivide_w_value(SkScalar w) { |
1285 return SkScalarSqrt(SK_ScalarHalf + w * SK_ScalarHalf); | 1285 return SkScalarSqrt(SK_ScalarHalf + w * SK_ScalarHalf); |
1286 } | 1286 } |
1287 | 1287 |
1288 void SkConic::chop(SkConic dst[2]) const { | 1288 static Sk2s twice(const Sk2s& value) { |
1289 SkScalar scale = SkScalarInvert(SK_Scalar1 + fW); | 1289 return value + value; |
1290 SkScalar p1x = fW * fPts[1].fX; | |
1291 SkScalar p1y = fW * fPts[1].fY; | |
1292 SkScalar mx = (fPts[0].fX + 2 * p1x + fPts[2].fX) * scale * SK_ScalarHalf; | |
1293 SkScalar my = (fPts[0].fY + 2 * p1y + fPts[2].fY) * scale * SK_ScalarHalf; | |
1294 | |
1295 dst[0].fPts[0] = fPts[0]; | |
1296 dst[0].fPts[1].set((fPts[0].fX + p1x) * scale, | |
1297 (fPts[0].fY + p1y) * scale); | |
1298 dst[0].fPts[2].set(mx, my); | |
1299 | |
1300 dst[1].fPts[0].set(mx, my); | |
1301 dst[1].fPts[1].set((p1x + fPts[2].fX) * scale, | |
1302 (p1y + fPts[2].fY) * scale); | |
1303 dst[1].fPts[2] = fPts[2]; | |
1304 | |
1305 dst[0].fW = dst[1].fW = subdivide_w_value(fW); | |
1306 } | 1290 } |
1307 | 1291 |
1308 void SkConic::chop2(SkConic * SK_RESTRICT dst) const { | 1292 void SkConic::chop(SkConic * SK_RESTRICT dst) const { |
1309 Sk2s scale = Sk2s(SK_Scalar1 + fW).invert(); // approxInvert is wicked fa
ster!!! | 1293 Sk2s scale = Sk2s(SkScalarInvert(SK_Scalar1 + fW)); |
1310 SkScalar newW = subdivide_w_value(fW); | 1294 SkScalar newW = subdivide_w_value(fW); |
1311 | 1295 |
1312 Sk2s p0 = from_point(fPts[0]); | 1296 Sk2s p0 = from_point(fPts[0]); |
1313 Sk2s p1 = from_point(fPts[1]); | 1297 Sk2s p1 = from_point(fPts[1]); |
1314 Sk2s p2 = from_point(fPts[2]); | 1298 Sk2s p2 = from_point(fPts[2]); |
1315 Sk2s ww(fW); | 1299 Sk2s ww(fW); |
1316 Sk2s half(0.5f); | |
1317 | 1300 |
1318 Sk2s wp1 = ww * p1; | 1301 Sk2s wp1 = ww * p1; |
1319 Sk2s m = ((p0 + wp1 + wp1 + p2) * half) * scale; | 1302 Sk2s m = (p0 + twice(wp1) + p2) * scale * Sk2s(0.5f); |
1320 | 1303 |
1321 dst[0].fPts[0] = fPts[0]; | 1304 dst[0].fPts[0] = fPts[0]; |
1322 dst[0].fPts[1] = to_point((p0 + wp1) * scale); | 1305 dst[0].fPts[1] = to_point((p0 + wp1) * scale); |
1323 dst[0].fPts[2] = dst[1].fPts[0] = to_point(m); | 1306 dst[0].fPts[2] = dst[1].fPts[0] = to_point(m); |
1324 dst[1].fPts[1] = to_point((wp1 + p2) * scale); | 1307 dst[1].fPts[1] = to_point((wp1 + p2) * scale); |
1325 dst[1].fPts[2] = fPts[2]; | 1308 dst[1].fPts[2] = fPts[2]; |
1326 | 1309 |
1327 dst[0].fW = dst[1].fW = newW; | 1310 dst[0].fW = dst[1].fW = newW; |
1328 } | 1311 } |
1329 | 1312 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1552 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
1570 } | 1553 } |
1571 if (userMatrix) { | 1554 if (userMatrix) { |
1572 matrix.postConcat(*userMatrix); | 1555 matrix.postConcat(*userMatrix); |
1573 } | 1556 } |
1574 for (int i = 0; i < conicCount; ++i) { | 1557 for (int i = 0; i < conicCount; ++i) { |
1575 matrix.mapPoints(dst[i].fPts, 3); | 1558 matrix.mapPoints(dst[i].fPts, 3); |
1576 } | 1559 } |
1577 return conicCount; | 1560 return conicCount; |
1578 } | 1561 } |
OLD | NEW |