Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
Point3Test.cpp File Reference
#include "include/core/SkPoint3.h"
#include "include/core/SkScalar.h"
#include "src/base/SkRandom.h"
#include "tests/Test.h"
#include <array>
#include <cstddef>

Go to the source code of this file.

Functions

static void test_eq_ops (skiatest::Reporter *reporter)
 
static void test_ops (skiatest::Reporter *reporter)
 
static void test_dot (skiatest::Reporter *reporter)
 
static void test_length (skiatest::Reporter *reporter, SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen)
 
static void test_normalize (skiatest::Reporter *reporter, SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen)
 
 DEF_TEST (Point3, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( Point3  ,
reporter   
)

Definition at line 126 of file Point3Test.cpp.

126 {
130
131 static const struct {
132 SkScalar fX;
133 SkScalar fY;
134 SkScalar fZ;
135 SkScalar fLength;
136 } gRec[] = {
137 { 0.0f, 0.0f, 0.0f, 0.0f },
138 { 0.3f, 0.4f, 0.5f, SK_ScalarRoot2Over2 },
139 { 1.0e-37f, 1.0e-37f, 1.0e-37f, 0.0f }, // underflows
140 { 3.4e38f, 0.0f, 0.0f, 3.4e38f } // overflows
141 };
142
143 for (size_t i = 0; i < std::size(gRec); ++i) {
144 test_length(reporter, gRec[i].fX, gRec[i].fY, gRec[i].fZ, gRec[i].fLength);
145 test_normalize(reporter, gRec[i].fX, gRec[i].fY, gRec[i].fZ, gRec[i].fLength);
146 }
147}
static const struct @223 gRec[]
reporter
static void test_ops(skiatest::Reporter *reporter)
static void test_dot(skiatest::Reporter *reporter)
static void test_eq_ops(skiatest::Reporter *reporter)
static void test_length(skiatest::Reporter *reporter, SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen)
static void test_normalize(skiatest::Reporter *reporter, SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen)
#define SK_ScalarRoot2Over2
Definition SkScalar.h:23
float SkScalar
Definition extension.cpp:12

◆ test_dot()

static void test_dot ( skiatest::Reporter reporter)
static

Definition at line 55 of file Point3Test.cpp.

55 {
56 const SkPoint3 xAxis = SkPoint3::Make(1.0f, 0.0f, 0.0f);
57 const SkPoint3 yAxis = SkPoint3::Make(0.0f, 1.0f, 0.0f);
58 const SkPoint3 zAxis = SkPoint3::Make(0.0f, 0.0f, 1.0f);
59
60 SkScalar dot = xAxis.dot(yAxis);
62
63 dot = yAxis.dot(zAxis);
65
66 dot = zAxis.dot(xAxis);
68
69 SkPoint3 v = SkPoint3::Make(13.0f, 2.0f, 7.0f);
70 v.normalize();
71
72 dot = v.dot(v);
74
76
77 dot = xAxis.dot(v);
79
80 dot = yAxis.dot(v);
82}
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
Definition SkVx.h:964
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.h:18
bool normalize()
Definition SkPoint3.cpp:49
SkScalar dot(const SkPoint3 &vec) const
Definition SkPoint3.h:126

◆ test_eq_ops()

static void test_eq_ops ( skiatest::Reporter reporter)
static

Definition at line 18 of file Point3Test.cpp.

18 {
19 const SkPoint3 p0 = SkPoint3::Make(0, 0, 0);
20 const SkPoint3 p1 = SkPoint3::Make(1, 1, 1);
21 const SkPoint3 p2 = SkPoint3::Make(1, 1, 1);
22
23 REPORTER_ASSERT(reporter, p0 != p1);
24 REPORTER_ASSERT(reporter, p1 == p2);
25}

◆ test_length()

static void test_length ( skiatest::Reporter reporter,
SkScalar  x,
SkScalar  y,
SkScalar  z,
SkScalar  expectedLen 
)
static

Definition at line 84 of file Point3Test.cpp.

85 {
86 SkPoint3 point = SkPoint3::Make(x, y, z);
87
88 SkScalar s1 = point.length();
89 SkScalar s2 = SkPoint3::Length(x, y, z);
90
93}
double y
double x
static SkScalar Length(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.cpp:29
SkScalar length() const
Definition SkPoint3.h:44

◆ test_normalize()

static void test_normalize ( skiatest::Reporter reporter,
SkScalar  x,
SkScalar  y,
SkScalar  z,
SkScalar  expectedLen 
)
static

Definition at line 95 of file Point3Test.cpp.

96 {
97 SkPoint3 point = SkPoint3::Make(x, y, z);
98
99 bool result = point.normalize();
100 SkScalar newLength = point.length();
101
102 if (0 == expectedLen) {
103 const SkPoint3 empty = SkPoint3::Make(0.0f, 0.0f, 0.0f);
104
107 REPORTER_ASSERT(reporter, point == empty);
108 } else {
111 }
112 SkRandom random;
113 random.setSeed(1234);
114 SkPoint3 pt3;
115 int testCount = 100000;
116 for (int index = 0; index < testCount; ++index) {
117 SkScalar testVal;
118 do {
119 testVal = random.nextRangeF(0, 2);
120 } while (!testVal);
121 pt3.set(testVal, 0, 0);
122 REPORTER_ASSERT(reporter, !pt3.normalize() || 1 == pt3.fX);
123 }
124}
static const size_t testCount
#define SK_Scalar1
Definition SkScalar.h:18
float nextRangeF(float min, float max)
Definition SkRandom.h:64
void setSeed(uint32_t seed)
Definition SkRandom.h:128
EMSCRIPTEN_KEEPALIVE void empty()
GAsyncResult * result
SkScalar fX
Definition SkPoint3.h:16
void set(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.h:28

◆ test_ops()

static void test_ops ( skiatest::Reporter reporter)
static

Definition at line 27 of file Point3Test.cpp.

27 {
28 SkPoint3 v = SkPoint3::Make(1, 1, 1);
29 v.normalize();
31
32 // scale
33 SkPoint3 p = v.makeScale(3.0f);
35
36 p.scale(1.0f/3.0f);
38
39 SkPoint3 p1 = SkPoint3::Make(20.0f, 2.0f, 10.0f);
40 SkPoint3 p2 = -p1;
41
42 // -
43 p = p1 - p1;
47
48 // +
49 p = p1 + p2;
53}
SkPoint3 makeScale(SkScalar scale) const
Definition SkPoint3.h:54