OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 #include "SkIntersections.h" |
| 8 #include "SkPathOpsCubic.h" |
| 9 #include "SkPathOpsQuad.h" |
| 10 #include "SkReduceOrder.h" |
| 11 #include "Test.h" |
| 12 |
| 13 static struct lineCubic { |
| 14 SkDCubic cubic; |
| 15 SkDQuad quad; |
| 16 int answerCount; |
| 17 SkDPoint answers[2]; |
| 18 } quadCubicTests[] = { |
| 19 {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}}, |
| 20 {{{18,226}, {14.686291694641113,226}, {12.342399597167969,228.3424072265
625}}}, 1, |
| 21 {{18,226}, {0,0}}}, |
| 22 {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}}, |
| 23 {{{12.342399597167969,228.3424072265625}, {10,230.68629455566406}, {10,2
34}}}, 1, |
| 24 {{10,234}, {0,0}}}, |
| 25 }; |
| 26 |
| 27 static const size_t quadCubicTests_count = SK_ARRAY_COUNT(quadCubicTests); |
| 28 |
| 29 static void PathOpsCubicQuadIntersectionTest(skiatest::Reporter* reporter) { |
| 30 for (size_t index = 0; index < quadCubicTests_count; ++index) { |
| 31 int iIndex = static_cast<int>(index); |
| 32 const SkDCubic& cubic = quadCubicTests[index].cubic; |
| 33 const SkDQuad& quad = quadCubicTests[index].quad; |
| 34 SkReduceOrder reduce1; |
| 35 SkReduceOrder reduce2; |
| 36 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics, |
| 37 SkReduceOrder::kFill_Style); |
| 38 int order2 = reduce2.reduce(quad, SkReduceOrder::kFill_Style); |
| 39 if (order1 != 4) { |
| 40 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); |
| 41 REPORTER_ASSERT(reporter, 0); |
| 42 } |
| 43 if (order2 != 3) { |
| 44 SkDebugf("[%d] quad order=%d\n", iIndex, order2); |
| 45 REPORTER_ASSERT(reporter, 0); |
| 46 } |
| 47 SkIntersections i; |
| 48 int roots = i.intersect(cubic, quad); |
| 49 SkASSERT(roots == quadCubicTests[index].answerCount); |
| 50 for (int pt = 0; pt < roots; ++pt) { |
| 51 double tt1 = i[0][pt]; |
| 52 SkDPoint xy1 = cubic.xyAtT(tt1); |
| 53 double tt2 = i[1][pt]; |
| 54 SkDPoint xy2 = quad.xyAtT(tt2); |
| 55 if (!xy1.approximatelyEqual(xy2)) { |
| 56 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 57 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX,
xy2.fY); |
| 58 } |
| 59 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); |
| 60 bool found = false; |
| 61 for (int idx2 = 0; idx2 < quadCubicTests[index].answerCount; ++idx2)
{ |
| 62 found |= quadCubicTests[index].answers[idx2].approximatelyEqual(
xy1); |
| 63 } |
| 64 REPORTER_ASSERT(reporter, found); |
| 65 } |
| 66 reporter->bumpTestCount(); |
| 67 } |
| 68 } |
| 69 |
| 70 #include "TestClassDef.h" |
| 71 DEFINE_TESTCLASS_SHORT(PathOpsCubicQuadIntersectionTest) |
OLD | NEW |