Flutter Engine
The Flutter Engine
Point3Test.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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 */
7
8// Unit tests for src/core/SkPoint3.cpp and its header
9
12#include "src/base/SkRandom.h"
13#include "tests/Test.h"
14
15#include <array>
16#include <cstddef>
17
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}
26
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}
54
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}
83
85 SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen) {
86 SkPoint3 point = SkPoint3::Make(x, y, z);
87
88 SkScalar s1 = point.length();
89 SkScalar s2 = SkPoint3::Length(x, y, z);
90
93}
94
96 SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen) {
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}
125
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
Definition: FontMgrTest.cpp:39
static const size_t testCount
static void test_ops(skiatest::Reporter *reporter)
Definition: Point3Test.cpp:27
static void test_dot(skiatest::Reporter *reporter)
Definition: Point3Test.cpp:55
static void test_eq_ops(skiatest::Reporter *reporter)
Definition: Point3Test.cpp:18
static void test_length(skiatest::Reporter *reporter, SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen)
Definition: Point3Test.cpp:84
static void test_normalize(skiatest::Reporter *reporter, SkScalar x, SkScalar y, SkScalar z, SkScalar expectedLen)
Definition: Point3Test.cpp:95
DEF_TEST(Point3, reporter)
Definition: Point3Test.cpp:126
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
#define SK_Scalar1
Definition: SkScalar.h:18
#define SK_ScalarRoot2Over2
Definition: SkScalar.h:23
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
float nextRangeF(float min, float max)
Definition: SkRandom.h:64
void setSeed(uint32_t seed)
Definition: SkRandom.h:128
float SkScalar
Definition: extension.cpp:12
EMSCRIPTEN_KEEPALIVE void empty()
GAsyncResult * result
double y
double x
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
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
Definition: SkVx.h:964
SkScalar fX
Definition: SkPoint3.h:16
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
static SkScalar Length(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.cpp:29
SkScalar length() const
Definition: SkPoint3.h:44
SkPoint3 makeScale(SkScalar scale) const
Definition: SkPoint3.h:54
bool normalize()
Definition: SkPoint3.cpp:49
SkScalar dot(const SkPoint3 &vec) const
Definition: SkPoint3.h:126
void set(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:28