Flutter Engine
The Flutter Engine
Classes | Functions | Variables
PathOpsQuadLineIntersectionTest.cpp File Reference
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "src/pathops/SkIntersections.h"
#include "src/pathops/SkPathOpsLine.h"
#include "src/pathops/SkPathOpsPoint.h"
#include "src/pathops/SkPathOpsQuad.h"
#include "src/pathops/SkReduceOrder.h"
#include "tests/PathOpsTestCommon.h"
#include "tests/Test.h"
#include <array>
#include <cstddef>
#include <utility>

Go to the source code of this file.

Classes

struct  lineQuad
 
struct  oneLineQuad
 

Functions

static int doIntersect (SkIntersections &intersections, const SkDQuad &quad, const SkDLine &line, bool &flipped)
 
static void testOneOffs (skiatest::Reporter *reporter)
 
 DEF_TEST (PathOpsQuadLineIntersectionOneOff, reporter)
 
 DEF_TEST (PathOpsQuadLineIntersection, reporter)
 

Variables

static struct lineQuad lineQuadTests []
 
static size_t lineQuadTests_count = std::size(lineQuadTests)
 
static struct oneLineQuad oneOffs []
 
static size_t oneOffs_count = std::size(oneOffs)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( PathOpsQuadLineIntersection  ,
reporter   
)

Definition at line 115 of file PathOpsQuadLineIntersectionTest.cpp.

115 {
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 struct lineQuad lineQuadTests[]
static int doIntersect(SkIntersections &intersections, const SkDQuad &quad, const SkDLine &line, bool &flipped)
static size_t lineQuadTests_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
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
int used() const
GAsyncResult * result
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)

◆ DEF_TEST() [2/2]

DEF_TEST ( PathOpsQuadLineIntersectionOneOff  ,
reporter   
)

Definition at line 111 of file PathOpsQuadLineIntersectionTest.cpp.

111 {
113}
static void testOneOffs(skiatest::Reporter *reporter)

◆ doIntersect()

static int doIntersect ( SkIntersections intersections,
const SkDQuad quad,
const SkDLine line,
bool &  flipped 
)
static

Definition at line 37 of file PathOpsQuadLineIntersectionTest.cpp.

38 {
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}
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
int intersect(const SkDLine &, const SkDLine &)
int vertical(const SkDLine &, double top, double bottom, double x, bool flipped)
int horizontal(const SkDLine &, double left, double right, double y, bool flipped)

◆ testOneOffs()

static void testOneOffs ( skiatest::Reporter reporter)
static

Definition at line 87 of file PathOpsQuadLineIntersectionTest.cpp.

87 {
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}
static struct oneLineQuad oneOffs[]
static size_t oneOffs_count

Variable Documentation

◆ lineQuadTests

struct lineQuad lineQuadTests[]
static
Initial value:
= {
{{{{1, 1}, {2, 1}, {0, 2}}}, {{{0, 0}, {1, 1}}}, 1, {{1, 1}, {0, 0}} },
{{{{0, 0}, {1, 1}, {3, 1}}}, {{{0, 0}, {3, 1}}}, 2, {{0, 0}, {3, 1}} },
{{{{2, 0}, {1, 1}, {2, 2}}}, {{{0, 0}, {0, 2}}}, 0, {{0, 0}, {0, 0}} },
{{{{4, 0}, {0, 1}, {4, 2}}}, {{{3, 1}, {4, 1}}}, 0, {{0, 0}, {0, 0}} },
{{{{0, 0}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}, 1, {{.25, .75}, {0, 0}} },
}

◆ lineQuadTests_count

size_t lineQuadTests_count = std::size(lineQuadTests)
static

Definition at line 35 of file PathOpsQuadLineIntersectionTest.cpp.

◆ oneOffs

struct oneLineQuad oneOffs[]
static
Initial value:
= {
{{{{97.9337616,100}, {88,112.94265}, {88,130}}},
{{{88.919838,120}, {107.058823,120}}}},
{{{{447.96701049804687, 894.4381103515625}, {448.007080078125, 894.4239501953125},
{448.0140380859375, 894.4215087890625}}},
{{{490.43548583984375, 879.40740966796875}, {405.59262084960937, 909.435546875}}}},
{{{{142.589081, 102.283646}, {149.821579, 100}, {158, 100}}},
{{{90, 230}, {160, 60}}}},
{{{{1101, 10}, {1101, 8.3431453704833984}, {1099.828857421875, 7.1711997985839844}}},
{{{1099.828857421875,7.1711711883544922}, {1099.121337890625,7.8786783218383789}}}},
{{{{973, 507}, {973, 508.24264526367187}, {972.12158203125, 509.12161254882812}}},
{{{930, 467}, {973, 510}}}},
{{{{369.848602, 145.680267}, {382.360413, 121.298294}, {406.207703, 121.298294}}},
{{{406.207703, 121.298294}, {348.781738, 123.864815}}}},
}

◆ oneOffs_count

size_t oneOffs_count = std::size(oneOffs)
static

Definition at line 85 of file PathOpsQuadLineIntersectionTest.cpp.