OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkPathOpsQuad.h" | 10 #include "SkPathOpsQuad.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkReduceOrder.h" | 12 #include "SkReduceOrder.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 | 14 |
15 static struct quadCubic { | 15 static struct quadCubic { |
16 SkDCubic cubic; | 16 SkDCubic cubic; |
17 SkDQuad quad; | 17 SkDQuad quad; |
18 } quadCubicTests[] = { | 18 } quadCubicTests[] = { |
| 19 {{{{945.08099365234375, 747.1619873046875}, {982.5679931640625, 747.16198730
46875}, {1013.6290283203125, 719.656005859375}, {1019.1910400390625, 683.7260131
8359375}}}, |
| 20 {{{945, 747}, {976.0660400390625, 747}, {998.03302001953125, 725.0330200195
3125}}}}, |
| 21 |
| 22 {{{{778, 14089}, {778, 14091.208984375}, {776.20916748046875, 14093}, {774,
14093}}}, |
| 23 {{{778, 14089}, {777.99957275390625, 14090.65625}, {776.82843017578125, 140
91.828125}}}}, |
| 24 |
19 {{{{1020.08099,672.161987}, {1020.08002,630.73999}, {986.502014,597.161987},
{945.080994,597.161987}}}, | 25 {{{{1020.08099,672.161987}, {1020.08002,630.73999}, {986.502014,597.161987},
{945.080994,597.161987}}}, |
20 {{{1020,672}, {1020,640.93396}, {998.03302,618.96698}}}}, | 26 {{{1020,672}, {1020,640.93396}, {998.03302,618.96698}}}}, |
21 | 27 |
22 {{{{778, 14089}, {778, 14091.208984375}, {776.20916748046875, 14093}, {774,
14093}}}, | 28 {{{{778, 14089}, {778, 14091.208984375}, {776.20916748046875, 14093}, {774,
14093}}}, |
23 {{{778, 14089}, {777.99957275390625, 14090.65625}, {776.82843017578125, 140
91.828125}}}}, | 29 {{{778, 14089}, {777.99957275390625, 14090.65625}, {776.82843017578125, 140
91.828125}}}}, |
24 | 30 |
25 {{{{1110, 817}, {1110.55225f, 817}, {1111, 817.447693f}, {1111, 818}}}, | 31 {{{{1110, 817}, {1110.55225f, 817}, {1111, 817.447693f}, {1111, 818}}}, |
26 {{{1110.70715f, 817.292908f}, {1110.41406f, 817.000122f}, {1110, 817}}}}, | 32 {{{1110.70715f, 817.292908f}, {1110.41406f, 817.000122f}, {1110, 817}}}}, |
27 | 33 |
28 {{{{1110, 817}, {1110.55225f, 817}, {1111, 817.447693f}, {1111, 818}}}, | 34 {{{{1110, 817}, {1110.55225f, 817}, {1111, 817.447693f}, {1111, 818}}}, |
(...skipping 27 matching lines...) Expand all Loading... |
56 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); | 62 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); |
57 int order2 = reduce2.reduce(quad); | 63 int order2 = reduce2.reduce(quad); |
58 if (order1 != 4) { | 64 if (order1 != 4) { |
59 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); | 65 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); |
60 REPORTER_ASSERT(reporter, 0); | 66 REPORTER_ASSERT(reporter, 0); |
61 } | 67 } |
62 if (order2 != 3) { | 68 if (order2 != 3) { |
63 SkDebugf("[%d] quad order=%d\n", iIndex, order2); | 69 SkDebugf("[%d] quad order=%d\n", iIndex, order2); |
64 REPORTER_ASSERT(reporter, 0); | 70 REPORTER_ASSERT(reporter, 0); |
65 } | 71 } |
66 SkDCubic quadToCubic = quad.toCubic(); | |
67 SkIntersections i; | 72 SkIntersections i; |
68 int roots = i.intersect(cubic, quadToCubic); | 73 int roots = i.intersect(cubic, quad); |
69 for (int pt = 0; pt < roots; ++pt) { | 74 for (int pt = 0; pt < roots; ++pt) { |
70 double tt1 = i[0][pt]; | 75 double tt1 = i[0][pt]; |
71 SkDPoint xy1 = cubic.ptAtT(tt1); | 76 SkDPoint xy1 = cubic.ptAtT(tt1); |
72 double tt2 = i[1][pt]; | 77 double tt2 = i[1][pt]; |
73 SkDPoint xy2 = quad.ptAtT(tt2); | 78 SkDPoint xy2 = quad.ptAtT(tt2); |
74 if (!xy1.approximatelyEqual(xy2)) { | 79 if (!xy1.approximatelyEqual(xy2)) { |
75 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", | 80 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
76 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.
fY); | 81 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.
fY); |
77 } | 82 } |
78 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); | 83 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); |
79 } | 84 } |
80 reporter->bumpTestCount(); | 85 reporter->bumpTestCount(); |
81 } | 86 } |
82 | 87 |
83 DEF_TEST(PathOpsCubicQuadIntersection, reporter) { | 88 DEF_TEST(PathOpsCubicQuadIntersection, reporter) { |
84 for (int index = 0; index < quadCubicTests_count; ++index) { | 89 for (int index = 0; index < quadCubicTests_count; ++index) { |
85 cubicQuadIntersection(reporter, index); | 90 cubicQuadIntersection(reporter, index); |
86 reporter->bumpTestCount(); | 91 reporter->bumpTestCount(); |
87 } | 92 } |
88 } | 93 } |
89 | 94 |
90 DEF_TEST(PathOpsCubicQuadIntersectionOneOff, reporter) { | 95 DEF_TEST(PathOpsCubicQuadIntersectionOneOff, reporter) { |
91 cubicQuadIntersection(reporter, 0); | 96 cubicQuadIntersection(reporter, 0); |
92 } | 97 } |
OLD | NEW |