提交 d464040d 编写于 作者: J Jan Wrobel

Simplify Box2 and Box3 setFromPoints, add tests.

上级 0a3ee86c
......@@ -24,42 +24,11 @@ THREE.Box2.prototype = {
setFromPoints: function ( points ) {
if ( points.length > 0 ) {
this.makeEmpty();
var point = points[ 0 ];
for ( var i = 0, il = points.length; i < il; i ++ ) {
this.min.copy( point );
this.max.copy( point );
for ( var i = 1, il = points.length; i < il; i ++ ) {
point = points[ i ];
if ( point.x < this.min.x ) {
this.min.x = point.x;
} else if ( point.x > this.max.x ) {
this.max.x = point.x;
}
if ( point.y < this.min.y ) {
this.min.y = point.y;
} else if ( point.y > this.max.y ) {
this.max.y = point.y;
}
}
} else {
this.makeEmpty();
this.expandByPoint( points[ i ] )
}
......
......@@ -25,22 +25,11 @@ THREE.Box3.prototype = {
setFromPoints: function ( points ) {
if ( points.length > 0 ) {
this.makeEmpty();
var point = points[ 0 ];
for ( var i = 0, il = points.length; i < il; i ++ ) {
this.min.copy( point );
this.max.copy( point );
for ( var i = 1, il = points.length; i < il; i ++ ) {
this.expandByPoint( points[ i ] )
}
} else {
this.makeEmpty();
this.expandByPoint( points[ i ] )
}
......
......@@ -39,6 +39,21 @@ test( "set", function() {
ok( a.max.equals( one2 ), "Passed!" );
});
test( "setFromPoints", function() {
var a = new THREE.Box2();
a.setFromPoints( [ zero2, one2, two2 ] );
ok( a.min.equals( zero2 ), "Passed!" );
ok( a.max.equals( two2 ), "Passed!" );
a.setFromPoints( [ one2 ] );
ok( a.min.equals( one2 ), "Passed!" );
ok( a.max.equals( one2 ), "Passed!" );
a.setFromPoints( [] );
ok( a.empty(), "Passed!" );
});
test( "empty/makeEmpty", function() {
var a = new THREE.Box2();
......
......@@ -39,6 +39,21 @@ test( "set", function() {
ok( a.max.equals( one3 ), "Passed!" );
});
test( "setFromPoints", function() {
var a = new THREE.Box3();
a.setFromPoints( [ zero3, one3, two3 ] );
ok( a.min.equals( zero3 ), "Passed!" );
ok( a.max.equals( two3 ), "Passed!" );
a.setFromPoints( [ one3 ] );
ok( a.min.equals( one3 ), "Passed!" );
ok( a.max.equals( one3 ), "Passed!" );
a.setFromPoints( [] );
ok( a.empty(), "Passed!" );
});
test( "empty/makeEmpty", function() {
var a = new THREE.Box3();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册