| 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 "SkIntersections.h" | 7 #include "SkIntersections.h" |
| 8 #include "SkPathOpsCubic.h" | 8 #include "SkPathOpsCubic.h" |
| 9 #include "SkPathOpsLine.h" | 9 #include "SkPathOpsLine.h" |
| 10 #include "SkReduceOrder.h" | 10 #include "SkReduceOrder.h" |
| 11 #include "Test.h" | 11 #include "Test.h" |
| 12 | 12 |
| 13 static struct lineCubic { | 13 static struct lineCubic { |
| 14 SkDCubic cubic; | 14 SkDCubic cubic; |
| 15 SkDLine line; | 15 SkDLine line; |
| 16 } lineCubicTests[] = { | 16 } lineCubicTests[] = { |
| 17 #if 0 |
| 18 {{{{258, 122}, {260.761414, 122}, { 263, 124.238579}, {263, 127}}}, |
| 19 {{{259.82843, 125.17157}, {261.535522, 123.46447}}}}, |
| 20 #endif |
| 17 {{{{1006.6951293945312,291}, {1023.263671875,291}, {1033.8402099609375,304.4
3145751953125}, | 21 {{{{1006.6951293945312,291}, {1023.263671875,291}, {1033.8402099609375,304.4
3145751953125}, |
| 18 {1030.318359375,321}}}, | 22 {1030.318359375,321}}}, |
| 19 {{{979.30487060546875,561}, {1036.695068359375,291}}}}, | 23 {{{979.30487060546875,561}, {1036.695068359375,291}}}}, |
| 20 {{{{259.30487060546875,561}, {242.73631286621094,561}, {232.15980529785156,5
47.56854248046875}, | 24 {{{{259.30487060546875,561}, {242.73631286621094,561}, {232.15980529785156,5
47.56854248046875}, |
| 21 {235.68154907226562,531}}}, | 25 {235.68154907226562,531}}}, |
| 22 {{{286.69512939453125,291}, {229.30485534667969,561}}}}, | 26 {{{286.69512939453125,291}, {229.30485534667969,561}}}}, |
| 23 {{{{1, 2}, {2, 6}, {2, 0}, {1, 0}}}, {{{1, 0}, {1, 2}}}}, | 27 {{{{1, 2}, {2, 6}, {2, 0}, {1, 0}}}, {{{1, 0}, {1, 2}}}}, |
| 24 {{{{0, 0}, {0, 1}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}}, | 28 {{{{0, 0}, {0, 1}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}}, |
| 25 }; | 29 }; |
| 26 | 30 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 64 } |
| 61 | 65 |
| 62 static void PathOpsCubicLineIntersectionTest(skiatest::Reporter* reporter) { | 66 static void PathOpsCubicLineIntersectionTest(skiatest::Reporter* reporter) { |
| 63 for (size_t index = 0; index < lineCubicTests_count; ++index) { | 67 for (size_t index = 0; index < lineCubicTests_count; ++index) { |
| 64 int iIndex = static_cast<int>(index); | 68 int iIndex = static_cast<int>(index); |
| 65 testOne(reporter, iIndex); | 69 testOne(reporter, iIndex); |
| 66 reporter->bumpTestCount(); | 70 reporter->bumpTestCount(); |
| 67 } | 71 } |
| 68 } | 72 } |
| 69 | 73 |
| 70 static void PathOpsCubicLineIntersectionTestOne(skiatest::Reporter* reporter) { | 74 static void PathOpsCubicLineIntersectionOneOffTest(skiatest::Reporter* reporter)
{ |
| 71 int iIndex = 0; | 75 int iIndex = 0; |
| 72 testOne(reporter, iIndex); | 76 testOne(reporter, iIndex); |
| 73 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; | 77 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; |
| 74 const SkDLine& line = lineCubicTests[iIndex].line; | 78 const SkDLine& line = lineCubicTests[iIndex].line; |
| 75 SkIntersections i; | 79 SkIntersections i; |
| 76 i.intersect(cubic, line); | 80 i.intersect(cubic, line); |
| 77 SkASSERT(i.used() == 1); | 81 SkASSERT(i.used() == 1); |
| 78 #if ONE_OFF_DEBUG | 82 #if ONE_OFF_DEBUG |
| 79 double cubicT = i[0][0]; | 83 double cubicT = i[0][0]; |
| 80 SkDPoint prev = cubic.xyAtT(cubicT * 2 - 1); | 84 SkDPoint prev = cubic.xyAtT(cubicT * 2 - 1); |
| 81 SkDPoint sect = cubic.xyAtT(cubicT); | 85 SkDPoint sect = cubic.xyAtT(cubicT); |
| 82 double left[3] = { line.isLeft(prev), line.isLeft(sect), line.isLeft(cubic[3
]) }; | 86 double left[3] = { line.isLeft(prev), line.isLeft(sect), line.isLeft(cubic[3
]) }; |
| 83 SkDebugf("cubic=(%1.9g, %1.9g, %1.9g)\n", left[0], left[1], left[2]); | 87 SkDebugf("cubic=(%1.9g, %1.9g, %1.9g)\n", left[0], left[1], left[2]); |
| 84 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prev.fX, prev.fY, sect.fX, sec
t.fY); | 88 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prev.fX, prev.fY, sect.fX, sec
t.fY); |
| 85 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", sect.fX, sect.fY, cubic[3].fX,
cubic[3].fY); | 89 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", sect.fX, sect.fY, cubic[3].fX,
cubic[3].fY); |
| 86 SkDPoint prevL = line.xyAtT(i[1][0] - 0.0000007); | 90 SkDPoint prevL = line.xyAtT(i[1][0] - 0.0000007); |
| 87 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prevL.fX, prevL.fY, i.pt(0).fX
, i.pt(0).fY); | 91 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prevL.fX, prevL.fY, i.pt(0).fX
, i.pt(0).fY); |
| 88 SkDPoint nextL = line.xyAtT(i[1][0] + 0.0000007); | 92 SkDPoint nextL = line.xyAtT(i[1][0] + 0.0000007); |
| 89 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", i.pt(0).fX, i.pt(0).fY, nextL.
fX, nextL.fY); | 93 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", i.pt(0).fX, i.pt(0).fY, nextL.
fX, nextL.fY); |
| 90 SkDebugf("prevD=%1.9g dist=%1.9g nextD=%1.9g\n", prev.distance(nextL), | 94 SkDebugf("prevD=%1.9g dist=%1.9g nextD=%1.9g\n", prev.distance(nextL), |
| 91 sect.distance(i.pt(0)), cubic[3].distance(prevL)); | 95 sect.distance(i.pt(0)), cubic[3].distance(prevL)); |
| 92 #endif | 96 #endif |
| 93 } | 97 } |
| 94 | 98 |
| 95 #include "TestClassDef.h" | 99 #include "TestClassDef.h" |
| 96 DEFINE_TESTCLASS_SHORT(PathOpsCubicLineIntersectionTest) | 100 DEFINE_TESTCLASS_SHORT(PathOpsCubicLineIntersectionTest) |
| 97 | 101 |
| 98 DEFINE_TESTCLASS_SHORT(PathOpsCubicLineIntersectionTestOne) | 102 DEFINE_TESTCLASS_SHORT(PathOpsCubicLineIntersectionOneOffTest) |
| OLD | NEW |