forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphere.js
More file actions
112 lines (84 loc) · 3.04 KB
/
Copy pathSphere.js
File metadata and controls
112 lines (84 loc) · 3.04 KB
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
/**
* @author bhouston / http://exocortex.com
*/
module( "Sphere" );
test( "constructor", function() {
var a = new THREE.Sphere();
ok( a.center.equals( zero3 ), "Passed!" );
ok( a.radius == 0, "Passed!" );
a = new THREE.Sphere( one3.clone(), 1 );
ok( a.center.equals( one3 ), "Passed!" );
ok( a.radius == 1, "Passed!" );
});
test( "copy", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
var b = new THREE.Sphere().copy( a );
ok( b.center.equals( one3 ), "Passed!" );
ok( b.radius == 1, "Passed!" );
// ensure that it is a true copy
a.center = zero3;
a.radius = 0;
ok( b.center.equals( one3 ), "Passed!" );
ok( b.radius == 1, "Passed!" );
});
test( "set", function() {
var a = new THREE.Sphere();
ok( a.center.equals( zero3 ), "Passed!" );
ok( a.radius == 0, "Passed!" );
a.set( one3, 1 );
ok( a.center.equals( one3 ), "Passed!" );
ok( a.radius == 1, "Passed!" );
});
test( "empty", function() {
var a = new THREE.Sphere();
ok( a.empty(), "Passed!" );
a.set( one3, 1 );
ok( ! a.empty(), "Passed!" );
});
test( "containsPoint", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
ok( ! a.containsPoint( zero3 ), "Passed!" );
ok( a.containsPoint( one3 ), "Passed!" );
});
test( "distanceToPoint", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
ok( ( a.distanceToPoint( zero3 ) - 0.7320 ) < 0.001, "Passed!" );
ok( a.distanceToPoint( one3 ) === -1, "Passed!" );
});
test( "intersectsSphere", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
var b = new THREE.Sphere( zero3.clone(), 1 );
var c = new THREE.Sphere( zero3.clone(), 0.25 );
ok( a.intersectsSphere( b ) , "Passed!" );
ok( ! a.intersectsSphere( c ) , "Passed!" );
});
test( "intersectsPlane", function() {
var a = new THREE.Sphere( zero3.clone(), 1 );
var b = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 1 );
var c = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 1.25 );
var d = new THREE.Plane( new THREE.Vector3( 0, -1, 0 ), 1.25 );
ok( a.intersectsPlane( b ) , "Passed!" );
ok( ! a.intersectsPlane( c ) , "Passed!" );
ok( ! a.intersectsPlane( d ) , "Passed!" );
});
test( "clampPoint", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
ok( a.clampPoint( new THREE.Vector3( 1, 1, 3 ) ).equals( new THREE.Vector3( 1, 1, 2 ) ), "Passed!" );
ok( a.clampPoint( new THREE.Vector3( 1, 1, -3 ) ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" );
});
test( "getBoundingBox", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
ok( a.getBoundingBox().equals( new THREE.Box3( zero3, two3 ) ), "Passed!" );
a.set( zero3, 0 )
ok( a.getBoundingBox().equals( new THREE.Box3( zero3, zero3 ) ), "Passed!" );
});
test( "applyMatrix4", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
var m = new THREE.Matrix4().makeTranslation( 1, -2, 1 );
ok( a.clone().applyMatrix4( m ).getBoundingBox().equals( a.getBoundingBox().applyMatrix4( m ) ), "Passed!" );
});
test( "translate", function() {
var a = new THREE.Sphere( one3.clone(), 1 );
a.translate( one3.clone().negate() );
ok( a.center.equals( zero3 ), "Passed!" );
});