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
/* global QUnit */
import { Spherical } from '../../../../src/math/Spherical.js';
import { Vector3 } from '../../../../src/math/Vector3.js';
import {
eps
} from '../../utils/math-constants.js';
export default QUnit.module( 'Maths', () => {
QUnit.module( 'Spherical', () => {
// INSTANCING
QUnit.test( 'Instancing', ( assert ) => {
let a = new Spherical();
const radius = 10.0;
const phi = Math.acos( - 0.5 );
const theta = Math.sqrt( Math.PI ) * phi;
assert.strictEqual( a.radius, 1.0, 'Default values: check radius' );
assert.strictEqual( a.phi, 0, 'Default values: check phi' );
assert.strictEqual( a.theta, 0, 'Default values: check theta' );
a = new Spherical( radius, phi, theta );
assert.strictEqual( a.radius, radius, 'Custom values: check radius' );
assert.strictEqual( a.phi, phi, 'Custom values: check phi' );
assert.strictEqual( a.theta, theta, 'Custom values: check theta' );
} );
// PUBLIC STUFF
QUnit.test( 'set', ( assert ) => {
const a = new Spherical();
const radius = 10.0;
const phi = Math.acos( - 0.5 );
const theta = Math.sqrt( Math.PI ) * phi;
a.set( radius, phi, theta );
assert.strictEqual( a.radius, radius, 'Check radius' );
assert.strictEqual( a.phi, phi, 'Check phi' );
assert.strictEqual( a.theta, theta, 'Check theta' );
} );
QUnit.test( 'clone', ( assert ) => {
const radius = 10.0;
const phi = Math.acos( - 0.5 );
const theta = Math.sqrt( Math.PI ) * phi;
const a = new Spherical( radius, phi, theta );
const b = a.clone();
assert.propEqual( a, b, 'Check a and b are equal after clone()' );
a.radius = 2.0;
assert.notPropEqual( a, b, 'Check a and b are not equal after modification' );
} );
QUnit.test( 'copy', ( assert ) => {
const radius = 10.0;
const phi = Math.acos( - 0.5 );
const theta = Math.sqrt( Math.PI ) * phi;
const a = new Spherical( radius, phi, theta );
const b = new Spherical().copy( a );
assert.propEqual( a, b, 'Check a and b are equal after copy()' );
a.radius = 2.0;
assert.notPropEqual( a, b, 'Check a and b are not equal after modification' );
} );
QUnit.test( 'makeSafe', ( assert ) => {
const EPS = 0.000001; // from source
const tooLow = 0.0;
const tooHigh = Math.PI;
const justRight = 1.5;
const a = new Spherical( 1, tooLow, 0 );
a.makeSafe();
assert.strictEqual( a.phi, EPS, 'Check if small values are set to EPS' );
a.set( 1, tooHigh, 0 );
a.makeSafe();
assert.strictEqual( a.phi, Math.PI - EPS, 'Check if high values are set to (Math.PI - EPS)' );
a.set( 1, justRight, 0 );
a.makeSafe();
assert.strictEqual( a.phi, justRight, 'Check that valid values don\'t get changed' );
} );
QUnit.test( 'setFromVector3', ( assert ) => {
const a = new Spherical( 1, 1, 1 );
const b = new Vector3( 0, 0, 0 );
const c = new Vector3( Math.PI, 1, - Math.PI );
const expected = new Spherical( 4.554032147688322, 1.3494066171539107, 2.356194490192345 );
a.setFromVector3( b );
assert.strictEqual( a.radius, 0, 'Zero-length vector: check radius' );
assert.strictEqual( a.phi, 0, 'Zero-length vector: check phi' );
assert.strictEqual( a.theta, 0, 'Zero-length vector: check theta' );
a.setFromVector3( c );
assert.ok( Math.abs( a.radius - expected.radius ) <= eps, 'Normal vector: check radius' );
assert.ok( Math.abs( a.phi - expected.phi ) <= eps, 'Normal vector: check phi' );
assert.ok( Math.abs( a.theta - expected.theta ) <= eps, 'Normal vector: check theta' );
} );
QUnit.test( 'setFromCartesianCoords', ( assert ) => {
const a = new Spherical( 1, 1, 1 );
const expected = new Spherical( 4.554032147688322, 1.3494066171539107, 2.356194490192345 );
a.setFromCartesianCoords( 0, 0, 0 );
assert.strictEqual( a.radius, 0, 'Zero-length vector: check radius' );
assert.strictEqual( a.phi, 0, 'Zero-length vector: check phi' );
assert.strictEqual( a.theta, 0, 'Zero-length vector: check theta' );
a.setFromCartesianCoords( Math.PI, 1, - Math.PI );
assert.ok( Math.abs( a.radius - expected.radius ) <= eps, 'Normal vector: check radius' );
assert.ok( Math.abs( a.phi - expected.phi ) <= eps, 'Normal vector: check phi' );
assert.ok( Math.abs( a.theta - expected.theta ) <= eps, 'Normal vector: check theta' );
} );
} );
} );