Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
PathOpsDVectorTest.cpp File Reference
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "src/pathops/SkPathOpsPoint.h"
#include "src/pathops/SkPathOpsTypes.h"
#include "tests/PathOpsTestCommon.h"
#include "tests/Test.h"
#include <array>
#include <cmath>
#include <cstddef>
#include <limits>

Go to the source code of this file.

Functions

 DEF_TEST (PathOpsDVector, reporter)
 
 DEF_TEST (SkDVector_normalize, reporter)
 
 DEF_TEST (SkDVector_normalize_infinity_and_nan, reporter)
 

Variables

static const SkDPoint tests []
 
static const size_t tests_count = std::size(tests)
 

Function Documentation

◆ DEF_TEST() [1/3]

DEF_TEST ( PathOpsDVector  ,
reporter   
)

Definition at line 32 of file PathOpsDVectorTest.cpp.

32 {
33 for (size_t index = 0; index < tests_count - 1; ++index) {
34 SkDVector v1 = tests[index + 1] - tests[index];
36 SkDVector v2 = tests[index] - tests[index + 1];
38 v1 += v2;
39 REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
40 v2 -= static_cast<decltype(v2)&>(v2);
41 REPORTER_ASSERT(reporter, v2.fX == 0 && v2.fY == 0);
42 v1 = tests[index + 1] - tests[index];
43 v1 /= 2;
44 v1 *= 2;
45 v1 -= tests[index + 1] - tests[index];
46 REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
47 SkVector sv = v1.asSkVector();
48 REPORTER_ASSERT(reporter, sv.fX == 0 && sv.fY == 0);
49 v1 = tests[index + 1] - tests[index];
50 double lenSq = v1.lengthSquared();
51 double v1Dot = v1.dot(v1);
52 REPORTER_ASSERT(reporter, lenSq == v1Dot);
54 double v1Cross = v1.cross(v1);
55 REPORTER_ASSERT(reporter, v1Cross == 0);
56 }
57}
reporter
static const size_t tests_count
static const SkDPoint tests[]
bool ValidVector(const SkDVector &v)
#define SkASSERT(cond)
Definition SkAssert.h:116
bool approximately_equal(double x, double y)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
Vec2Value v2
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition SkVx.h:706
double length() const
double cross(const SkDVector &a) const
SkVector asSkVector() const
double dot(const SkDVector &a) const
double lengthSquared() const
float fX
x-axis value
float fY
y-axis value

◆ DEF_TEST() [2/3]

DEF_TEST ( SkDVector_normalize  ,
reporter   
)

Definition at line 59 of file PathOpsDVectorTest.cpp.

59 {
60 // See also SkVx_normalize
61 auto assertDoublesEqual = [&](double left, double right) {
63 };
64 SkDVector first{1.2, 3.4};
65 first.normalize();
66 REPORTER_ASSERT(reporter, first.isFinite());
67 assertDoublesEqual(first.fX, 0.332820);
68 assertDoublesEqual(first.fY, 0.942990);
69
70 SkDVector second{2.3, -4.5};
71 second.normalize();
72 REPORTER_ASSERT(reporter, second.isFinite());
73 assertDoublesEqual(second.fX, 0.455111);
74 assertDoublesEqual(second.fY, -0.890435);
75}
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
SkDVector & normalize()

◆ DEF_TEST() [3/3]

DEF_TEST ( SkDVector_normalize_infinity_and_nan  ,
reporter   
)

Definition at line 77 of file PathOpsDVectorTest.cpp.

77 {
78 // See also SkVx_normalize_infinity_and_nan
79 SkDVector first{0, 0};
80 first.normalize();
81 REPORTER_ASSERT(reporter, !first.isFinite());
82 REPORTER_ASSERT(reporter, std::isnan(first.fX), "%f is not nan", first.fX);
83 REPORTER_ASSERT(reporter, std::isnan(first.fY), "%f is not nan", first.fY);
84
85 SkDVector second{std::numeric_limits<double>::max(),
86 std::numeric_limits<double>::max()};
87 second.normalize();
88 REPORTER_ASSERT(reporter, second.isFinite());
89 REPORTER_ASSERT(reporter, second.fX == 0, "%f != 0", second.fX);
90 REPORTER_ASSERT(reporter, second.fY == 0, "%f != 0", second.fY);
91}

Variable Documentation

◆ tests

const SkDPoint tests[]
static
Initial value:
= {
{0, 0},
{1, 0},
{0, 1},
{2, 1},
{1, 2},
{1, 1},
{2, 2}
}

Definition at line 20 of file PathOpsDVectorTest.cpp.

20 {
21 {0, 0},
22 {1, 0},
23 {0, 1},
24 {2, 1},
25 {1, 2},
26 {1, 1},
27 {2, 2}
28};

◆ tests_count

const size_t tests_count = std::size(tests)
static

Definition at line 30 of file PathOpsDVectorTest.cpp.