Flutter Engine
The Flutter Engine
Functions | Variables
PathOpsDCubicTest.cpp File Reference
#include "include/core/SkSpan.h"
#include "include/private/base/SkFloatingPoint.h"
#include "src/pathops/SkPathOpsCubic.h"
#include "src/pathops/SkPathOpsPoint.h"
#include "tests/PathOpsTestCommon.h"
#include "tests/Test.h"
#include <string>
#include <cstddef>

Go to the source code of this file.

Functions

 DEF_TEST (PathOpsCubicHull, reporter)
 
static bool nearly_equal (double expected, double actual)
 
static void testConvertToPolynomial (skiatest::Reporter *reporter, const std::string &name, SkSpan< const SkDPoint > curveInputs, bool yValues, double expectedA, double expectedB, double expectedC, double expectedD)
 
 DEF_TEST (SkDCubicPolynomialCoefficients, reporter)
 

Variables

static const CubicPts hullTests []
 
static const size_t hullTests_count = std::size(hullTests)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( PathOpsCubicHull  ,
reporter   
)

Definition at line 23 of file PathOpsDCubicTest.cpp.

23 {
24 for (size_t index = 0; index < hullTests_count; ++index) {
25 const CubicPts& c = hullTests[index];
27 cubic.debugSet(c.fPts);
28 char order[4];
29 cubic.convexHull(order);
30 }
31}
static const size_t hullTests_count
static const CubicPts hullTests[]
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:195
SkDPoint fPts[kPointCount]

◆ DEF_TEST() [2/2]

DEF_TEST ( SkDCubicPolynomialCoefficients  ,
reporter   
)

Definition at line 61 of file PathOpsDCubicTest.cpp.

61 {
62 testConvertToPolynomial(reporter, "Arbitrary control points X direction",
63 {{1, 2}, {-3, 4}, {5, -6}, {7, 8}}, false, /*=yValues*/
64 -18, 36, -12, 1
65 );
66 testConvertToPolynomial(reporter, "Arbitrary control points Y direction",
67 {{1, 2}, {-3, 4}, {5, -6}, {7, 8}}, true, /*=yValues*/
68 36, -36, 6, 2
69 );
70}
reporter
Definition: FontMgrTest.cpp:39
static void testConvertToPolynomial(skiatest::Reporter *reporter, const std::string &name, SkSpan< const SkDPoint > curveInputs, bool yValues, double expectedA, double expectedB, double expectedC, double expectedD)

◆ nearly_equal()

static bool nearly_equal ( double  expected,
double  actual 
)
static

Definition at line 33 of file PathOpsDCubicTest.cpp.

33 {
34 if (sk_double_nearly_zero(expected)) {
35 return sk_double_nearly_zero(actual);
36 }
37 return sk_doubles_nearly_equal_ulps(expected, actual, 64);
38}
bool sk_double_nearly_zero(double a)
bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t maxUlpsDiff=16)

◆ testConvertToPolynomial()

static void testConvertToPolynomial ( skiatest::Reporter reporter,
const std::string &  name,
SkSpan< const SkDPoint curveInputs,
bool  yValues,
double  expectedA,
double  expectedB,
double  expectedC,
double  expectedD 
)
static

Definition at line 40 of file PathOpsDCubicTest.cpp.

43 {
45 REPORTER_ASSERT(reporter, curveInputs.size() == 4,
46 "Invalid test case. Need 4 points (start, control, control, end)");
47
48 const double* input = &curveInputs[0].fX;
49 if (yValues) {
50 input = &curveInputs[0].fY;
51 }
52 double A, B, C, D;
53 SkDCubic::Coefficients(input, &A, &B, &C, &D);
54
55 REPORTER_ASSERT(reporter, nearly_equal(expectedA, A), "%f != %f", expectedA, A);
56 REPORTER_ASSERT(reporter, nearly_equal(expectedB, B), "%f != %f", expectedB, B);
57 REPORTER_ASSERT(reporter, nearly_equal(expectedC, C), "%f != %f", expectedC, C);
58 REPORTER_ASSERT(reporter, nearly_equal(expectedD, D), "%f != %f", expectedD, D);
59}
static bool nearly_equal(double expected, double actual)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
constexpr size_t size() const
Definition: SkSpan_impl.h:95
#define C(TEST_CATEGORY)
Definition: colrv1.cpp:248
#define B
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
static void Coefficients(const double *cubic, double *A, double *B, double *C, double *D)

Variable Documentation

◆ hullTests

const CubicPts hullTests[]
static
Initial value:
= {
{{{2.6250000819563866, 2.3750000223517418}, {2.833333432674408, 2.3333333432674408}, {3.1111112236976624, 2.3333333134651184}, {3.4074075222015381, 2.3333332538604736}}},
}

Definition at line 17 of file PathOpsDCubicTest.cpp.

◆ hullTests_count

const size_t hullTests_count = std::size(hullTests)
static

Definition at line 21 of file PathOpsDCubicTest.cpp.