Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
PathOpsConicLineIntersectionTest.cpp File Reference
#include "include/core/SkPath.h"
#include "include/core/SkPoint.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "src/core/SkGeometry.h"
#include "src/pathops/SkIntersections.h"
#include "src/pathops/SkPathOpsConic.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  lineConic
 
struct  oneLineConic
 

Functions

static int doIntersect (SkIntersections &intersections, const SkDConic &conic, const SkDLine &line, bool &flipped)
 
static void testOneOffs (skiatest::Reporter *reporter)
 
 DEF_TEST (PathOpsConicLineIntersectionOneOff, reporter)
 
 DEF_TEST (PathOpsConicLineIntersection, reporter)
 

Variables

static struct lineConic lineConicTests []
 
static size_t lineConicTests_count = std::size(lineConicTests)
 
static struct oneLineConic oneOffs []
 
static size_t oneOffs_count = std::size(oneOffs)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( PathOpsConicLineIntersection  ,
reporter   
)

Definition at line 108 of file PathOpsConicLineIntersectionTest.cpp.

108 {
109 for (size_t index = 0; index < lineConicTests_count; ++index) {
110 int iIndex = static_cast<int>(index);
111 const ConicPts& c = lineConicTests[index].conic;
113 conic.debugSet(c.fPts.fPts, c.fWeight);
114 SkASSERT(ValidConic(conic));
115 const SkDLine& line = lineConicTests[index].line;
116 SkASSERT(ValidLine(line));
117 SkReduceOrder reducer;
118 SkPoint pts[3] = { conic.fPts.fPts[0].asSkPoint(), conic.fPts.fPts[1].asSkPoint(),
119 conic.fPts.fPts[2].asSkPoint() };
120 SkPoint reduced[3];
121 SkConic floatConic;
122 floatConic.set(pts, conic.fWeight);
123 SkPath::Verb order1 = SkReduceOrder::Conic(floatConic, reduced);
124 if (order1 != SkPath::kConic_Verb) {
125 SkDebugf("%s [%d] conic verb=%d\n", __FUNCTION__, iIndex, order1);
127 }
128 int order2 = reducer.reduce(line);
129 if (order2 < 2) {
130 SkDebugf("%s [%d] line order=%d\n", __FUNCTION__, iIndex, order2);
132 }
133 SkIntersections intersections;
134 bool flipped = false;
135 int result = doIntersect(intersections, conic, line, flipped);
137 if (intersections.used() <= 0) {
138 continue;
139 }
140 for (int pt = 0; pt < result; ++pt) {
141 double tt1 = intersections[0][pt];
142 REPORTER_ASSERT(reporter, tt1 >= 0 && tt1 <= 1);
143 SkDPoint t1 = conic.ptAtT(tt1);
144 double tt2 = intersections[1][pt];
145 REPORTER_ASSERT(reporter, tt2 >= 0 && tt2 <= 1);
146 SkDPoint t2 = line.ptAtT(tt2);
147 if (!t1.approximatelyEqual(t2)) {
148 SkDebugf("%s [%d,%d] x!= t1=%1.9g (%1.9g,%1.9g) t2=%1.9g (%1.9g,%1.9g)\n",
149 __FUNCTION__, iIndex, pt, tt1, t1.fX, t1.fY, tt2, t2.fX, t2.fY);
151 }
153 && (lineConicTests[index].result == 1
154 || !t1.approximatelyEqual(lineConicTests[index].expected[1]))) {
155 SkDebugf("%s t1=(%1.9g,%1.9g)\n", __FUNCTION__, t1.fX, t1.fY);
157 }
158 }
159 }
160}
reporter
static size_t lineConicTests_count
static struct lineConic lineConicTests[]
static int doIntersect(SkIntersections &intersections, const SkDConic &conic, const SkDLine &line, bool &flipped)
bool ValidConic(const SkDConic &conic)
bool ValidLine(const SkDLine &line)
#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
@ kConic_Verb
Definition SkPath.h:1461
GAsyncResult * result
AI float conic(float tolerance, const SkPoint pts[], float w, const VectorXform &vectorXform=VectorXform())
SkScalar fWeight
SkDPoint fPts[kPointCount]
void set(const SkPoint pts[3], SkScalar w)
Definition SkGeometry.h:339
bool approximatelyEqual(const SkDPoint &a) const
static SkPath::Verb Conic(const SkConic &conic, SkPoint *reducePts)
int reduce(const SkDCubic &cubic, Quadratics)

◆ DEF_TEST() [2/2]

DEF_TEST ( PathOpsConicLineIntersectionOneOff  ,
reporter   
)

Definition at line 104 of file PathOpsConicLineIntersectionTest.cpp.

104 {
106}
static void testOneOffs(skiatest::Reporter *reporter)

◆ doIntersect()

static int doIntersect ( SkIntersections intersections,
const SkDConic conic,
const SkDLine line,
bool &  flipped 
)
static

Definition at line 41 of file PathOpsConicLineIntersectionTest.cpp.

42 {
43 int result;
44 flipped = false;
45 if (line[0].fX == line[1].fX) {
46 double top = line[0].fY;
47 double bottom = line[1].fY;
48 flipped = top > bottom;
49 if (flipped) {
50 using std::swap;
51 swap(top, bottom);
52 }
53 result = intersections.vertical(conic, top, bottom, line[0].fX, flipped);
54 } else if (line[0].fY == line[1].fY) {
55 double left = line[0].fX;
56 double right = line[1].fX;
57 flipped = left > right;
58 if (flipped) {
59 using std::swap;
60 swap(left, right);
61 }
62 result = intersections.horizontal(conic, left, right, line[0].fY, flipped);
63 } else {
64 intersections.intersect(conic, line);
65 result = intersections.used();
66 }
67 return result;
68}
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 80 of file PathOpsConicLineIntersectionTest.cpp.

80 {
81 bool flipped = false;
82 for (size_t index = 0; index < oneOffs_count; ++index) {
83 const ConicPts& c = oneOffs[index].conic;
85 conic.debugSet(c.fPts.fPts, c.fWeight);
86 SkASSERT(ValidConic(conic));
87 const SkDLine& line = oneOffs[index].line;
88 SkASSERT(ValidLine(line));
89 SkIntersections intersections;
90 int result = doIntersect(intersections, conic, line, flipped);
91 for (int inner = 0; inner < result; ++inner) {
92 double conicT = intersections[0][inner];
93 SkDPoint conicXY = conic.ptAtT(conicT);
94 double lineT = intersections[1][inner];
95 SkDPoint lineXY = line.ptAtT(lineT);
96 if (!conicXY.approximatelyEqual(lineXY)) {
97 conicXY.approximatelyEqual(lineXY);
98 }
100 }
101 }
102}
static struct oneLineConic oneOffs[]
static size_t oneOffs_count

Variable Documentation

◆ lineConicTests

struct lineConic lineConicTests[]
static
Initial value:
= {
{
{{{{30.6499996,25.6499996}, {30.6499996,20.6499996}, {25.6499996,20.6499996}}}, 0.707107008f},
{{{25.6499996,20.6499996}, {45.6500015,20.6499996}}},
1,
{{25.6499996,20.6499996}, {0,0}}
},
}

◆ lineConicTests_count

size_t lineConicTests_count = std::size(lineConicTests)
static

Definition at line 39 of file PathOpsConicLineIntersectionTest.cpp.

◆ oneOffs

struct oneLineConic oneOffs[]
static
Initial value:
= {
{{{{{30.6499996,25.6499996}, {30.6499996,20.6499996}, {25.6499996,20.6499996}}}, 0.707107008f},
{{{25.6499996,20.6499996}, {45.6500015,20.6499996}}}}
}

◆ oneOffs_count

size_t oneOffs_count = std::size(oneOffs)
static

Definition at line 78 of file PathOpsConicLineIntersectionTest.cpp.