blob: bdf1d42d377223bfc4d702b0ab018f475435ab7e [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 {
caryclarka35ab3e2016-10-20 08:32:18 -070015 ConicPts conic;
16 QuadPts quad;
caryclark6c3b9cd2016-09-26 05:36:58 -070017} conicQuadTests[] = {
Cary Clark74b42902018-03-09 07:38:47 -050018 {{{{{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
caryclark6c3b9cd2016-09-26 05:36:58 -070025 {{{{{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
32static const int conicQuadTests_count = (int) SK_ARRAY_COUNT(conicQuadTests);
33
34static void conicQuadIntersection(skiatest::Reporter* reporter, int index) {
caryclarka35ab3e2016-10-20 08:32:18 -070035 const ConicPts& c = conicQuadTests[index].conic;
36 SkDConic conic;
37 conic.debugSet(c.fPts.fPts, c.fWeight);
caryclark6c3b9cd2016-09-26 05:36:58 -070038 SkASSERT(ValidConic(conic));
caryclarka35ab3e2016-10-20 08:32:18 -070039 const QuadPts& q = conicQuadTests[index].quad;
40 SkDQuad quad;
41 quad.debugSet(q.fPts);
caryclark6c3b9cd2016-09-26 05:36:58 -070042 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
71DEF_TEST(PathOpsConicQuadIntersection, reporter) {
72 for (int index = 0; index < conicQuadTests_count; ++index) {
73 conicQuadIntersection(reporter, index);
74 reporter->bumpTestCount();
75 }
76}
77
78DEF_TEST(PathOpsConicQuadIntersectionOneOff, reporter) {
Cary Clark74b42902018-03-09 07:38:47 -050079 conicQuadIntersection(reporter, 0);
caryclark6c3b9cd2016-09-26 05:36:58 -070080}