Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions | Variables
PathOpsConicIntersectionTest.cpp File Reference
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "src/core/SkGeometry.h"
#include "src/pathops/SkIntersections.h"
#include "src/pathops/SkPathOpsConic.h"
#include "src/pathops/SkPathOpsPoint.h"
#include "src/pathops/SkPathOpsQuad.h"
#include "src/pathops/SkPathOpsTypes.h"
#include "tests/PathOpsTestCommon.h"
#include "tests/Test.h"
#include <array>

Go to the source code of this file.

Macros

#define DEBUG_VISUALIZE_CONICS   0
 

Functions

static void chopCompare (const SkConic chopped[2], const SkDConic dChopped[2])
 
static void chopBothWays (const SkDConic &dConic, double t, const char *name)
 
static void oneOff (skiatest::Reporter *reporter, const ConicPts &conic1, const ConicPts &conic2, bool coin)
 
static void oneOff (skiatest::Reporter *reporter, int outer, int inner)
 
static void oneOffTests (skiatest::Reporter *reporter)
 
 DEF_TEST (PathOpsConicIntersectionOneOff, reporter)
 
 DEF_TEST (PathOpsConicIntersection, reporter)
 

Variables

static const ConicPts testSet []
 
const int testSetCount = (int) std::size(testSet)
 

Macro Definition Documentation

◆ DEBUG_VISUALIZE_CONICS

#define DEBUG_VISUALIZE_CONICS   0

Definition at line 72 of file PathOpsConicIntersectionTest.cpp.

Function Documentation

◆ chopBothWays()

static void chopBothWays ( const SkDConic dConic,
double  t,
const char *  name 
)
static

Definition at line 166 of file PathOpsConicIntersectionTest.cpp.

166 {
168 for (int index = 0; index < 3; ++index) {
169 conic.fPts[index] = dConic.fPts[index].asSkPoint();
170 }
171 conic.fW = dConic.fWeight;
172 SkConic chopped[2];
173 SkDConic dChopped[2];
174 if (!conic.chopAt(SkDoubleToScalar(t), chopped)) {
175 return;
176 }
177 dChopped[0] = dConic.subDivide(0, t);
178 dChopped[1] = dConic.subDivide(t, 1);
179#if DEBUG_VISUALIZE_CONICS
180 dConic.dump();
181#endif
182 chopCompare(chopped, dChopped);
183#if DEBUG_VISUALIZE_CONICS
184 writePng(conic, chopped, name);
185#endif
186}
static void chopCompare(const SkConic chopped[2], const SkDConic dChopped[2])
#define SkDoubleToScalar(x)
Definition SkScalar.h:64
const char * name
Definition fuchsia.cc:50
AI float conic(float tolerance, const SkPoint pts[], float w, const VectorXform &vectorXform=VectorXform())
void dump() const
SkDQuad fPts
SkDConic subDivide(double t1, double t2) const
SkScalar fWeight

◆ chopCompare()

static void chopCompare ( const SkConic  chopped[2],
const SkDConic  dChopped[2] 
)
static

Definition at line 56 of file PathOpsConicIntersectionTest.cpp.

56 {
57 SkASSERT(roughly_equal(chopped[0].fW, dChopped[0].fWeight));
58 SkASSERT(roughly_equal(chopped[1].fW, dChopped[1].fWeight));
59 for (int cIndex = 0; cIndex < 2; ++cIndex) {
60 for (int pIndex = 0; pIndex < 3; ++pIndex) {
61 SkDPoint up;
62 up.set(chopped[cIndex].fPts[pIndex]);
63 SkASSERT(dChopped[cIndex].fPts[pIndex].approximatelyEqual(up));
64 }
65 }
66#if DEBUG_VISUALIZE_CONICS
67 dChopped[0].dump();
68 dChopped[1].dump();
69#endif
70}
SkPoint fPts[2]
#define SkASSERT(cond)
Definition SkAssert.h:116
bool roughly_equal(double x, double y)
void set(const SkPoint &pt)

◆ DEF_TEST() [1/2]

DEF_TEST ( PathOpsConicIntersection  ,
reporter   
)

Definition at line 356 of file PathOpsConicIntersectionTest.cpp.

356 {
358}
reporter
static void oneOffTests(skiatest::Reporter *reporter)

◆ DEF_TEST() [2/2]

DEF_TEST ( PathOpsConicIntersectionOneOff  ,
reporter   
)

Definition at line 352 of file PathOpsConicIntersectionTest.cpp.

352 {
353 oneOff(reporter, 0, 1);
354}
static void oneOff(skiatest::Reporter *reporter, const ConicPts &conic1, const ConicPts &conic2, bool coin)

◆ oneOff() [1/2]

static void oneOff ( skiatest::Reporter reporter,
const ConicPts conic1,
const ConicPts conic2,
bool  coin 
)
static

Definition at line 304 of file PathOpsConicIntersectionTest.cpp.

305 {
306#if DEBUG_VISUALIZE_CONICS
307 writeFrames();
308#endif
309 SkDConic c1, c2;
310 c1.debugSet(conic1.fPts.fPts, conic1.fWeight);
311 c2.debugSet(conic2.fPts.fPts, conic2.fWeight);
312 chopBothWays(c1, 0.5, "c1");
313 chopBothWays(c2, 0.5, "c2");
314#if DEBUG_VISUALIZE_CONICS
315 writeDPng(c1, "d1");
316 writeDPng(c2, "d2");
317#endif
318 SkASSERT(ValidConic(c1));
319 SkASSERT(ValidConic(c2));
320 SkIntersections intersections;
321 intersections.intersect(c1, c2);
322 REPORTER_ASSERT(reporter, !coin || intersections.used() == 2);
323 double tt1, tt2;
324 SkDPoint xy1, xy2;
325 for (int pt3 = 0; pt3 < intersections.used(); ++pt3) {
326 tt1 = intersections[0][pt3];
327 xy1 = c1.ptAtT(tt1);
328 tt2 = intersections[1][pt3];
329 xy2 = c2.ptAtT(tt2);
330 const SkDPoint& iPt = intersections.pt(pt3);
334 }
335 reporter->bumpTestCount();
336}
static void chopBothWays(const SkDConic &dConic, double t, const char *name)
bool ValidConic(const SkDConic &conic)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
int intersect(const SkDLine &, const SkDLine &)
const SkDPoint & pt(int index) const
SkScalar fWeight
SkDPoint fPts[kPointCount]
SkDPoint ptAtT(double t) const
void debugSet(const SkDPoint *pts, SkScalar weight)
bool approximatelyEqual(const SkDPoint &a) const

◆ oneOff() [2/2]

static void oneOff ( skiatest::Reporter reporter,
int  outer,
int  inner 
)
static

Definition at line 338 of file PathOpsConicIntersectionTest.cpp.

338 {
339 const ConicPts& c1 = testSet[outer];
340 const ConicPts& c2 = testSet[inner];
341 oneOff(reporter, c1, c2, false);
342}
static const ConicPts testSet[]

◆ oneOffTests()

static void oneOffTests ( skiatest::Reporter reporter)
static

Definition at line 344 of file PathOpsConicIntersectionTest.cpp.

344 {
345 for (int outer = 0; outer < testSetCount - 1; ++outer) {
346 for (int inner = outer + 1; inner < testSetCount; ++inner) {
347 oneOff(reporter, outer, inner);
348 }
349 }
350}
const int testSetCount

Variable Documentation

◆ testSet

const ConicPts testSet[]
static
Initial value:
= {
{{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
{{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
{{{{5.1114602088928223, 628.77813720703125},
{10.834027290344238, 988.964111328125},
{163.40835571289062, 988.964111328125}}}, 0.72944212f},
{{{{163.40835571289062, 988.964111328125},
{5, 988.964111328125},
{5, 614.7423095703125}}}, 0.707106769f},
{{{{11.17222976684570312, -8.103978157043457031},
{22.91432571411132812, -10.37866020202636719},
{23.7764129638671875, -7.725424289703369141}}}, 1.00862849f},
{{{{-1.545085430145263672, -4.755282402038574219},
{22.23132705688476562, -12.48070907592773438},
{23.7764129638671875, -7.725427150726318359}}}, 0.707106769f},
{{{{-4,1}, {-4,5}, {0,5}}}, 0.707106769f},
{{{{-3,4}, {-3,1}, {0,1}}}, 0.707106769f},
{{{{0, 0}, {0, 1}, {1, 1}}}, 0.5f},
{{{{1, 0}, {0, 0}, {0, 1}}}, 0.5f},
}

Definition at line 28 of file PathOpsConicIntersectionTest.cpp.

28 {
29 {{{{306.588013,-227.983994}, {212.464996,-262.242004}, {95.5512009,58.9763985}}}, 0.707107008f},
30 {{{{377.218994,-141.981003}, {40.578701,-201.339996}, {23.1854992,-102.697998}}}, 0.707107008f},
31
32 {{{{5.1114602088928223, 628.77813720703125},
33 {10.834027290344238, 988.964111328125},
34 {163.40835571289062, 988.964111328125}}}, 0.72944212f},
35 {{{{163.40835571289062, 988.964111328125},
36 {5, 988.964111328125},
37 {5, 614.7423095703125}}}, 0.707106769f},
38
39 {{{{11.17222976684570312, -8.103978157043457031},
40 {22.91432571411132812, -10.37866020202636719},
41 {23.7764129638671875, -7.725424289703369141}}}, 1.00862849f},
42 {{{{-1.545085430145263672, -4.755282402038574219},
43 {22.23132705688476562, -12.48070907592773438},
44 {23.7764129638671875, -7.725427150726318359}}}, 0.707106769f},
45
46 {{{{-4,1}, {-4,5}, {0,5}}}, 0.707106769f},
47 {{{{-3,4}, {-3,1}, {0,1}}}, 0.707106769f},
48
49 {{{{0, 0}, {0, 1}, {1, 1}}}, 0.5f},
50 {{{{1, 0}, {0, 0}, {0, 1}}}, 0.5f},
51
52};

◆ testSetCount

const int testSetCount = (int) std::size(testSet)

Definition at line 54 of file PathOpsConicIntersectionTest.cpp.