Flutter Engine
The Flutter Engine
PathOpsQuadLineIntersectionTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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 */
15#include "tests/Test.h"
16
17#include <array>
18#include <cstddef>
19#include <utility>
20
21static struct lineQuad {
24 int result;
26} lineQuadTests[] = {
27 // quad line results
28 {{{{1, 1}, {2, 1}, {0, 2}}}, {{{0, 0}, {1, 1}}}, 1, {{1, 1}, {0, 0}} },
29 {{{{0, 0}, {1, 1}, {3, 1}}}, {{{0, 0}, {3, 1}}}, 2, {{0, 0}, {3, 1}} },
30 {{{{2, 0}, {1, 1}, {2, 2}}}, {{{0, 0}, {0, 2}}}, 0, {{0, 0}, {0, 0}} },
31 {{{{4, 0}, {0, 1}, {4, 2}}}, {{{3, 1}, {4, 1}}}, 0, {{0, 0}, {0, 0}} },
32 {{{{0, 0}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}, 1, {{.25, .75}, {0, 0}} },
33};
34
36
37static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, const SkDLine& line,
38 bool& flipped) {
39 int result;
40 flipped = false;
41 if (line[0].fX == line[1].fX) {
42 double top = line[0].fY;
43 double bottom = line[1].fY;
44 flipped = top > bottom;
45 if (flipped) {
46 using std::swap;
47 swap(top, bottom);
48 }
49 result = intersections.vertical(quad, top, bottom, line[0].fX, flipped);
50 } else if (line[0].fY == line[1].fY) {
51 double left = line[0].fX;
52 double right = line[1].fX;
53 flipped = left > right;
54 if (flipped) {
55 using std::swap;
56 swap(left, right);
57 }
58 result = intersections.horizontal(quad, left, right, line[0].fY, flipped);
59 } else {
60 intersections.intersect(quad, line);
61 result = intersections.used();
62 }
63 return result;
64}
65
66static struct oneLineQuad {
69} oneOffs[] = {
70 {{{{97.9337616,100}, {88,112.94265}, {88,130}}},
71 {{{88.919838,120}, {107.058823,120}}}},
72 {{{{447.96701049804687, 894.4381103515625}, {448.007080078125, 894.4239501953125},
73 {448.0140380859375, 894.4215087890625}}},
74 {{{490.43548583984375, 879.40740966796875}, {405.59262084960937, 909.435546875}}}},
75 {{{{142.589081, 102.283646}, {149.821579, 100}, {158, 100}}},
76 {{{90, 230}, {160, 60}}}},
77 {{{{1101, 10}, {1101, 8.3431453704833984}, {1099.828857421875, 7.1711997985839844}}},
78 {{{1099.828857421875,7.1711711883544922}, {1099.121337890625,7.8786783218383789}}}},
79 {{{{973, 507}, {973, 508.24264526367187}, {972.12158203125, 509.12161254882812}}},
80 {{{930, 467}, {973, 510}}}},
81 {{{{369.848602, 145.680267}, {382.360413, 121.298294}, {406.207703, 121.298294}}},
82 {{{406.207703, 121.298294}, {348.781738, 123.864815}}}},
83};
84
86
88 bool flipped = false;
89 for (size_t index = 0; index < oneOffs_count; ++index) {
90 const QuadPts& q = oneOffs[index].quad;
91 SkDQuad quad;
92 quad.debugSet(q.fPts);
93 SkASSERT(ValidQuad(quad));
94 const SkDLine& line = oneOffs[index].line;
96 SkIntersections intersections;
97 int result = doIntersect(intersections, quad, line, flipped);
98 for (int inner = 0; inner < result; ++inner) {
99 double quadT = intersections[0][inner];
100 SkDPoint quadXY = quad.ptAtT(quadT);
101 double lineT = intersections[1][inner];
102 SkDPoint lineXY = line.ptAtT(lineT);
103 if (!quadXY.approximatelyEqual(lineXY)) {
104 quadXY.approximatelyEqual(lineXY);
105 }
107 }
108 }
109}
110
111DEF_TEST(PathOpsQuadLineIntersectionOneOff, reporter) {
113}
114
115DEF_TEST(PathOpsQuadLineIntersection, reporter) {
116 for (size_t index = 0; index < lineQuadTests_count; ++index) {
117 int iIndex = static_cast<int>(index);
118 const QuadPts& q = lineQuadTests[index].quad;
119 SkDQuad quad;
120 quad.debugSet(q.fPts);
121 SkASSERT(ValidQuad(quad));
122 const SkDLine& line = lineQuadTests[index].line;
124 SkReduceOrder reducer1, reducer2;
125 int order1 = reducer1.reduce(quad);
126 int order2 = reducer2.reduce(line);
127 if (order1 < 3) {
128 SkDebugf("%s [%d] quad order=%d\n", __FUNCTION__, iIndex, order1);
130 }
131 if (order2 < 2) {
132 SkDebugf("%s [%d] line order=%d\n", __FUNCTION__, iIndex, order2);
134 }
135 SkIntersections intersections;
136 bool flipped = false;
137 int result = doIntersect(intersections, quad, line, flipped);
139 if (intersections.used() <= 0) {
140 continue;
141 }
142 for (int pt = 0; pt < result; ++pt) {
143 double tt1 = intersections[0][pt];
144 REPORTER_ASSERT(reporter, tt1 >= 0 && tt1 <= 1);
145 SkDPoint t1 = quad.ptAtT(tt1);
146 double tt2 = intersections[1][pt];
147 REPORTER_ASSERT(reporter, tt2 >= 0 && tt2 <= 1);
148 SkDPoint t2 = line.ptAtT(tt2);
149 if (!t1.approximatelyEqual(t2)) {
150 SkDebugf("%s [%d,%d] x!= t1=%1.9g (%1.9g,%1.9g) t2=%1.9g (%1.9g,%1.9g)\n",
151 __FUNCTION__, iIndex, pt, tt1, t1.fX, t1.fY, tt2, t2.fX, t2.fY);
153 }
154 if (!t1.approximatelyEqual(lineQuadTests[index].expected[0])
155 && (lineQuadTests[index].result == 1
156 || !t1.approximatelyEqual(lineQuadTests[index].expected[1]))) {
157 SkDebugf("%s t1=(%1.9g,%1.9g)\n", __FUNCTION__, t1.fX, t1.fY);
159 }
160 }
161 }
162}
reporter
Definition: FontMgrTest.cpp:39
static void testOneOffs(skiatest::Reporter *reporter)
static struct oneLineQuad oneOffs[]
DEF_TEST(PathOpsQuadLineIntersectionOneOff, reporter)
static struct lineQuad lineQuadTests[]
static int doIntersect(SkIntersections &intersections, const SkDQuad &quad, const SkDLine &line, bool &flipped)
static size_t lineQuadTests_count
static size_t oneOffs_count
bool ValidLine(const SkDLine &line)
bool ValidQuad(const SkDQuad &quad)
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
int intersect(const SkDLine &, const SkDLine &)
int vertical(const SkDLine &, double top, double bottom, double x, bool flipped)
int used() const
int horizontal(const SkDLine &, double left, double right, double y, bool flipped)
GAsyncResult * result
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkDPoint fPts[kPointCount]
bool approximatelyEqual(const SkDPoint &a) const
void debugSet(const SkDPoint *pts)
SkDPoint ptAtT(double t) const
int reduce(const SkDCubic &cubic, Quadratics)