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" |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 // | 1139 // |
1140 // F = (A (1 - t)^2 + C t^2 + 2 B (1 - t) t w) | 1140 // F = (A (1 - t)^2 + C t^2 + 2 B (1 - t) t w) |
1141 // ------------------------------------------ | 1141 // ------------------------------------------ |
1142 // ((1 - t)^2 + t^2 + 2 (1 - t) t w) | 1142 // ((1 - t)^2 + t^2 + 2 (1 - t) t w) |
1143 // | 1143 // |
1144 // = {t^2 (P0 + P2 - 2 P1 w), t (-2 P0 + 2 P1 w), P0} | 1144 // = {t^2 (P0 + P2 - 2 P1 w), t (-2 P0 + 2 P1 w), P0} |
1145 // ------------------------------------------------ | 1145 // ------------------------------------------------ |
1146 // {t^2 (2 - 2 w), t (-2 + 2 w), 1} | 1146 // {t^2 (2 - 2 w), t (-2 + 2 w), 1} |
1147 // | 1147 // |
1148 | 1148 |
1149 static SkScalar conic_eval_pos(const SkScalar src[], SkScalar w, SkScalar t) { | |
1150 SkASSERT(src); | |
1151 SkASSERT(t >= 0 && t <= SK_Scalar1); | |
1152 | |
1153 SkScalar src2w = SkScalarMul(src[2], w); | |
1154 SkScalar C = src[0]; | |
1155 SkScalar A = src[4] - 2 * src2w + C; | |
1156 SkScalar B = 2 * (src2w - C); | |
1157 SkScalar numer = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C); | |
1158 | |
1159 B = 2 * (w - SK_Scalar1); | |
1160 C = SK_Scalar1; | |
1161 A = -B; | |
1162 SkScalar denom = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C); | |
1163 | |
1164 return numer / denom; | |
1165 } | |
1166 | |
1167 // F' = 2 (C t (1 + t (-1 + w)) - A (-1 + t) (t (-1 + w) - w) + B (1 - 2 t) w) | 1149 // F' = 2 (C t (1 + t (-1 + w)) - A (-1 + t) (t (-1 + w) - w) + B (1 - 2 t) w) |
1168 // | 1150 // |
1169 // t^2 : (2 P0 - 2 P2 - 2 P0 w + 2 P2 w) | 1151 // t^2 : (2 P0 - 2 P2 - 2 P0 w + 2 P2 w) |
1170 // t^1 : (-2 P0 + 2 P2 + 4 P0 w - 4 P1 w) | 1152 // t^1 : (-2 P0 + 2 P2 + 4 P0 w - 4 P1 w) |
1171 // t^0 : -2 P0 w + 2 P1 w | 1153 // t^0 : -2 P0 w + 2 P1 w |
1172 // | 1154 // |
1173 // We disregard magnitude, so we can freely ignore the denominator of F', and | 1155 // We disregard magnitude, so we can freely ignore the denominator of F', and |
1174 // divide the numerator by 2 | 1156 // divide the numerator by 2 |
1175 // | 1157 // |
1176 // coeff[0] for t^2 | 1158 // coeff[0] for t^2 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 dst[3] = SkScalarInterp(ab, bc, t); | 1205 dst[3] = SkScalarInterp(ab, bc, t); |
1224 dst[6] = bc; | 1206 dst[6] = bc; |
1225 } | 1207 } |
1226 | 1208 |
1227 static void ratquad_mapTo3D(const SkPoint src[3], SkScalar w, SkP3D dst[]) { | 1209 static void ratquad_mapTo3D(const SkPoint src[3], SkScalar w, SkP3D dst[]) { |
1228 dst[0].set(src[0].fX * 1, src[0].fY * 1, 1); | 1210 dst[0].set(src[0].fX * 1, src[0].fY * 1, 1); |
1229 dst[1].set(src[1].fX * w, src[1].fY * w, w); | 1211 dst[1].set(src[1].fX * w, src[1].fY * w, w); |
1230 dst[2].set(src[2].fX * 1, src[2].fY * 1, 1); | 1212 dst[2].set(src[2].fX * 1, src[2].fY * 1, 1); |
1231 } | 1213 } |
1232 | 1214 |
1233 void SkConic::evalAt(SkScalar t, SkPoint* pt, SkVector* tangent) const { | |
1234 SkASSERT(t >= 0 && t <= SK_Scalar1); | |
1235 | |
1236 if (pt) { | |
1237 pt->set(conic_eval_pos(&fPts[0].fX, fW, t), | |
1238 conic_eval_pos(&fPts[0].fY, fW, t)); | |
1239 } | |
1240 if (tangent) { | |
1241 *tangent = evalTangentAt(t); | |
1242 } | |
1243 } | |
1244 | |
1245 void SkConic::chopAt(SkScalar t, SkConic dst[2]) const { | 1215 void SkConic::chopAt(SkScalar t, SkConic dst[2]) const { |
1246 SkP3D tmp[3], tmp2[3]; | 1216 SkP3D tmp[3], tmp2[3]; |
1247 | 1217 |
1248 ratquad_mapTo3D(fPts, fW, tmp); | 1218 ratquad_mapTo3D(fPts, fW, tmp); |
1249 | 1219 |
1250 p3d_interp(&tmp[0].fX, &tmp2[0].fX, t); | 1220 p3d_interp(&tmp[0].fX, &tmp2[0].fX, t); |
1251 p3d_interp(&tmp[0].fY, &tmp2[0].fY, t); | 1221 p3d_interp(&tmp[0].fY, &tmp2[0].fY, t); |
1252 p3d_interp(&tmp[0].fZ, &tmp2[0].fZ, t); | 1222 p3d_interp(&tmp[0].fZ, &tmp2[0].fZ, t); |
1253 | 1223 |
1254 dst[0].fPts[0] = fPts[0]; | 1224 dst[0].fPts[0] = fPts[0]; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 Sk2s p20 = p2 - p0; | 1280 Sk2s p20 = p2 - p0; |
1311 Sk2s p10 = p1 - p0; | 1281 Sk2s p10 = p1 - p0; |
1312 | 1282 |
1313 Sk2s C = ww * p10; | 1283 Sk2s C = ww * p10; |
1314 Sk2s A = ww * p20 - p20; | 1284 Sk2s A = ww * p20 - p20; |
1315 Sk2s B = p20 - C - C; | 1285 Sk2s B = p20 - C - C; |
1316 | 1286 |
1317 return to_vector(quad_poly_eval(A, B, C, Sk2s(t))); | 1287 return to_vector(quad_poly_eval(A, B, C, Sk2s(t))); |
1318 } | 1288 } |
1319 | 1289 |
| 1290 void SkConic::evalAt(SkScalar t, SkPoint* pt, SkVector* tangent) const { |
| 1291 SkASSERT(t >= 0 && t <= SK_Scalar1); |
| 1292 |
| 1293 if (pt) { |
| 1294 *pt = this->evalAt(t); |
| 1295 } |
| 1296 if (tangent) { |
| 1297 *tangent = this->evalTangentAt(t); |
| 1298 } |
| 1299 } |
| 1300 |
1320 static SkScalar subdivide_w_value(SkScalar w) { | 1301 static SkScalar subdivide_w_value(SkScalar w) { |
1321 return SkScalarSqrt(SK_ScalarHalf + w * SK_ScalarHalf); | 1302 return SkScalarSqrt(SK_ScalarHalf + w * SK_ScalarHalf); |
1322 } | 1303 } |
1323 | 1304 |
1324 static Sk2s twice(const Sk2s& value) { | 1305 static Sk2s twice(const Sk2s& value) { |
1325 return value + value; | 1306 return value + value; |
1326 } | 1307 } |
1327 | 1308 |
1328 void SkConic::chop(SkConic * SK_RESTRICT dst) const { | 1309 void SkConic::chop(SkConic * SK_RESTRICT dst) const { |
1329 Sk2s scale = Sk2s(SkScalarInvert(SK_Scalar1 + fW)); | 1310 Sk2s scale = Sk2s(SkScalarInvert(SK_Scalar1 + fW)); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1571 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
1591 } | 1572 } |
1592 if (userMatrix) { | 1573 if (userMatrix) { |
1593 matrix.postConcat(*userMatrix); | 1574 matrix.postConcat(*userMatrix); |
1594 } | 1575 } |
1595 for (int i = 0; i < conicCount; ++i) { | 1576 for (int i = 0; i < conicCount; ++i) { |
1596 matrix.mapPoints(dst[i].fPts, 3); | 1577 matrix.mapPoints(dst[i].fPts, 3); |
1597 } | 1578 } |
1598 return conicCount; | 1579 return conicCount; |
1599 } | 1580 } |
OLD | NEW |