source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/test/unit/math/Sphere.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 2.6 KB
Line 
1/**
2 * @author bhouston / http://exocortex.com
3 */
4
5module( "Sphere" );
6
7test( "constructor", function() {
8 var a = new THREE.Sphere();
9 ok( a.center.equals( zero3 ), "Passed!" );
10 ok( a.radius == 0, "Passed!" );
11
12 a = new THREE.Sphere( one3.clone(), 1 );
13 ok( a.center.equals( one3 ), "Passed!" );
14 ok( a.radius == 1, "Passed!" );
15});
16
17test( "copy", function() {
18 var a = new THREE.Sphere( one3.clone(), 1 );
19 var b = new THREE.Sphere().copy( a );
20
21 ok( b.center.equals( one3 ), "Passed!" );
22 ok( b.radius == 1, "Passed!" );
23
24 // ensure that it is a true copy
25 a.center = zero3;
26 a.radius = 0;
27 ok( b.center.equals( one3 ), "Passed!" );
28 ok( b.radius == 1, "Passed!" );
29});
30
31test( "set", function() {
32 var a = new THREE.Sphere();
33 ok( a.center.equals( zero3 ), "Passed!" );
34 ok( a.radius == 0, "Passed!" );
35
36 a.set( one3, 1 );
37 ok( a.center.equals( one3 ), "Passed!" );
38 ok( a.radius == 1, "Passed!" );
39});
40
41test( "empty", function() {
42 var a = new THREE.Sphere();
43 ok( a.empty(), "Passed!" );
44
45 a.set( one3, 1 );
46 ok( ! a.empty(), "Passed!" );
47});
48
49test( "containsPoint", function() {
50 var a = new THREE.Sphere( one3.clone(), 1 );
51
52 ok( ! a.containsPoint( zero3 ), "Passed!" );
53 ok( a.containsPoint( one3 ), "Passed!" );
54});
55
56test( "distanceToPoint", function() {
57 var a = new THREE.Sphere( one3.clone(), 1 );
58
59 ok( ( a.distanceToPoint( zero3 ) - 0.7320 ) < 0.001, "Passed!" );
60 ok( a.distanceToPoint( one3 ) === -1, "Passed!" );
61});
62
63test( "intersectsSphere", function() {
64 var a = new THREE.Sphere( one3.clone(), 1 );
65 var b = new THREE.Sphere( zero3.clone(), 1 );
66 var c = new THREE.Sphere( zero3.clone(), 0.25 );
67
68 ok( a.intersectsSphere( b ) , "Passed!" );
69 ok( ! a.intersectsSphere( c ) , "Passed!" );
70});
71
72test( "clampPoint", function() {
73 var a = new THREE.Sphere( one3.clone(), 1 );
74
75 ok( a.clampPoint( new THREE.Vector3( 1, 1, 3 ) ).equals( new THREE.Vector3( 1, 1, 2 ) ), "Passed!" );
76 ok( a.clampPoint( new THREE.Vector3( 1, 1, -3 ) ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" );
77});
78
79test( "getBoundingBox", function() {
80 var a = new THREE.Sphere( one3.clone(), 1 );
81
82 ok( a.getBoundingBox().equals( new THREE.Box3( zero3, two3 ) ), "Passed!" );
83
84 a.set( zero3, 0 )
85 ok( a.getBoundingBox().equals( new THREE.Box3( zero3, zero3 ) ), "Passed!" );
86});
87
88test( "applyMatrix4", function() {
89 var a = new THREE.Sphere( one3.clone(), 1 );
90
91 var m = new THREE.Matrix4().makeTranslation( 1, -2, 1 );
92
93 ok( a.clone().applyMatrix4( m ).getBoundingBox().equals( a.getBoundingBox().applyMatrix4( m ) ), "Passed!" );
94});
95
96test( "translate", function() {
97 var a = new THREE.Sphere( one3.clone(), 1 );
98
99 a.translate( one3.clone().negate() );
100 ok( a.center.equals( zero3 ), "Passed!" );
101});
Note: See TracBrowser for help on using the repository browser.