OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
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 #include "PathOpsTestCommon.h" | 7 #include "PathOpsTestCommon.h" |
8 #include "SkIntersections.h" | 8 #include "SkIntersections.h" |
9 #include "SkPathOpsCubic.h" | 9 #include "SkPathOpsCubic.h" |
10 #include "SkPathOpsLine.h" | 10 #include "SkPathOpsLine.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 if (largest <= 1) { | 187 if (largest <= 1) { |
188 #if 0 | 188 #if 0 |
189 SkDebugf("realRoots=%d (%1.9g, %1.9g, %1.9g) valid=%d (%1.9g, %1.9g,
%1.9g)\n", | 189 SkDebugf("realRoots=%d (%1.9g, %1.9g, %1.9g) valid=%d (%1.9g, %1.9g,
%1.9g)\n", |
190 realRoots, allRoots[0], allRoots[1], allRoots[2], valid, validRo
ots[0], | 190 realRoots, allRoots[0], allRoots[1], allRoots[2], valid, validRo
ots[0], |
191 validRoots[1], validRoots[2]); | 191 validRoots[1], validRoots[2]); |
192 #endif | 192 #endif |
193 double smallest = SkTMin(allRoots[0], allRoots[1]); | 193 double smallest = SkTMin(allRoots[0], allRoots[1]); |
194 if (realRoots == 3) { | 194 if (realRoots == 3) { |
195 smallest = SkTMin(smallest, allRoots[2]); | 195 smallest = SkTMin(smallest, allRoots[2]); |
196 } | 196 } |
197 SK_ALWAYSBREAK(smallest < 0); | 197 SkASSERT_RELEASE(smallest < 0); |
198 SK_ALWAYSBREAK(smallest >= -1); | 198 SkASSERT_RELEASE(smallest >= -1); |
199 largeBits = 0; | 199 largeBits = 0; |
200 } else { | 200 } else { |
201 frexp(largest, &largeBits); | 201 frexp(largest, &largeBits); |
202 SK_ALWAYSBREAK(largeBits >= 0); | 202 SkASSERT_RELEASE(largeBits >= 0); |
203 SK_ALWAYSBREAK(largeBits < 256); | 203 SkASSERT_RELEASE(largeBits < 256); |
204 } | 204 } |
205 double step = 1e-6; | 205 double step = 1e-6; |
206 if (largeBits > 21) { | 206 if (largeBits > 21) { |
207 step = 1e-1; | 207 step = 1e-1; |
208 } else if (largeBits > 18) { | 208 } else if (largeBits > 18) { |
209 step = 1e-2; | 209 step = 1e-2; |
210 } else if (largeBits > 15) { | 210 } else if (largeBits > 15) { |
211 step = 1e-3; | 211 step = 1e-3; |
212 } else if (largeBits > 12) { | 212 } else if (largeBits > 12) { |
213 step = 1e-4; | 213 step = 1e-4; |
214 } else if (largeBits > 9) { | 214 } else if (largeBits > 9) { |
215 step = 1e-5; | 215 step = 1e-5; |
216 } | 216 } |
217 double diff; | 217 double diff; |
218 do { | 218 do { |
219 double newT = binary_search(cubic, step, pt, t, &iters); | 219 double newT = binary_search(cubic, step, pt, t, &iters); |
220 if (newT >= 0) { | 220 if (newT >= 0) { |
221 diff = fabs(t - newT); | 221 diff = fabs(t - newT); |
222 break; | 222 break; |
223 } | 223 } |
224 step *= 1.5; | 224 step *= 1.5; |
225 SK_ALWAYSBREAK(step < 1); | 225 SkASSERT_RELEASE(step < 1); |
226 } while (true); | 226 } while (true); |
227 worstStep[largeBits] = SkTMax(worstStep[largeBits], diff); | 227 worstStep[largeBits] = SkTMax(worstStep[largeBits], diff); |
228 #if 0 | 228 #if 0 |
229 { | 229 { |
230 cubic.dump(); | 230 cubic.dump(); |
231 SkDebugf("\n"); | 231 SkDebugf("\n"); |
232 SkDLine line = {{{pt.fX - 1, pt.fY}, {pt.fX + 1, pt.fY}}}; | 232 SkDLine line = {{{pt.fX - 1, pt.fY}, {pt.fX + 1, pt.fY}}}; |
233 line.dump(); | 233 line.dump(); |
234 SkDebugf("\n"); | 234 SkDebugf("\n"); |
235 } | 235 } |
(...skipping 13 matching lines...) Expand all Loading... |
249 | 249 |
250 static double testOneFailure(const CubicLineFailures& failure) { | 250 static double testOneFailure(const CubicLineFailures& failure) { |
251 const SkDCubic& cubic = failure.c; | 251 const SkDCubic& cubic = failure.c; |
252 const SkDPoint& pt = failure.p; | 252 const SkDPoint& pt = failure.p; |
253 double A, B, C, D; | 253 double A, B, C, D; |
254 SkDCubic::Coefficients(&cubic[0].fY, &A, &B, &C, &D); | 254 SkDCubic::Coefficients(&cubic[0].fY, &A, &B, &C, &D); |
255 D -= pt.fY; | 255 D -= pt.fY; |
256 double allRoots[3] = {0}, validRoots[3] = {0}; | 256 double allRoots[3] = {0}, validRoots[3] = {0}; |
257 int realRoots = SkDCubic::RootsReal(A, B, C, D, allRoots); | 257 int realRoots = SkDCubic::RootsReal(A, B, C, D, allRoots); |
258 int valid = SkDQuad::AddValidTs(allRoots, realRoots, validRoots); | 258 int valid = SkDQuad::AddValidTs(allRoots, realRoots, validRoots); |
259 SK_ALWAYSBREAK(valid == 1); | 259 SkASSERT_RELEASE(valid == 1); |
260 SK_ALWAYSBREAK(realRoots != 1); | 260 SkASSERT_RELEASE(realRoots != 1); |
261 double t = validRoots[0]; | 261 double t = validRoots[0]; |
262 SkDPoint calcPt = cubic.ptAtT(t); | 262 SkDPoint calcPt = cubic.ptAtT(t); |
263 SK_ALWAYSBREAK(!calcPt.approximatelyEqual(pt)); | 263 SkASSERT_RELEASE(!calcPt.approximatelyEqual(pt)); |
264 int iters = 0; | 264 int iters = 0; |
265 double newT = binary_search(cubic, 0.1, pt, t, &iters); | 265 double newT = binary_search(cubic, 0.1, pt, t, &iters); |
266 return newT; | 266 return newT; |
267 } | 267 } |
268 | 268 |
269 DEF_TEST(PathOpsCubicLineFailures, reporter) { | 269 DEF_TEST(PathOpsCubicLineFailures, reporter) { |
270 return; // disable for now | 270 return; // disable for now |
271 for (int index = 0; index < cubicLineFailuresCount; ++index) { | 271 for (int index = 0; index < cubicLineFailuresCount; ++index) { |
272 const CubicLineFailures& failure = cubicLineFailures[index]; | 272 const CubicLineFailures& failure = cubicLineFailures[index]; |
273 double newT = testOneFailure(failure); | 273 double newT = testOneFailure(failure); |
274 SK_ALWAYSBREAK(newT >= 0); | 274 SkASSERT_RELEASE(newT >= 0); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 DEF_TEST(PathOpsCubicLineOneFailure, reporter) { | 278 DEF_TEST(PathOpsCubicLineOneFailure, reporter) { |
279 return; // disable for now | 279 return; // disable for now |
280 const CubicLineFailures& failure = cubicLineFailures[1]; | 280 const CubicLineFailures& failure = cubicLineFailures[1]; |
281 double newT = testOneFailure(failure); | 281 double newT = testOneFailure(failure); |
282 SK_ALWAYSBREAK(newT >= 0); | 282 SkASSERT_RELEASE(newT >= 0); |
283 } | 283 } |
OLD | NEW |