Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
CubicMapTest.cpp File Reference
#include "include/core/SkCubicMap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "src/base/SkCubics.h"
#include "src/base/SkVx.h"
#include "src/core/SkGeometry.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

static float accurate_t (float A, float B, float C, float D)
 
static float accurate_solve (SkPoint p1, SkPoint p2, SkScalar x)
 
static bool nearly_le (SkScalar a, SkScalar b)
 
static void exercise_cubicmap (SkPoint p1, SkPoint p2, skiatest::Reporter *reporter)
 
 DEF_TEST (CubicMap, r)
 

Function Documentation

◆ accurate_solve()

static float accurate_solve ( SkPoint  p1,
SkPoint  p2,
SkScalar  x 
)
static

Definition at line 25 of file CubicMapTest.cpp.

25 {
26 SkPoint array[] = { {0, 0}, p1, p2, {1,1} };
27 SkCubicCoeff coeff(array);
28
29 float t = accurate_t(coeff.fA[0], coeff.fB[0], coeff.fC[0], coeff.fD[0] - x);
30 SkASSERT(t >= 0 && t <= 1);
31 float y = coeff.eval(t)[1];
32 SkASSERT(y >= 0 && y <= 1.0001f);
33 return y;
34}
static float accurate_t(float A, float B, float C, float D)
#define SkASSERT(cond)
Definition SkAssert.h:116
double y
double x

◆ accurate_t()

static float accurate_t ( float  A,
float  B,
float  C,
float  D 
)
static

Definition at line 18 of file CubicMapTest.cpp.

18 {
19 double roots[3];
20 SkDEBUGCODE(int count =) SkCubics::RootsValidT(A, B, C, D, roots);
21 SkASSERT(count == 1);
22 return (float)roots[0];
23}
int count
#define SkDEBUGCODE(...)
Definition SkDebug.h:23

◆ DEF_TEST()

DEF_TEST ( CubicMap  ,
 
)

Definition at line 63 of file CubicMapTest.cpp.

63 {
64 const SkScalar values[] = {
65 0, 1, 0.5f, 0.0000001f, 0.999999f,
66 };
67
68 for (SkScalar x0 : values) {
69 for (SkScalar y0 : values) {
70 for (SkScalar x1 : values) {
71 for (SkScalar y1 : values) {
72 exercise_cubicmap({ x0, y0 }, { x1, y1 }, r);
73 }
74 }
75 }
76 }
77}
static void exercise_cubicmap(SkPoint p1, SkPoint p2, skiatest::Reporter *reporter)
float SkScalar
Definition extension.cpp:12

◆ exercise_cubicmap()

static void exercise_cubicmap ( SkPoint  p1,
SkPoint  p2,
skiatest::Reporter reporter 
)
static

Definition at line 40 of file CubicMapTest.cpp.

40 {
41 const SkScalar MAX_SOLVER_ERR = 0.008f; // found by running w/ current impl
42
43 SkCubicMap cmap(p1, p2);
44
45 SkScalar prev_y = 0;
46 SkScalar dx = 1.0f / 512;
47 for (SkScalar x = dx; x < 1; x += dx) {
48 SkScalar y = cmap.computeYFromX(x);
49 // are we valid and (mostly) monotonic?
50 if (!nearly_le(prev_y, y)) {
51 cmap.computeYFromX(x);
53 }
54 prev_y = y;
55
56 // are we close to the "correct" answer?
57 SkScalar yy = accurate_solve(p1, p2, x);
58 SkScalar diff = SkScalarAbs(yy - y);
59 REPORTER_ASSERT(reporter, diff < MAX_SOLVER_ERR);
60 }
61}
static bool nearly_le(SkScalar a, SkScalar b)
static float accurate_solve(SkPoint p1, SkPoint p2, SkScalar x)
reporter
#define SkScalarAbs(x)
Definition SkScalar.h:39
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition SkRecords.h:208

◆ nearly_le()

static bool nearly_le ( SkScalar  a,
SkScalar  b 
)
static

Definition at line 36 of file CubicMapTest.cpp.

36 {
37 return a <= b || SkScalarNearlyZero(a - b);
38}
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
static bool b
struct MyStruct a[10]