1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 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 "src/core/SkGeometry.h"
8cb93a386Sopenharmony_ci#include "src/pathops/SkIntersections.h"
9cb93a386Sopenharmony_ci#include "tests/PathOpsTestCommon.h"
10cb93a386Sopenharmony_ci#include "tests/Test.h"
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ci/*
13cb93a386Sopenharmony_cimanually compute the intersection of a pair of circles and see if the conic intersection matches
14cb93a386Sopenharmony_ci  given two circles
15cb93a386Sopenharmony_ci    construct a line connecting their centers
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_ci */
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_cistatic const ConicPts testSet[] = {
20cb93a386Sopenharmony_ci    {{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
21cb93a386Sopenharmony_ci    {{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
22cb93a386Sopenharmony_ci
23cb93a386Sopenharmony_ci    {{{{5.1114602088928223, 628.77813720703125},
24cb93a386Sopenharmony_ci        {10.834027290344238, 988.964111328125},
25cb93a386Sopenharmony_ci        {163.40835571289062, 988.964111328125}}}, 0.72944212f},
26cb93a386Sopenharmony_ci    {{{{163.40835571289062, 988.964111328125},
27cb93a386Sopenharmony_ci        {5, 988.964111328125},
28cb93a386Sopenharmony_ci        {5, 614.7423095703125}}}, 0.707106769f},
29cb93a386Sopenharmony_ci
30cb93a386Sopenharmony_ci    {{{{11.17222976684570312, -8.103978157043457031},
31cb93a386Sopenharmony_ci        {22.91432571411132812, -10.37866020202636719},
32cb93a386Sopenharmony_ci        {23.7764129638671875, -7.725424289703369141}}}, 1.00862849f},
33cb93a386Sopenharmony_ci    {{{{-1.545085430145263672, -4.755282402038574219},
34cb93a386Sopenharmony_ci        {22.23132705688476562, -12.48070907592773438},
35cb93a386Sopenharmony_ci        {23.7764129638671875, -7.725427150726318359}}}, 0.707106769f},
36cb93a386Sopenharmony_ci
37cb93a386Sopenharmony_ci    {{{{-4,1}, {-4,5}, {0,5}}}, 0.707106769f},
38cb93a386Sopenharmony_ci    {{{{-3,4}, {-3,1}, {0,1}}}, 0.707106769f},
39cb93a386Sopenharmony_ci
40cb93a386Sopenharmony_ci    {{{{0, 0}, {0, 1}, {1, 1}}}, 0.5f},
41cb93a386Sopenharmony_ci    {{{{1, 0}, {0, 0}, {0, 1}}}, 0.5f},
42cb93a386Sopenharmony_ci
43cb93a386Sopenharmony_ci};
44cb93a386Sopenharmony_ci
45cb93a386Sopenharmony_ciconst int testSetCount = (int) SK_ARRAY_COUNT(testSet);
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_cistatic void chopCompare(const SkConic chopped[2], const SkDConic dChopped[2]) {
48cb93a386Sopenharmony_ci    SkASSERT(roughly_equal(chopped[0].fW, dChopped[0].fWeight));
49cb93a386Sopenharmony_ci    SkASSERT(roughly_equal(chopped[1].fW, dChopped[1].fWeight));
50cb93a386Sopenharmony_ci    for (int cIndex = 0; cIndex < 2; ++cIndex) {
51cb93a386Sopenharmony_ci        for (int pIndex = 0; pIndex < 3; ++pIndex) {
52cb93a386Sopenharmony_ci            SkDPoint up;
53cb93a386Sopenharmony_ci            up.set(chopped[cIndex].fPts[pIndex]);
54cb93a386Sopenharmony_ci            SkASSERT(dChopped[cIndex].fPts[pIndex].approximatelyEqual(up));
55cb93a386Sopenharmony_ci        }
56cb93a386Sopenharmony_ci    }
57cb93a386Sopenharmony_ci#if DEBUG_VISUALIZE_CONICS
58cb93a386Sopenharmony_ci    dChopped[0].dump();
59cb93a386Sopenharmony_ci    dChopped[1].dump();
60cb93a386Sopenharmony_ci#endif
61cb93a386Sopenharmony_ci}
62cb93a386Sopenharmony_ci
63cb93a386Sopenharmony_ci#include "include/core/SkBitmap.h"
64cb93a386Sopenharmony_ci#include "include/core/SkCanvas.h"
65cb93a386Sopenharmony_ci#include "include/core/SkImageEncoder.h"
66cb93a386Sopenharmony_ci#include "include/core/SkPaint.h"
67cb93a386Sopenharmony_ci#include "include/core/SkString.h"
68cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsRect.h"
69cb93a386Sopenharmony_ci
70cb93a386Sopenharmony_ci#define DEBUG_VISUALIZE_CONICS 0
71cb93a386Sopenharmony_ci
72cb93a386Sopenharmony_ci#if DEBUG_VISUALIZE_CONICS
73cb93a386Sopenharmony_cistatic void writePng(const SkConic& c, const SkConic ch[2], const char* name) {
74cb93a386Sopenharmony_ci    const int scale = 10;
75cb93a386Sopenharmony_ci    SkConic conic, chopped[2];
76cb93a386Sopenharmony_ci    for (int index = 0; index < 3; ++index) {
77cb93a386Sopenharmony_ci        conic.fPts[index].fX = c.fPts[index].fX * scale;
78cb93a386Sopenharmony_ci        conic.fPts[index].fY = c.fPts[index].fY * scale;
79cb93a386Sopenharmony_ci        for (int chIndex = 0; chIndex < 2; ++chIndex) {
80cb93a386Sopenharmony_ci            chopped[chIndex].fPts[index].fX = ch[chIndex].fPts[index].fX * scale;
81cb93a386Sopenharmony_ci            chopped[chIndex].fPts[index].fY = ch[chIndex].fPts[index].fY * scale;
82cb93a386Sopenharmony_ci        }
83cb93a386Sopenharmony_ci    }
84cb93a386Sopenharmony_ci    conic.fW = c.fW;
85cb93a386Sopenharmony_ci    chopped[0].fW = ch[0].fW;
86cb93a386Sopenharmony_ci    chopped[1].fW = ch[1].fW;
87cb93a386Sopenharmony_ci    SkBitmap bitmap;
88cb93a386Sopenharmony_ci    SkRect bounds;
89cb93a386Sopenharmony_ci    conic.computeTightBounds(&bounds);
90cb93a386Sopenharmony_ci    bounds.outset(10, 10);
91cb93a386Sopenharmony_ci    bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(
92cb93a386Sopenharmony_ci          SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height())));
93cb93a386Sopenharmony_ci    SkCanvas canvas(bitmap);
94cb93a386Sopenharmony_ci    SkPaint paint;
95cb93a386Sopenharmony_ci    paint.setAntiAlias(true);
96cb93a386Sopenharmony_ci    paint.setStyle(SkPaint::kStroke_Style);
97cb93a386Sopenharmony_ci    canvas.translate(-bounds.fLeft, -bounds.fTop);
98cb93a386Sopenharmony_ci    canvas.drawColor(SK_ColorWHITE);
99cb93a386Sopenharmony_ci    SkPath path;
100cb93a386Sopenharmony_ci    path.moveTo(conic.fPts[0]);
101cb93a386Sopenharmony_ci    path.conicTo(conic.fPts[1], conic.fPts[2], conic.fW);
102cb93a386Sopenharmony_ci    paint.setARGB(0x80, 0xFF, 0, 0);
103cb93a386Sopenharmony_ci    canvas.drawPath(path, paint);
104cb93a386Sopenharmony_ci    path.reset();
105cb93a386Sopenharmony_ci    path.moveTo(chopped[0].fPts[0]);
106cb93a386Sopenharmony_ci    path.conicTo(chopped[0].fPts[1], chopped[0].fPts[2], chopped[0].fW);
107cb93a386Sopenharmony_ci    path.moveTo(chopped[1].fPts[0]);
108cb93a386Sopenharmony_ci    path.conicTo(chopped[1].fPts[1], chopped[1].fPts[2], chopped[1].fW);
109cb93a386Sopenharmony_ci    paint.setARGB(0x80, 0, 0, 0xFF);
110cb93a386Sopenharmony_ci    canvas.drawPath(path, paint);
111cb93a386Sopenharmony_ci    SkString filename("c:\\Users\\caryclark\\Documents\\");
112cb93a386Sopenharmony_ci    filename.appendf("%s.png", name);
113cb93a386Sopenharmony_ci    ToolUtils::EncodeImageToFile(filename.c_str(), bitmap, SkEncodedImageFormat::kPNG, 100);
114cb93a386Sopenharmony_ci}
115cb93a386Sopenharmony_ci
116cb93a386Sopenharmony_cistatic void writeDPng(const SkDConic& dC, const char* name) {
117cb93a386Sopenharmony_ci    const int scale = 5;
118cb93a386Sopenharmony_ci    SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale },
119cb93a386Sopenharmony_ci        {dC.fPts[1].fX * scale, dC.fPts[1].fY * scale },
120cb93a386Sopenharmony_ci        {dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight };
121cb93a386Sopenharmony_ci    SkBitmap bitmap;
122cb93a386Sopenharmony_ci    SkDRect bounds;
123cb93a386Sopenharmony_ci    bounds.setBounds(dConic);
124cb93a386Sopenharmony_ci    bounds.fLeft -= 10;
125cb93a386Sopenharmony_ci    bounds.fTop -= 10;
126cb93a386Sopenharmony_ci    bounds.fRight += 10;
127cb93a386Sopenharmony_ci    bounds.fBottom += 10;
128cb93a386Sopenharmony_ci    bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(
129cb93a386Sopenharmony_ci          SkScalarRoundToInt(SkDoubleToScalar(bounds.width())),
130cb93a386Sopenharmony_ci          SkScalarRoundToInt(SkDoubleToScalar(bounds.height()))));
131cb93a386Sopenharmony_ci    SkCanvas canvas(bitmap);
132cb93a386Sopenharmony_ci    SkPaint paint;
133cb93a386Sopenharmony_ci    paint.setAntiAlias(true);
134cb93a386Sopenharmony_ci    paint.setStyle(SkPaint::kStroke_Style);
135cb93a386Sopenharmony_ci    canvas.translate(SkDoubleToScalar(-bounds.fLeft), SkDoubleToScalar(-bounds.fTop));
136cb93a386Sopenharmony_ci    canvas.drawColor(SK_ColorWHITE);
137cb93a386Sopenharmony_ci    SkPath path;
138cb93a386Sopenharmony_ci    path.moveTo(dConic.fPts[0].asSkPoint());
139cb93a386Sopenharmony_ci    path.conicTo(dConic.fPts[1].asSkPoint(), dConic.fPts[2].asSkPoint(), dConic.fWeight);
140cb93a386Sopenharmony_ci    paint.setARGB(0x80, 0xFF, 0, 0);
141cb93a386Sopenharmony_ci    canvas.drawPath(path, paint);
142cb93a386Sopenharmony_ci    path.reset();
143cb93a386Sopenharmony_ci    const int chops = 2;
144cb93a386Sopenharmony_ci    for (int tIndex = 0; tIndex < chops; ++tIndex) {
145cb93a386Sopenharmony_ci        SkDConic chopped = dConic.subDivide(tIndex / (double) chops,
146cb93a386Sopenharmony_ci                (tIndex + 1) / (double) chops);
147cb93a386Sopenharmony_ci        path.moveTo(chopped.fPts[0].asSkPoint());
148cb93a386Sopenharmony_ci        path.conicTo(chopped.fPts[1].asSkPoint(), chopped.fPts[2].asSkPoint(), chopped.fWeight);
149cb93a386Sopenharmony_ci    }
150cb93a386Sopenharmony_ci    paint.setARGB(0x80, 0, 0, 0xFF);
151cb93a386Sopenharmony_ci    canvas.drawPath(path, paint);
152cb93a386Sopenharmony_ci    SkString filename("c:\\Users\\caryclark\\Documents\\");
153cb93a386Sopenharmony_ci    filename.appendf("%s.png", name);
154cb93a386Sopenharmony_ci    ToolUtils::EncodeImageToFile(filename.c_str(), bitmap, SkEncodedImageFormat::kPNG, 100);
155cb93a386Sopenharmony_ci}
156cb93a386Sopenharmony_ci#endif
157cb93a386Sopenharmony_ci
158cb93a386Sopenharmony_cistatic void chopBothWays(const SkDConic& dConic, double t, const char* name) {
159cb93a386Sopenharmony_ci    SkConic conic;
160cb93a386Sopenharmony_ci    for (int index = 0; index < 3; ++index) {
161cb93a386Sopenharmony_ci        conic.fPts[index] = dConic.fPts[index].asSkPoint();
162cb93a386Sopenharmony_ci    }
163cb93a386Sopenharmony_ci    conic.fW = dConic.fWeight;
164cb93a386Sopenharmony_ci    SkConic chopped[2];
165cb93a386Sopenharmony_ci    SkDConic dChopped[2];
166cb93a386Sopenharmony_ci    if (!conic.chopAt(SkDoubleToScalar(t), chopped)) {
167cb93a386Sopenharmony_ci        return;
168cb93a386Sopenharmony_ci    }
169cb93a386Sopenharmony_ci    dChopped[0] = dConic.subDivide(0, t);
170cb93a386Sopenharmony_ci    dChopped[1] = dConic.subDivide(t, 1);
171cb93a386Sopenharmony_ci#if DEBUG_VISUALIZE_CONICS
172cb93a386Sopenharmony_ci    dConic.dump();
173cb93a386Sopenharmony_ci#endif
174cb93a386Sopenharmony_ci    chopCompare(chopped, dChopped);
175cb93a386Sopenharmony_ci#if DEBUG_VISUALIZE_CONICS
176cb93a386Sopenharmony_ci    writePng(conic, chopped, name);
177cb93a386Sopenharmony_ci#endif
178cb93a386Sopenharmony_ci}
179cb93a386Sopenharmony_ci
180cb93a386Sopenharmony_ci#if DEBUG_VISUALIZE_CONICS
181cb93a386Sopenharmony_ciconst SkDConic frame0[] = {
182cb93a386Sopenharmony_ci{{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
183cb93a386Sopenharmony_ci{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
184cb93a386Sopenharmony_ci};
185cb93a386Sopenharmony_ci
186cb93a386Sopenharmony_ciconst SkDConic frame1[] = {
187cb93a386Sopenharmony_ci{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
188cb93a386Sopenharmony_ci{{{{306.58801299999999, -227.983994}, {212.46499600000001, -262.24200400000001}, {95.551200899999998, 58.976398500000002}}}, 0.707107008f},
189cb93a386Sopenharmony_ci{{{{377.21899400000001, -141.98100299999999}, {237.77799285476553, -166.56830755921084}, {134.08399674208422, -155.06258330544892}}}, 0.788580656f},
190cb93a386Sopenharmony_ci{{{{134.08399674208422, -155.06258330544892}, {30.390000629402859, -143.55685905168704}, {23.185499199999999, -102.697998}}}, 0.923879623f},
191cb93a386Sopenharmony_ci};
192cb93a386Sopenharmony_ci
193cb93a386Sopenharmony_ciconst SkDConic frame2[] = {
194cb93a386Sopenharmony_ci{{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
195cb93a386Sopenharmony_ci{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
196cb93a386Sopenharmony_ci{{{{205.78973252799028, -158.12538713371103}, {143.97848953841861, -74.076645245042371}, {95.551200899999998, 58.976398500000002}}}, 0.923879623f},
197cb93a386Sopenharmony_ci{{{{377.21899400000001, -141.98100299999999}, {237.77799285476553, -166.56830755921084}, {134.08399674208422, -155.06258330544892}}}, 0.788580656f},
198cb93a386Sopenharmony_ci};
199cb93a386Sopenharmony_ci
200cb93a386Sopenharmony_ciconst SkDConic frame3[] = {
201cb93a386Sopenharmony_ci{{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
202cb93a386Sopenharmony_ci{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
203cb93a386Sopenharmony_ci{{{{205.78973252799028, -158.12538713371103}, {143.97848953841861, -74.076645245042371}, {95.551200899999998, 58.976398500000002}}}, 0.923879623f},
204cb93a386Sopenharmony_ci{{{{252.08225670812539, -156.90491625851064}, {185.93099479842493, -160.81544543232982}, {134.08399674208422, -155.06258330544892}}}, 0.835816324f},
205cb93a386Sopenharmony_ci};
206cb93a386Sopenharmony_ci
207cb93a386Sopenharmony_ciconst SkDConic frame4[] = {
208cb93a386Sopenharmony_ci{{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
209cb93a386Sopenharmony_ci{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
210cb93a386Sopenharmony_ci{{{{205.78973252799028, -158.12538713371103}, {174.88411103320448, -116.10101618937664}, {145.19509369736275, -56.857102571363754}}}, 0.871667147f},
211cb93a386Sopenharmony_ci{{{{252.08225670812539, -156.90491625851064}, {185.93099479842493, -160.81544543232982}, {134.08399674208422, -155.06258330544892}}}, 0.835816324f},
212cb93a386Sopenharmony_ci};
213cb93a386Sopenharmony_ci
214cb93a386Sopenharmony_ciconst SkDConic frame5[] = {
215cb93a386Sopenharmony_ci{{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
216cb93a386Sopenharmony_ci{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
217cb93a386Sopenharmony_ci{{{{205.78973252799028, -158.12538713371103}, {174.88411103320448, -116.10101618937664}, {145.19509369736275, -56.857102571363754}}}, 0.871667147f},
218cb93a386Sopenharmony_ci{{{{252.08225670812539, -156.90491625851064}, {219.70109133058406, -158.81912754088933}, {190.17095392508796, -158.38373974664466}}}, 0.858306944f},
219cb93a386Sopenharmony_ci};
220cb93a386Sopenharmony_ci
221cb93a386Sopenharmony_ciconst SkDConic frame6[] = {
222cb93a386Sopenharmony_ci{{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
223cb93a386Sopenharmony_ci{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
224cb93a386Sopenharmony_ci{{{{205.78973252799028, -158.12538713371103}, {190.33692178059735, -137.11320166154385}, {174.87004877564593, -111.2132534799228}}}, 0.858117759f},
225cb93a386Sopenharmony_ci{{{{252.08225670812539, -156.90491625851064}, {219.70109133058406, -158.81912754088933}, {190.17095392508796, -158.38373974664466}}}, 0.858306944f},
226cb93a386Sopenharmony_ci};
227cb93a386Sopenharmony_ci
228cb93a386Sopenharmony_ciconst SkDConic* frames[] = {
229cb93a386Sopenharmony_ci    frame0, frame1, frame2, frame3, frame4, frame5, frame6
230cb93a386Sopenharmony_ci};
231cb93a386Sopenharmony_ci
232cb93a386Sopenharmony_ciconst int frameSizes[] = { (int) SK_ARRAY_COUNT(frame0), (int) SK_ARRAY_COUNT(frame1),
233cb93a386Sopenharmony_ci        (int) SK_ARRAY_COUNT(frame2), (int) SK_ARRAY_COUNT(frame3),
234cb93a386Sopenharmony_ci        (int) SK_ARRAY_COUNT(frame4), (int) SK_ARRAY_COUNT(frame5),
235cb93a386Sopenharmony_ci        (int) SK_ARRAY_COUNT(frame6),
236cb93a386Sopenharmony_ci};
237cb93a386Sopenharmony_ci
238cb93a386Sopenharmony_cistatic void writeFrames() {
239cb93a386Sopenharmony_ci    const int scale = 5;
240cb93a386Sopenharmony_ci
241cb93a386Sopenharmony_ci    for (int index = 0; index < (int) SK_ARRAY_COUNT(frameSizes); ++index) {
242cb93a386Sopenharmony_ci        SkDRect bounds;
243cb93a386Sopenharmony_ci        bool boundsSet = false;
244cb93a386Sopenharmony_ci        int frameSize = frameSizes[index];
245cb93a386Sopenharmony_ci        for (int fIndex = 0; fIndex < frameSize; ++fIndex) {
246cb93a386Sopenharmony_ci            const SkDConic& dC = frames[index][fIndex];
247cb93a386Sopenharmony_ci            SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale },
248cb93a386Sopenharmony_ci                {dC.fPts[1].fX * scale, dC.fPts[1].fY * scale },
249cb93a386Sopenharmony_ci                {dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight };
250cb93a386Sopenharmony_ci            SkDRect dBounds;
251cb93a386Sopenharmony_ci            dBounds.setBounds(dConic);
252cb93a386Sopenharmony_ci            if (!boundsSet) {
253cb93a386Sopenharmony_ci                bounds = dBounds;
254cb93a386Sopenharmony_ci                boundsSet = true;
255cb93a386Sopenharmony_ci            } else {
256cb93a386Sopenharmony_ci                bounds.add((SkDPoint&) dBounds.fLeft);
257cb93a386Sopenharmony_ci                bounds.add((SkDPoint&) dBounds.fRight);
258cb93a386Sopenharmony_ci            }
259cb93a386Sopenharmony_ci        }
260cb93a386Sopenharmony_ci        bounds.fLeft -= 10;
261cb93a386Sopenharmony_ci        bounds.fTop -= 10;
262cb93a386Sopenharmony_ci        bounds.fRight += 10;
263cb93a386Sopenharmony_ci        bounds.fBottom += 10;
264cb93a386Sopenharmony_ci        SkBitmap bitmap;
265cb93a386Sopenharmony_ci        bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(
266cb93a386Sopenharmony_ci              SkScalarRoundToInt(SkDoubleToScalar(bounds.width())),
267cb93a386Sopenharmony_ci              SkScalarRoundToInt(SkDoubleToScalar(bounds.height()))));
268cb93a386Sopenharmony_ci        SkCanvas canvas(bitmap);
269cb93a386Sopenharmony_ci        SkPaint paint;
270cb93a386Sopenharmony_ci        paint.setAntiAlias(true);
271cb93a386Sopenharmony_ci        paint.setStyle(SkPaint::kStroke_Style);
272cb93a386Sopenharmony_ci        canvas.translate(SkDoubleToScalar(-bounds.fLeft), SkDoubleToScalar(-bounds.fTop));
273cb93a386Sopenharmony_ci        canvas.drawColor(SK_ColorWHITE);
274cb93a386Sopenharmony_ci        for (int fIndex = 0; fIndex < frameSize; ++fIndex) {
275cb93a386Sopenharmony_ci            const SkDConic& dC = frames[index][fIndex];
276cb93a386Sopenharmony_ci            SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale },
277cb93a386Sopenharmony_ci                {dC.fPts[1].fX * scale, dC.fPts[1].fY * scale },
278cb93a386Sopenharmony_ci                {dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight };
279cb93a386Sopenharmony_ci            SkPath path;
280cb93a386Sopenharmony_ci            path.moveTo(dConic.fPts[0].asSkPoint());
281cb93a386Sopenharmony_ci            path.conicTo(dConic.fPts[1].asSkPoint(), dConic.fPts[2].asSkPoint(), dConic.fWeight);
282cb93a386Sopenharmony_ci            if (fIndex < 2) {
283cb93a386Sopenharmony_ci                paint.setARGB(0x80, 0xFF, 0, 0);
284cb93a386Sopenharmony_ci            } else {
285cb93a386Sopenharmony_ci                paint.setARGB(0x80, 0, 0, 0xFF);
286cb93a386Sopenharmony_ci            }
287cb93a386Sopenharmony_ci            canvas.drawPath(path, paint);
288cb93a386Sopenharmony_ci        }
289cb93a386Sopenharmony_ci        SkString filename("c:\\Users\\caryclark\\Documents\\");
290cb93a386Sopenharmony_ci        filename.appendf("f%d.png", index);
291cb93a386Sopenharmony_ci        ToolUtils::EncodeImageToFile(filename.c_str(), bitmap, SkEncodedImageFormat::kPNG, 100);
292cb93a386Sopenharmony_ci    }
293cb93a386Sopenharmony_ci}
294cb93a386Sopenharmony_ci#endif
295cb93a386Sopenharmony_ci
296cb93a386Sopenharmony_cistatic void oneOff(skiatest::Reporter* reporter, const ConicPts& conic1, const ConicPts& conic2,
297cb93a386Sopenharmony_ci        bool coin) {
298cb93a386Sopenharmony_ci#if DEBUG_VISUALIZE_CONICS
299cb93a386Sopenharmony_ci    writeFrames();
300cb93a386Sopenharmony_ci#endif
301cb93a386Sopenharmony_ci    SkDConic c1, c2;
302cb93a386Sopenharmony_ci    c1.debugSet(conic1.fPts.fPts, conic1.fWeight);
303cb93a386Sopenharmony_ci    c2.debugSet(conic2.fPts.fPts, conic2.fWeight);
304cb93a386Sopenharmony_ci    chopBothWays(c1, 0.5, "c1");
305cb93a386Sopenharmony_ci    chopBothWays(c2, 0.5, "c2");
306cb93a386Sopenharmony_ci#if DEBUG_VISUALIZE_CONICS
307cb93a386Sopenharmony_ci    writeDPng(c1, "d1");
308cb93a386Sopenharmony_ci    writeDPng(c2, "d2");
309cb93a386Sopenharmony_ci#endif
310cb93a386Sopenharmony_ci    SkASSERT(ValidConic(c1));
311cb93a386Sopenharmony_ci    SkASSERT(ValidConic(c2));
312cb93a386Sopenharmony_ci    SkIntersections intersections;
313cb93a386Sopenharmony_ci    intersections.intersect(c1, c2);
314cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, !coin || intersections.used() == 2);
315cb93a386Sopenharmony_ci    double tt1, tt2;
316cb93a386Sopenharmony_ci    SkDPoint xy1, xy2;
317cb93a386Sopenharmony_ci    for (int pt3 = 0; pt3 < intersections.used(); ++pt3) {
318cb93a386Sopenharmony_ci        tt1 = intersections[0][pt3];
319cb93a386Sopenharmony_ci        xy1 = c1.ptAtT(tt1);
320cb93a386Sopenharmony_ci        tt2 = intersections[1][pt3];
321cb93a386Sopenharmony_ci        xy2 = c2.ptAtT(tt2);
322cb93a386Sopenharmony_ci        const SkDPoint& iPt = intersections.pt(pt3);
323cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, xy1.approximatelyEqual(iPt));
324cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, xy2.approximatelyEqual(iPt));
325cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
326cb93a386Sopenharmony_ci    }
327cb93a386Sopenharmony_ci    reporter->bumpTestCount();
328cb93a386Sopenharmony_ci}
329cb93a386Sopenharmony_ci
330cb93a386Sopenharmony_cistatic void oneOff(skiatest::Reporter* reporter, int outer, int inner) {
331cb93a386Sopenharmony_ci    const ConicPts& c1 = testSet[outer];
332cb93a386Sopenharmony_ci    const ConicPts& c2 = testSet[inner];
333cb93a386Sopenharmony_ci    oneOff(reporter, c1, c2, false);
334cb93a386Sopenharmony_ci}
335cb93a386Sopenharmony_ci
336cb93a386Sopenharmony_cistatic void oneOffTests(skiatest::Reporter* reporter) {
337cb93a386Sopenharmony_ci    for (int outer = 0; outer < testSetCount - 1; ++outer) {
338cb93a386Sopenharmony_ci        for (int inner = outer + 1; inner < testSetCount; ++inner) {
339cb93a386Sopenharmony_ci            oneOff(reporter, outer, inner);
340cb93a386Sopenharmony_ci        }
341cb93a386Sopenharmony_ci    }
342cb93a386Sopenharmony_ci}
343cb93a386Sopenharmony_ci
344cb93a386Sopenharmony_ciDEF_TEST(PathOpsConicIntersectionOneOff, reporter) {
345cb93a386Sopenharmony_ci    oneOff(reporter, 0, 1);
346cb93a386Sopenharmony_ci}
347cb93a386Sopenharmony_ci
348cb93a386Sopenharmony_ciDEF_TEST(PathOpsConicIntersection, reporter) {
349cb93a386Sopenharmony_ci    oneOffTests(reporter);
350cb93a386Sopenharmony_ci}
351