| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "PathOpsCubicIntersectionTestData.h" | 7 #include "PathOpsCubicIntersectionTestData.h" |
| 8 #include "PathOpsTestCommon.h" | 8 #include "PathOpsTestCommon.h" |
| 9 #include "SkIntersections.h" | 9 #include "SkIntersections.h" |
| 10 #include "SkPathOpsRect.h" | 10 #include "SkPathOpsRect.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 {{{18.1312339, 31.6473732}, {95.5711034, 63.5350219}, {92.3283165, 62.0158945}, | 157 {{{18.1312339, 31.6473732}, {95.5711034, 63.5350219}, {92.3283165, 62.0158945}, |
| 158 {18.5656052, 32.1268808}}}, | 158 {18.5656052, 32.1268808}}}, |
| 159 {{{97.402018, 35.7169972}, {33.1127443, 25.8935163}, {1.13970027, 54.9424981}, | 159 {{{97.402018, 35.7169972}, {33.1127443, 25.8935163}, {1.13970027, 54.9424981}, |
| 160 {56.4860195, 60.529264}}}, | 160 {56.4860195, 60.529264}}}, |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 const size_t testSetCount = SK_ARRAY_COUNT(testSet); | 163 const size_t testSetCount = SK_ARRAY_COUNT(testSet); |
| 164 | 164 |
| 165 static const SkDCubic newTestSet[] = { | 165 static const SkDCubic newTestSet[] = { |
| 166 {{{134,11414}, {131.990234375,11414}, {130.32666015625,11415.482421875}, {130.04
275512695312,11417.4130859375}}}, |
| 167 {{{132,11419}, {130.89543151855469,11419}, {130,11418.1044921875}, {130,11417}}}
, |
| 168 |
| 169 {{{132,11419}, {130.89543151855469,11419}, {130,11418.1044921875}, {130,11417}}}
, |
| 170 {{{130.04275512695312,11417.4130859375}, {130.23312377929687,11418.3193359375},
{131.03707885742187,11419}, {132,11419}}}, |
| 171 |
| 166 {{{0, 1}, {2, 3}, {5, 1}, {4, 3}}}, | 172 {{{0, 1}, {2, 3}, {5, 1}, {4, 3}}}, |
| 167 {{{1, 5}, {3, 4}, {1, 0}, {3, 2}}}, | 173 {{{1, 5}, {3, 4}, {1, 0}, {3, 2}}}, |
| 168 | 174 |
| 169 {{{3, 5}, {1, 6}, {5, 0}, {3, 1}}}, | 175 {{{3, 5}, {1, 6}, {5, 0}, {3, 1}}}, |
| 170 {{{0, 5}, {1, 3}, {5, 3}, {6, 1}}}, | 176 {{{0, 5}, {1, 3}, {5, 3}, {6, 1}}}, |
| 171 | 177 |
| 172 {{{0, 1}, {1, 5}, {1, 0}, {1, 0}}}, | 178 {{{0, 1}, {1, 5}, {1, 0}, {1, 0}}}, |
| 173 {{{0, 1}, {0, 1}, {1, 0}, {5, 1}}}, | 179 {{{0, 1}, {0, 1}, {1, 0}, {5, 1}}}, |
| 174 | 180 |
| 175 {{{1, 3}, {5, 6}, {5, 3}, {5, 4}}}, | 181 {{{1, 3}, {5, 6}, {5, 3}, {5, 4}}}, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 230 |
| 225 {{{0, 2}, {0, 1}, {3, 0}, {1, 0}}}, | 231 {{{0, 2}, {0, 1}, {3, 0}, {1, 0}}}, |
| 226 {{{0, 3}, {0, 1}, {2, 0}, {1, 0}}}, | 232 {{{0, 3}, {0, 1}, {2, 0}, {1, 0}}}, |
| 227 }; | 233 }; |
| 228 | 234 |
| 229 const size_t newTestSetCount = SK_ARRAY_COUNT(newTestSet); | 235 const size_t newTestSetCount = SK_ARRAY_COUNT(newTestSet); |
| 230 | 236 |
| 231 static void oneOff(skiatest::Reporter* reporter, const SkDCubic& cubic1, const S
kDCubic& cubic2) { | 237 static void oneOff(skiatest::Reporter* reporter, const SkDCubic& cubic1, const S
kDCubic& cubic2) { |
| 232 #if ONE_OFF_DEBUG | 238 #if ONE_OFF_DEBUG |
| 233 SkDebugf("computed quadratics given\n"); | 239 SkDebugf("computed quadratics given\n"); |
| 234 SkDebugf(" {{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}},\
n", | 240 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n"
, |
| 235 cubic1[0].fX, cubic1[0].fY, cubic1[1].fX, cubic1[1].fY, | 241 cubic1[0].fX, cubic1[0].fY, cubic1[1].fX, cubic1[1].fY, |
| 236 cubic1[2].fX, cubic1[2].fY, cubic1[3].fX, cubic1[3].fY); | 242 cubic1[2].fX, cubic1[2].fY, cubic1[3].fX, cubic1[3].fY); |
| 237 SkDebugf(" {{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}},\
n", | 243 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n"
, |
| 238 cubic2[0].fX, cubic2[0].fY, cubic2[1].fX, cubic2[1].fY, | 244 cubic2[0].fX, cubic2[0].fY, cubic2[1].fX, cubic2[1].fY, |
| 239 cubic2[2].fX, cubic2[2].fY, cubic2[3].fX, cubic2[3].fY); | 245 cubic2[2].fX, cubic2[2].fY, cubic2[3].fX, cubic2[3].fY); |
| 240 #endif | 246 #endif |
| 241 SkTDArray<SkDQuad> quads1; | 247 SkTDArray<SkDQuad> quads1; |
| 242 CubicToQuads(cubic1, cubic1.calcPrecision(), quads1); | 248 CubicToQuads(cubic1, cubic1.calcPrecision(), quads1); |
| 243 #if ONE_OFF_DEBUG | 249 #if ONE_OFF_DEBUG |
| 244 SkDebugf("computed quadratics set 1\n"); | 250 SkDebugf("computed quadratics set 1\n"); |
| 245 for (int index = 0; index < quads1.count(); ++index) { | 251 for (int index = 0; index < quads1.count(); ++index) { |
| 246 const SkDQuad& q = quads1[index]; | 252 const SkDQuad& q = quads1[index]; |
| 247 SkDebugf(" {{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}},\n", q[0].fX
, q[0].fY, | 253 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].fX,
q[0].fY, |
| 248 q[1].fX, q[1].fY, q[2].fX, q[2].fY); | 254 q[1].fX, q[1].fY, q[2].fX, q[2].fY); |
| 249 } | 255 } |
| 250 #endif | 256 #endif |
| 251 SkTDArray<SkDQuad> quads2; | 257 SkTDArray<SkDQuad> quads2; |
| 252 CubicToQuads(cubic2, cubic2.calcPrecision(), quads2); | 258 CubicToQuads(cubic2, cubic2.calcPrecision(), quads2); |
| 253 #if ONE_OFF_DEBUG | 259 #if ONE_OFF_DEBUG |
| 254 SkDebugf("computed quadratics set 2\n"); | 260 SkDebugf("computed quadratics set 2\n"); |
| 255 for (int index = 0; index < quads2.count(); ++index) { | 261 for (int index = 0; index < quads2.count(); ++index) { |
| 256 const SkDQuad& q = quads2[index]; | 262 const SkDQuad& q = quads2[index]; |
| 257 SkDebugf(" {{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}},\n", q[0].fX
, q[0].fY, | 263 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].fX,
q[0].fY, |
| 258 q[1].fX, q[1].fY, q[2].fX, q[2].fY); | 264 q[1].fX, q[1].fY, q[2].fX, q[2].fY); |
| 259 } | 265 } |
| 260 #endif | 266 #endif |
| 261 SkIntersections intersections; | 267 SkIntersections intersections; |
| 262 intersections.intersect(cubic1, cubic2); | 268 intersections.intersect(cubic1, cubic2); |
| 263 double tt1, tt2; | 269 double tt1, tt2; |
| 264 SkDPoint xy1, xy2; | 270 SkDPoint xy1, xy2; |
| 265 for (int pt3 = 0; pt3 < intersections.used(); ++pt3) { | 271 for (int pt3 = 0; pt3 < intersections.used(); ++pt3) { |
| 266 tt1 = intersections[0][pt3]; | 272 tt1 = intersections[0][pt3]; |
| 267 xy1 = cubic1.xyAtT(tt1); | 273 xy1 = cubic1.xyAtT(tt1); |
| 268 tt2 = intersections[1][pt3]; | 274 tt2 = intersections[1][pt3]; |
| 269 xy2 = cubic2.xyAtT(tt2); | 275 xy2 = cubic2.xyAtT(tt2); |
| 276 const SkDPoint& iPt = intersections.pt(pt3); |
| 270 #if ONE_OFF_DEBUG | 277 #if ONE_OFF_DEBUG |
| 271 SkDebugf("%s t1=%1.9g (%1.9g, %1.9g) (%1.9g, %1.9g) (%1.9g, %1.9g) t2=%1
.9g\n", | 278 SkDebugf("%s t1=%1.9g (%1.9g, %1.9g) (%1.9g, %1.9g) (%1.9g, %1.9g) t2=%1
.9g\n", |
| 272 __FUNCTION__, tt1, xy1.fX, xy1.fY, intersections.pt(pt3).fX, | 279 __FUNCTION__, tt1, xy1.fX, xy1.fY, iPt.fX, |
| 273 intersections.pt(pt3).fY, xy2.fX, xy2.fY, tt2); | 280 iPt.fY, xy2.fX, xy2.fY, tt2); |
| 274 #endif | 281 #endif |
| 275 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); | 282 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(iPt)); |
| 283 REPORTER_ASSERT(reporter, xy2.approximatelyEqual(iPt)); |
| 284 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); |
| 276 } | 285 } |
| 277 } | 286 } |
| 278 | 287 |
| 279 static void oneOff(skiatest::Reporter* reporter, int outer, int inner) { | 288 static void oneOff(skiatest::Reporter* reporter, int outer, int inner) { |
| 280 const SkDCubic& cubic1 = testSet[outer]; | 289 const SkDCubic& cubic1 = testSet[outer]; |
| 281 const SkDCubic& cubic2 = testSet[inner]; | 290 const SkDCubic& cubic2 = testSet[inner]; |
| 282 oneOff(reporter, cubic1, cubic2); | 291 oneOff(reporter, cubic1, cubic2); |
| 283 } | 292 } |
| 284 | 293 |
| 285 static void newOneOff(skiatest::Reporter* reporter, int outer, int inner) { | 294 static void newOneOff(skiatest::Reporter* reporter, int outer, int inner) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 oneOffTest(reporter); | 519 oneOffTest(reporter); |
| 511 oneOffTests(reporter); | 520 oneOffTests(reporter); |
| 512 cubicIntersectionSelfTest(reporter); | 521 cubicIntersectionSelfTest(reporter); |
| 513 standardTestCases(reporter); | 522 standardTestCases(reporter); |
| 514 if (false) CubicIntersection_IntersectionFinder(); | 523 if (false) CubicIntersection_IntersectionFinder(); |
| 515 if (false) CubicIntersection_RandTest(reporter); | 524 if (false) CubicIntersection_RandTest(reporter); |
| 516 } | 525 } |
| 517 | 526 |
| 518 #include "TestClassDef.h" | 527 #include "TestClassDef.h" |
| 519 DEFINE_TESTCLASS_SHORT(PathOpsCubicIntersectionTest) | 528 DEFINE_TESTCLASS_SHORT(PathOpsCubicIntersectionTest) |
| OLD | NEW |