blob: 5996cf804cfb0cbcf5063f7aab6d3f09630ba028 [file] [log] [blame]
caryclark6c3b9cd2016-09-26 05:36:58 -07001/*
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
14static struct conicQuad {
15 SkDConic conic;
16 SkDQuad 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
25static const int conicQuadTests_count = (int) SK_ARRAY_COUNT(conicQuadTests);
26
27static void conicQuadIntersection(skiatest::Reporter* reporter, int index) {
28 const SkDConic& conic = conicQuadTests[index].conic;
29 SkASSERT(ValidConic(conic));
30 const SkDQuad& quad = conicQuadTests[index].quad;
31 SkASSERT(ValidQuad(quad));
32 SkReduceOrder reduce1;
33 SkReduceOrder reduce2;
34 int order1 = reduce2.reduce(conic.fPts);
35 int order2 = reduce1.reduce(quad);
36 if (order2 != 3) {
37 SkDebugf("[%d] conic order=%d\n", index, order1);
38 REPORTER_ASSERT(reporter, 0);
39 }
40 if (order1 != 3) {
41 SkDebugf("[%d] quad order=%d\n", index, order2);
42 REPORTER_ASSERT(reporter, 0);
43 }
44 SkIntersections i;
45 int roots = i.intersect(conic, quad);
46 for (int pt = 0; pt < roots; ++pt) {
47 double tt1 = i[0][pt];
48 SkDPoint xy1 = conic.ptAtT(tt1);
49 double tt2 = i[1][pt];
50 SkDPoint xy2 = quad.ptAtT(tt2);
51 if (!xy1.approximatelyEqual(xy2)) {
52 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
53 __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
54 }
55 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
56 }
57 reporter->bumpTestCount();
58}
59
60DEF_TEST(PathOpsConicQuadIntersection, reporter) {
61 for (int index = 0; index < conicQuadTests_count; ++index) {
62 conicQuadIntersection(reporter, index);
63 reporter->bumpTestCount();
64 }
65}
66
67DEF_TEST(PathOpsConicQuadIntersectionOneOff, reporter) {
68 conicQuadIntersection(reporter, 1);
69}