1 /* 2 * Copyright 2015 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 "PathOpsTestCommon.h" 8 #include "SkIntersections.h" 9 #include "SkPathOpsConic.h" 10 #include "SkPathOpsQuad.h" 11 #include "SkReduceOrder.h" 12 #include "Test.h" 13 14 static struct conicQuad { 15 ConicPts conic; 16 QuadPts quad; 17 } conicQuadTests[] = { 18 {{{{{0.00000000000000000, -1.8135968446731567 }, 19 {0.00000000000000000, -1.0033817291259766 }, 20 {-0.0073835160583257675, 0.00000000000000000 }}}, 2.26585215e+11f}, 21 {{{0.00000000000000000, -1.0000113248825073 }, 22 {-2.4824290449032560e-05, -1.0000115633010864 }, 23 {-0.0073835160583257675, 0.00000000000000000 }}}}, 24 25 {{{{{494.348663,224.583771}, {494.365143,224.633194}, {494.376404,224.684067}}}, 0.998645842f}, 26 {{{494.30481,224.474213}, {494.334961,224.538284}, {494.355774,224.605927}}}}, 27 28 {{{{{494.348663,224.583771}, {494.365143,224.633194}, {494.376404,224.684067}}}, 0.998645842f}, 29 {{{494.355774f, 224.605927f}, {494.363708f, 224.631714f}, {494.370148f, 224.657471f}}}}, 30 }; 31 32 static const int conicQuadTests_count = (int) SK_ARRAY_COUNT(conicQuadTests); 33 34 static void conicQuadIntersection(skiatest::Reporter* reporter, int index) { 35 const ConicPts& c = conicQuadTests[index].conic; 36 SkDConic conic; 37 conic.debugSet(c.fPts.fPts, c.fWeight); 38 SkASSERT(ValidConic(conic)); 39 const QuadPts& q = conicQuadTests[index].quad; 40 SkDQuad quad; 41 quad.debugSet(q.fPts); 42 SkASSERT(ValidQuad(quad)); 43 SkReduceOrder reduce1; 44 SkReduceOrder reduce2; 45 int order1 = reduce2.reduce(conic.fPts); 46 int order2 = reduce1.reduce(quad); 47 if (order2 != 3) { 48 SkDebugf("[%d] conic order=%d\n", index, order1); 49 REPORTER_ASSERT(reporter, 0); 50 } 51 if (order1 != 3) { 52 SkDebugf("[%d] quad order=%d\n", index, order2); 53 REPORTER_ASSERT(reporter, 0); 54 } 55 SkIntersections i; 56 int roots = i.intersect(conic, quad); 57 for (int pt = 0; pt < roots; ++pt) { 58 double tt1 = i[0][pt]; 59 SkDPoint xy1 = conic.ptAtT(tt1); 60 double tt2 = i[1][pt]; 61 SkDPoint xy2 = quad.ptAtT(tt2); 62 if (!xy1.approximatelyEqual(xy2)) { 63 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", 64 __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); 65 } 66 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); 67 } 68 reporter->bumpTestCount(); 69 } 70 71 DEF_TEST(PathOpsConicQuadIntersection, reporter) { 72 for (int index = 0; index < conicQuadTests_count; ++index) { 73 conicQuadIntersection(reporter, index); 74 reporter->bumpTestCount(); 75 } 76 } 77 78 DEF_TEST(PathOpsConicQuadIntersectionOneOff, reporter) { 79 conicQuadIntersection(reporter, 0); 80 } 81