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