1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
<html>
<head>
<script src="../http/tests/inspector/inspector-test.js"></script>
<script>
function test()
{
InspectorTest.runTestSuite([
function testVectorLength(next)
{
var testVectors = [
new WebInspector.Geometry.Vector(3, 4, 5),
new WebInspector.Geometry.Vector(-1, 0, -1),
new WebInspector.Geometry.Vector(6, -2, 3)
];
InspectorTest.addResult("Testing vector length");
for (var i = 0; i < testVectors.length; ++i)
InspectorTest.addResult(String.sprintf("Vector length: %.4f", testVectors[i].length()));
next();
},
function testVectorNormalize(next)
{
var testVectors = [
new WebInspector.Geometry.Vector(3, 4, 5),
new WebInspector.Geometry.Vector(-1, 0, -1),
new WebInspector.Geometry.Vector(6, -2, 3)
];
var eps = 1e-05;
for (var i = 0; i < testVectors.length; ++i) {
testVectors[i].normalize();
InspectorTest.assertTrue(Math.abs(testVectors[i].length() - 1) <= eps, "Length of normalized vector is not 1")
}
var zeroVector = new WebInspector.Geometry.Vector(0, 0, 0);
zeroVector.normalize();
InspectorTest.assertTrue(zeroVector.length() <= eps, "Zero vector after normalization isn't zero vector");
next();
},
function testScalarProduct(next)
{
var vectorsU = [
new WebInspector.Geometry.Vector(3, 4, 5),
new WebInspector.Geometry.Vector(-1, 0, -1),
new WebInspector.Geometry.Vector(6, -2, 3)
];
var vectorsV = [
new WebInspector.Geometry.Vector(1, 10, -5),
new WebInspector.Geometry.Vector(2, 3, 4),
new WebInspector.Geometry.Vector(0, 0, 0)
];
for (var i = 0; i < vectorsU.length; ++i)
InspectorTest.addResult("Scalar Product:" + WebInspector.Geometry.scalarProduct(vectorsU[i], vectorsV[i]))
next();
},
function testCrossProduct(next)
{
var vectorsU = [
new WebInspector.Geometry.Vector(3, 4, 5),
new WebInspector.Geometry.Vector(-1, 0, -1),
new WebInspector.Geometry.Vector(6, -2, 3)
];
var vectorsV = [
new WebInspector.Geometry.Vector(1, 10, -5),
new WebInspector.Geometry.Vector(2, 3, 4),
new WebInspector.Geometry.Vector(0, 0, 0)
];
for (var i = 0; i < vectorsU.length; ++i) {
var result = WebInspector.Geometry.crossProduct(vectorsU[i], vectorsV[i]);
InspectorTest.addResult(String.sprintf("Cross Product: [%.4f, %.4f, %.4f]", result.x, result.y, result.z));
}
next();
},
function testCalculateAngle(next)
{
var vectorsU = [
new WebInspector.Geometry.Vector(3, 4, 5),
new WebInspector.Geometry.Vector(-1, 0, -1),
new WebInspector.Geometry.Vector(1, 1, 0),
new WebInspector.Geometry.Vector(6, -2, 3),
];
var vectorsV = [
new WebInspector.Geometry.Vector(-3, -4, -5),
new WebInspector.Geometry.Vector(2, 3, 4),
new WebInspector.Geometry.Vector(-1, 1, 0),
new WebInspector.Geometry.Vector(0, 0, 0),
];
for (var i = 0; i < vectorsU.length; ++i)
InspectorTest.addResult(String.sprintf("Calculate angle: %.4f", WebInspector.Geometry.calculateAngle(vectorsU[i], vectorsV[i])));
next();
},
function testRadToDeg(next)
{
var angles = [Math.PI, Math.PI / 4, Math.PI / 6];
for (var i = 0; i < angles.length; ++i)
InspectorTest.addResult(String.sprintf("deg: %.4f", WebInspector.Geometry.radToDeg(angles[i])));
next();
},
function testEulerAnglesFromRotationMatrix(next)
{
var rotationMatrices = [
"matrix3d(0.612, 0.353, -0.707, 0, 0.280, 0.739, 0.612, 0, 0.739, -0.573, 0.353, 0, 0, 0, 0, 1)",
"matrix3d(0.353, 0.612, -0.707, 0, -0.573, 0.739, 0.353, 0, 0.739, 0.280, 0.612, 0, 0, 0, 0, 1)",
"matrix3d(0.342, 0, -0.939, 0, 0.321, 0.939, 0.116, 0, 0.883, -0.342, 0.321, 0, 0, 0, 0, 1)"
];
for (var i = 0; i < rotationMatrices.length; ++i) {
var angles = WebInspector.Geometry.EulerAngles.fromRotationMatrix(new WebKitCSSMatrix(rotationMatrices[i]));
InspectorTest.addResult(String.sprintf("Euler angles: %.4f %.4f %.4f", angles.alpha, angles.beta, angles.gamma));
}
next();
}
]);
}
</script>
</head>
<body onload="runTest()">
<p>Tests Geometry utility class</p>
</body>
</html>
|