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 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 SkScalar fpow2 = SkScalarLog2((x * x + y * y) / tol2) * 0.25f; | 1146 SkScalar fpow2 = SkScalarLog2((x * x + y * y) / tol2) * 0.25f; |
1147 int altPow2 = SkScalarCeilToInt(fpow2); | 1147 int altPow2 = SkScalarCeilToInt(fpow2); |
1148 if (altPow2 != pow2) { | 1148 if (altPow2 != pow2) { |
1149 SkDebugf("pow2 %d altPow2 %d fbits %g err %g tol %g\n", pow2, altPow
2, fpow2, err, tol); | 1149 SkDebugf("pow2 %d altPow2 %d fbits %g err %g tol %g\n", pow2, altPow
2, fpow2, err, tol); |
1150 } | 1150 } |
1151 pow2 = altPow2; | 1151 pow2 = altPow2; |
1152 } | 1152 } |
1153 return pow2; | 1153 return pow2; |
1154 } | 1154 } |
1155 | 1155 |
1156 // This was originally developed and tested for pathops: see SkOpTypes.h | |
1157 // returns true if (a <= b <= c) || (a >= b >= c) | |
1158 static bool between(SkScalar a, SkScalar b, SkScalar c) { | |
1159 return (a - b) * (c - b) <= 0; | |
1160 } | |
1161 | |
1162 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { | 1156 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { |
1163 SkASSERT(level >= 0); | 1157 SkASSERT(level >= 0); |
1164 | 1158 |
1165 if (0 == level) { | 1159 if (0 == level) { |
1166 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); | 1160 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); |
1167 return pts + 2; | 1161 return pts + 2; |
1168 } else { | 1162 } else { |
1169 SkConic dst[2]; | 1163 SkConic dst[2]; |
1170 src.chop(dst); | 1164 src.chop(dst); |
1171 const SkScalar startY = src.fPts[0].fY; | |
1172 const SkScalar endY = src.fPts[2].fY; | |
1173 if (between(startY, src.fPts[1].fY, endY)) { | |
1174 // If the input is monotonic and the output is not, the scan convert
er hangs. | |
1175 // Ensure that the chopped conics maintain their y-order. | |
1176 SkScalar midY = dst[0].fPts[2].fY; | |
1177 if (!between(startY, midY, endY)) { | |
1178 // If the computed midpoint is outside the ends, move it to the
closer one. | |
1179 SkScalar closerY = SkTAbs(midY - startY) < SkTAbs(midY - endY) ?
startY : endY; | |
1180 dst[0].fPts[2].fY = dst[1].fPts[0].fY = closerY; | |
1181 } | |
1182 if (!between(startY, dst[0].fPts[1].fY, dst[0].fPts[2].fY)) { | |
1183 // If the 1st control is not between the start and end, put it a
t the start. | |
1184 // This also reduces the quad to a line. | |
1185 dst[0].fPts[1].fY = startY; | |
1186 } | |
1187 if (!between(dst[1].fPts[0].fY, dst[1].fPts[1].fY, endY)) { | |
1188 // If the 2nd control is not between the start and end, put it a
t the end. | |
1189 // This also reduces the quad to a line. | |
1190 dst[1].fPts[1].fY = endY; | |
1191 } | |
1192 // Verify that all five points are in order. | |
1193 SkASSERT(between(startY, dst[0].fPts[1].fY, dst[0].fPts[2].fY)); | |
1194 SkASSERT(between(dst[0].fPts[1].fY, dst[0].fPts[2].fY, dst[1].fPts[1
].fY)); | |
1195 SkASSERT(between(dst[0].fPts[2].fY, dst[1].fPts[1].fY, endY)); | |
1196 } | |
1197 --level; | 1165 --level; |
1198 pts = subdivide(dst[0], pts, level); | 1166 pts = subdivide(dst[0], pts, level); |
1199 return subdivide(dst[1], pts, level); | 1167 return subdivide(dst[1], pts, level); |
1200 } | 1168 } |
1201 } | 1169 } |
1202 | 1170 |
1203 int SkConic::chopIntoQuadsPOW2(SkPoint pts[], int pow2) const { | 1171 int SkConic::chopIntoQuadsPOW2(SkPoint pts[], int pow2) const { |
1204 SkASSERT(pow2 >= 0); | 1172 SkASSERT(pow2 >= 0); |
1205 *pts = fPts[0]; | 1173 *pts = fPts[0]; |
1206 SkDEBUGCODE(SkPoint* endPts); | 1174 SkDEBUGCODE(SkPoint* endPts); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1365 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
1398 } | 1366 } |
1399 if (userMatrix) { | 1367 if (userMatrix) { |
1400 matrix.postConcat(*userMatrix); | 1368 matrix.postConcat(*userMatrix); |
1401 } | 1369 } |
1402 for (int i = 0; i < conicCount; ++i) { | 1370 for (int i = 0; i < conicCount; ++i) { |
1403 matrix.mapPoints(dst[i].fPts, 3); | 1371 matrix.mapPoints(dst[i].fPts, 3); |
1404 } | 1372 } |
1405 return conicCount; | 1373 return conicCount; |
1406 } | 1374 } |
OLD | NEW |