Skip to content

Commit

Permalink
add spacings
Browse files Browse the repository at this point in the history
  • Loading branch information
simonThiele committed Nov 20, 2015
1 parent 244b952 commit aa8ce37
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions test/unit/core/Raycaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ test( "intersectObjects", function() {
var raycaster = getRaycaster();
var objectsToCheck = getObjectsToCheck();

ok ( raycaster.intersectObjects(objectsToCheck).length === 1,
ok ( raycaster.intersectObjects( objectsToCheck ).length === 1,
"no recursive search should lead to one hit" );

ok ( raycaster.intersectObjects(objectsToCheck, true).length === 3,
ok ( raycaster.intersectObjects( objectsToCheck, true ).length === 3,
"recursive search should lead to two hits" );

var intersections = raycaster.intersectObjects(objectsToCheck, true);
for (var i = 0; i < intersections.length - 1; i++) {
ok( intersections[i].distance <= intersections[i + 1].distance, "intersections are sorted" );
var intersections = raycaster.intersectObjects( objectsToCheck, true );
for ( var i = 0; i < intersections.length - 1; i++ ) {

ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );

}
});

test( "intersectObject", function() {
var raycaster = getRaycaster();
var objectsToCheck = getObjectsToCheck();

ok ( raycaster.intersectObject(objectsToCheck[0]).length === 1,
ok ( raycaster.intersectObject( objectsToCheck[ 0 ] ).length === 1,
"no recursive search should lead to one hit" );

ok ( raycaster.intersectObject(objectsToCheck[0], true).length === 3,
ok ( raycaster.intersectObject( objectsToCheck[ 0 ], true ).length === 3,
"recursive search should lead to two hits" );

var intersections = raycaster.intersectObject(objectsToCheck[0], true);
for (var i = 0; i < intersections.length - 1; i++) {
ok( intersections[i].distance <= intersections[i + 1].distance, "intersections are sorted" );
var intersections = raycaster.intersectObject( objectsToCheck[ 0 ], true );
for ( var i = 0; i < intersections.length - 1; i++ ) {

ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );

}
});

Expand All @@ -46,16 +50,23 @@ test( "setFromCamera", function() {
"camera is looking straight to -z and so does the ray in the middle of the screen" );

var step = 0.1;
for (var x = -1; x <= 1; x+=step) {
for (var y = -1; y <= 1; y+=step) {

for ( var x = -1; x <= 1; x += step ) {

for ( var y = -1; y <= 1; y += step ) {

raycaster.setFromCamera( { x, y }, camera );
var refVector = new THREE.Vector3(x, y, -1).normalize();
checkRayDirectionAgainstReferenceVector(rayDirection, refVector);

var refVector = new THREE.Vector3( x, y, -1 ).normalize();

checkRayDirectionAgainstReferenceVector( rayDirection, refVector );

}

}
});

function checkRayDirectionAgainstReferenceVector(rayDirection, refVector) {
function checkRayDirectionAgainstReferenceVector( rayDirection, refVector ) {
ok( refVector.x - rayDirection.x <= Number.EPSILON &&
refVector.y - rayDirection.y <= Number.EPSILON &&
refVector.z - rayDirection.z <= Number.EPSILON,
Expand All @@ -75,31 +86,34 @@ function getObjectsToCheck() {
var objects = [];

var sphere1 = getSphere();
sphere1.position.set(0, 0, -10);
sphere1.position.set( 0, 0, -10 );
sphere1.name = 1;
objects.push(sphere1);
objects.push( sphere1 );

var sphere11 = getSphere();
sphere11.position.set(0, 0, 1);
sphere11.position.set( 0, 0, 1 );
sphere11.name = 11;
sphere1.add(sphere11);
sphere1.add( sphere11 );

var sphere12 = getSphere();
sphere12.position.set(0, 0, -1);
sphere12.position.set( 0, 0, -1 );
sphere12.name = 12;
sphere1.add(sphere12);
sphere1.add( sphere12 );

var sphere2 = getSphere();
sphere2.position.set(-5, 0, -5);
sphere2.position.set( -5, 0, -5 );
sphere2.name = 2;
objects.push(sphere2);
objects.push( sphere2 );

for ( var i = 0; i < objects.length; i++ ) {

objects[ i ].updateMatrixWorld();

for (var i = 0; i < objects.length; i++) {
objects[i].updateMatrixWorld();
}

return objects;
}

function getSphere() {
return new THREE.Mesh(new THREE.SphereGeometry(1, 100, 100));
return new THREE.Mesh( new THREE.SphereGeometry( 1, 100, 100 ) );
}

0 comments on commit aa8ce37

Please sign in to comment.