1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2013 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#include "include/utils/SkRandom.h" 8cb93a386Sopenharmony_ci#include "src/pathops/SkIntersections.h" 9cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsCubic.h" 10cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsQuad.h" 11cb93a386Sopenharmony_ci#include "src/pathops/SkReduceOrder.h" 12cb93a386Sopenharmony_ci#include "tests/PathOpsTestCommon.h" 13cb93a386Sopenharmony_ci#include "tests/Test.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_cistatic struct quadCubic { 16cb93a386Sopenharmony_ci CubicPts cubic; 17cb93a386Sopenharmony_ci QuadPts quad; 18cb93a386Sopenharmony_ci} quadCubicTests[] = { 19cb93a386Sopenharmony_ci {{{{945.08099365234375, 747.1619873046875}, {982.5679931640625, 747.1619873046875}, {1013.6290283203125, 719.656005859375}, {1019.1910400390625, 683.72601318359375}}}, 20cb93a386Sopenharmony_ci {{{945, 747}, {976.0660400390625, 747}, {998.03302001953125, 725.03302001953125}}}}, 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci {{{{778, 14089}, {778, 14091.208984375}, {776.20916748046875, 14093}, {774, 14093}}}, 23cb93a386Sopenharmony_ci {{{778, 14089}, {777.99957275390625, 14090.65625}, {776.82843017578125, 14091.828125}}}}, 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_ci {{{{1020.08099,672.161987}, {1020.08002,630.73999}, {986.502014,597.161987}, {945.080994,597.161987}}}, 26cb93a386Sopenharmony_ci {{{1020,672}, {1020,640.93396}, {998.03302,618.96698}}}}, 27cb93a386Sopenharmony_ci 28cb93a386Sopenharmony_ci {{{{778, 14089}, {778, 14091.208984375}, {776.20916748046875, 14093}, {774, 14093}}}, 29cb93a386Sopenharmony_ci {{{778, 14089}, {777.99957275390625, 14090.65625}, {776.82843017578125, 14091.828125}}}}, 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci {{{{1110, 817}, {1110.55225f, 817}, {1111, 817.447693f}, {1111, 818}}}, 32cb93a386Sopenharmony_ci {{{1110.70715f, 817.292908f}, {1110.41406f, 817.000122f}, {1110, 817}}}}, 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ci {{{{1110, 817}, {1110.55225f, 817}, {1111, 817.447693f}, {1111, 818}}}, 35cb93a386Sopenharmony_ci {{{1111, 818}, {1110.99988f, 817.585876f}, {1110.70715f, 817.292908f}}}}, 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci {{{{55, 207}, {52.238574981689453, 207}, {50, 204.76142883300781}, {50, 202}}}, 38cb93a386Sopenharmony_ci {{{55, 207}, {52.929431915283203, 206.99949645996094}, 39cb93a386Sopenharmony_ci {51.464466094970703, 205.53553771972656}}}}, 40cb93a386Sopenharmony_ci 41cb93a386Sopenharmony_ci {{{{49, 47}, {49, 74.614250183105469}, {26.614250183105469, 97}, {-1, 97}}}, 42cb93a386Sopenharmony_ci {{{-8.659739592076221e-015, 96.991401672363281}, {20.065492630004883, 96.645187377929688}, 43cb93a386Sopenharmony_ci {34.355339050292969, 82.355339050292969}}}}, 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ci {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}}, 46cb93a386Sopenharmony_ci {{{18,226}, {14.686291694641113,226}, {12.342399597167969,228.3424072265625}}}}, 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ci {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}}, 49cb93a386Sopenharmony_ci {{{12.342399597167969,228.3424072265625}, {10,230.68629455566406}, {10,234}}}}, 50cb93a386Sopenharmony_ci}; 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_cistatic const int quadCubicTests_count = (int) SK_ARRAY_COUNT(quadCubicTests); 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_cistatic void cubicQuadIntersection(skiatest::Reporter* reporter, int index) { 55cb93a386Sopenharmony_ci int iIndex = static_cast<int>(index); 56cb93a386Sopenharmony_ci const CubicPts& c = quadCubicTests[index].cubic; 57cb93a386Sopenharmony_ci SkDCubic cubic; 58cb93a386Sopenharmony_ci cubic.debugSet(c.fPts); 59cb93a386Sopenharmony_ci SkASSERT(ValidCubic(cubic)); 60cb93a386Sopenharmony_ci const QuadPts& q = quadCubicTests[index].quad; 61cb93a386Sopenharmony_ci SkDQuad quad; 62cb93a386Sopenharmony_ci quad.debugSet(q.fPts); 63cb93a386Sopenharmony_ci SkASSERT(ValidQuad(quad)); 64cb93a386Sopenharmony_ci SkReduceOrder reduce1; 65cb93a386Sopenharmony_ci SkReduceOrder reduce2; 66cb93a386Sopenharmony_ci int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics); 67cb93a386Sopenharmony_ci int order2 = reduce2.reduce(quad); 68cb93a386Sopenharmony_ci if (order1 != 4) { 69cb93a386Sopenharmony_ci SkDebugf("[%d] cubic order=%d\n", iIndex, order1); 70cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, 0); 71cb93a386Sopenharmony_ci } 72cb93a386Sopenharmony_ci if (order2 != 3) { 73cb93a386Sopenharmony_ci SkDebugf("[%d] quad order=%d\n", iIndex, order2); 74cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, 0); 75cb93a386Sopenharmony_ci } 76cb93a386Sopenharmony_ci SkIntersections i; 77cb93a386Sopenharmony_ci int roots = i.intersect(cubic, quad); 78cb93a386Sopenharmony_ci for (int pt = 0; pt < roots; ++pt) { 79cb93a386Sopenharmony_ci double tt1 = i[0][pt]; 80cb93a386Sopenharmony_ci SkDPoint xy1 = cubic.ptAtT(tt1); 81cb93a386Sopenharmony_ci double tt2 = i[1][pt]; 82cb93a386Sopenharmony_ci SkDPoint xy2 = quad.ptAtT(tt2); 83cb93a386Sopenharmony_ci if (!xy1.approximatelyEqual(xy2)) { 84cb93a386Sopenharmony_ci SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", 85cb93a386Sopenharmony_ci __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); 86cb93a386Sopenharmony_ci } 87cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); 88cb93a386Sopenharmony_ci } 89cb93a386Sopenharmony_ci reporter->bumpTestCount(); 90cb93a386Sopenharmony_ci} 91cb93a386Sopenharmony_ci 92cb93a386Sopenharmony_ciDEF_TEST(PathOpsCubicQuadIntersection, reporter) { 93cb93a386Sopenharmony_ci for (int index = 0; index < quadCubicTests_count; ++index) { 94cb93a386Sopenharmony_ci cubicQuadIntersection(reporter, index); 95cb93a386Sopenharmony_ci reporter->bumpTestCount(); 96cb93a386Sopenharmony_ci } 97cb93a386Sopenharmony_ci} 98cb93a386Sopenharmony_ci 99cb93a386Sopenharmony_ciDEF_TEST(PathOpsCubicQuadIntersectionOneOff, reporter) { 100cb93a386Sopenharmony_ci cubicQuadIntersection(reporter, 0); 101cb93a386Sopenharmony_ci} 102