17839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger/*
27839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger * Copyright 2012 Google Inc.
37839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger *
47839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger * Use of this source code is governed by a BSD-style license that can be
57839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger * found in the LICENSE file.
67839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger */
77839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#include "PathOpsQuadIntersectionTestData.h"
87839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#include "SkIntersections.h"
97839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#include "SkPathOpsRect.h"
107839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#include "SkReduceOrder.h"
117839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#include "Test.h"
127839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
137839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerstatic const SkDQuad testSet[] = {
147839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    {{{1, 1}, {2, 2}, {1, 1.000003}}},
157839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    {{{1, 0}, {2, 6}, {3, 0}}}
167839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger};
177839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
187839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerstatic const size_t testSetCount = SK_ARRAY_COUNT(testSet);
197839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
207839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerstatic void oneOffTest(skiatest::Reporter* reporter) {
217839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    for (size_t index = 0; index < testSetCount; ++index) {
227839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        const SkDQuad& quad = testSet[index];
237839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        SkReduceOrder reducer;
24910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger        SkDEBUGCODE(int result = ) reducer.reduce(quad);
257839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        SkASSERT(result == 3);
267839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    }
277839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger}
287839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
297839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerstatic void standardTestCases(skiatest::Reporter* reporter) {
307839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    size_t index;
317839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    SkReduceOrder reducer;
327839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    int order;
337839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    enum {
347839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        RunAll,
357839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        RunQuadraticLines,
367839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        RunQuadraticModLines,
377839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        RunNone
387839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    } run = RunAll;
397839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    int firstTestIndex = 0;
407839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#if 0
417839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    run = RunQuadraticLines;
427839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    firstTestIndex = 1;
437839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#endif
447839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex
457839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger            : SK_MaxS32;
467839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex
477839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger            : SK_MaxS32;
487839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
497839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
507839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        const SkDQuad& quad = quadraticLines[index];
51910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger        order = reducer.reduce(quad);
527839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        if (order != 2) {
530a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger            SkDebugf("[%d] line quad order=%d\n", (int) index, order);
547839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        }
557839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    }
567839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
577839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        const SkDQuad& quad = quadraticModEpsilonLines[index];
58910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger        order = reducer.reduce(quad);
597839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        if (order != 3) {
600a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger            SkDebugf("[%d] line mod quad order=%d\n", (int) index, order);
617839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger        }
627839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    }
637839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger}
647839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
657839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenbergerstatic void PathOpsReduceOrderQuadTest(skiatest::Reporter* reporter) {
667839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    oneOffTest(reporter);
677839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger    standardTestCases(reporter);
687839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger}
697839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger
707839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger#include "TestClassDef.h"
717839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek SollenbergerDEFINE_TESTCLASS_SHORT(PathOpsReduceOrderQuadTest)
72