Flutter Engine
The Flutter Engine
PathOpsDCubicTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
12#include "tests/Test.h"
13
14#include <string>
15#include <cstddef>
16
17static const CubicPts hullTests[] = {
18{{{2.6250000819563866, 2.3750000223517418}, {2.833333432674408, 2.3333333432674408}, {3.1111112236976624, 2.3333333134651184}, {3.4074075222015381, 2.3333332538604736}}},
19};
20
21static const size_t hullTests_count = std::size(hullTests);
22
23DEF_TEST(PathOpsCubicHull, reporter) {
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}
32
33static bool nearly_equal(double expected, double actual) {
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}
39
41 SkSpan<const SkDPoint> curveInputs, bool yValues,
42 double expectedA, double expectedB,
43 double expectedC, double expectedD) {
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}
60
61DEF_TEST(SkDCubicPolynomialCoefficients, reporter) {
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
DEF_TEST(PathOpsCubicHull, reporter)
static const size_t hullTests_count
static bool nearly_equal(double expected, double actual)
static const CubicPts hullTests[]
static void testConvertToPolynomial(skiatest::Reporter *reporter, const std::string &name, SkSpan< const SkDPoint > curveInputs, bool yValues, double expectedA, double expectedB, double expectedC, double expectedD)
bool sk_double_nearly_zero(double a)
bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t maxUlpsDiff=16)
#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
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:195
SkDPoint fPts[kPointCount]
static void Coefficients(const double *cubic, double *A, double *B, double *C, double *D)