Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
SkGaussFilterTest.cpp File Reference
#include "src/core/SkGaussFilter.h"
#include "tests/Test.h"
#include <cmath>
#include <cstdlib>
#include <initializer_list>
#include <tuple>
#include <vector>

Go to the source code of this file.

Functions

static double careful_add (int n, double *gauss)
 
 DEF_TEST (SkGaussFilterCommon, r)
 
 DEF_TEST (SkGaussFilterSweep, r)
 

Variables

static constexpr double kEpsilon = 0.000001
 

Function Documentation

◆ careful_add()

static double careful_add ( int  n,
double *  gauss 
)
static

Definition at line 20 of file SkGaussFilterTest.cpp.

20 {
21 // Sum smallest to largest to retain precision.
22 double sum = 0;
23 for (int i = n - 1; i >= 1; i--) {
24 sum += 2.0 * gauss[i];
25 }
26 sum += gauss[0];
27 return sum;
28}

◆ DEF_TEST() [1/2]

DEF_TEST ( SkGaussFilterCommon  ,
 
)

Definition at line 30 of file SkGaussFilterTest.cpp.

30 {
31 using Test = std::tuple<double, std::vector<double>>;
32
33 auto golden_check = [&](const Test& test) {
34 double sigma; std::vector<double> golden;
35 std::tie(sigma, golden) = test;
36 SkGaussFilter filter{sigma};
38 int n = 0;
39 for (auto d : filter) {
40 result[n++] = d;
41 }
42 REPORTER_ASSERT(r, static_cast<size_t>(n) == golden.size());
43 double sum = careful_add(n, result);
44 REPORTER_ASSERT(r, sum == 1.0);
45 for (size_t i = 0; i < golden.size(); i++) {
46 REPORTER_ASSERT(r, std::abs(golden[i] - result[i]) < kEpsilon);
47 }
48 };
49
50 // The following two sigmas account for about 85% of all sigmas used for masks.
51 // Golden values generated using Mathematica.
52 auto tests = {
53 // GaussianMatrix[{{Automatic}, {.788675}}]
54 Test{0.788675, {0.593605, 0.176225, 0.0269721}},
55
56 // GaussianMatrix[{{4}, {1.07735}}, Method -> "Bessel"]
57 Test{1.07735, {0.429537, 0.214955, 0.059143, 0.0111337}},
58 };
59
60 for (auto& test : tests) {
61 golden_check(test);
62 }
63}
static BlurTest tests[]
Definition BlurTest.cpp:84
#define test(name)
static constexpr double kEpsilon
static double careful_add(int n, double *gauss)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static constexpr int kGaussArrayMax
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
GAsyncResult * result

◆ DEF_TEST() [2/2]

DEF_TEST ( SkGaussFilterSweep  ,
 
)

Definition at line 65 of file SkGaussFilterTest.cpp.

65 {
66 // The double just before 2.0.
67 const double maxSigma = nextafter(2.0, 0.0);
68 auto check = [&](double sigma) {
69 SkGaussFilter filter{sigma};
71 int n = 0;
72 for (auto d : filter) {
73 result[n++] = d;
74 }
76 double sum = careful_add(n, result);
77 REPORTER_ASSERT(r, sum == 1.0);
78 };
79
80 for (double sigma = 0.0; sigma < 2.0; sigma += 0.1) {
81 check(sigma);
82 }
83 check(maxSigma);
84}
#define check(reporter, ref, unref, make, kill)

Variable Documentation

◆ kEpsilon

constexpr double kEpsilon = 0.000001
staticconstexpr

Definition at line 18 of file SkGaussFilterTest.cpp.