提交 a1ac92db 编写于 作者: B Ben Houston

Merge branch 'vector-index-accessors' into dev

......@@ -41,6 +41,18 @@ THREE.Vector2.prototype = {
},
setComponent: function ( index, value ) {
this[ THREE.Vector2.__indexToName[ index ] ] = value;
},
getComponent: function ( index ) {
return this[ THREE.Vector2.__indexToName[ index ] ];
},
copy: function ( v ) {
this.x = v.x;
......@@ -263,3 +275,8 @@ THREE.Vector2.prototype = {
}
};
THREE.Vector2.__indexToName = {
0: 'x',
1: 'y'
};
......@@ -54,6 +54,18 @@ THREE.Vector3.prototype = {
},
setComponent: function ( index, value ) {
this[ THREE.Vector3.__indexToName[ index ] ] = value;
},
getComponent: function ( index ) {
return this[ THREE.Vector3.__indexToName[ index ] ];
},
copy: function ( v ) {
this.x = v.x;
......@@ -579,3 +591,9 @@ THREE.Vector3.prototype = {
}
};
THREE.Vector3.__indexToName = {
0: 'x',
1: 'y',
2: 'z'
};
......@@ -62,6 +62,18 @@ THREE.Vector4.prototype = {
},
setComponent: function ( index, value ) {
this[ THREE.Vector4.__indexToName[ index ] ] = value;
},
getComponent: function ( index ) {
return this[ THREE.Vector4.__indexToName[ index ] ];
},
copy: function ( v ) {
this.x = v.x;
......@@ -494,3 +506,10 @@ THREE.Vector4.prototype = {
}
};
THREE.Vector4.__indexToName = {
0: 'x',
1: 'y',
2: 'z',
3: 'w'
};
......@@ -48,6 +48,17 @@ test( "setX,setY", function() {
ok( a.y == y, "Passed!" );
});
test( "setComponent,getComponent", function() {
var a = new THREE.Vector2();
ok( a.x == 0, "Passed!" );
ok( a.y == 0, "Passed!" );
a.setComponent( 0, 1 );
a.setComponent( 1, 2 );
ok( a.getComponent( 0 ) == 1, "Passed!" );
ok( a.getComponent( 1 ) == 2, "Passed!" );
});
test( "add", function() {
var a = new THREE.Vector2( x, y );
var b = new THREE.Vector2( -x, -y );
......
......@@ -59,6 +59,20 @@ test( "setX,setY,setZ", function() {
ok( a.z == z, "Passed!" );
});
test( "setComponent,getComponent", function() {
var a = new THREE.Vector3();
ok( a.x == 0, "Passed!" );
ok( a.y == 0, "Passed!" );
ok( a.z == 0, "Passed!" );
a.setComponent( 0, 1 );
a.setComponent( 1, 2 );
a.setComponent( 2, 3 );
ok( a.getComponent( 0 ) == 1, "Passed!" );
ok( a.getComponent( 1 ) == 2, "Passed!" );
ok( a.getComponent( 2 ) == 3, "Passed!" );
});
test( "add", function() {
var a = new THREE.Vector3( x, y, z );
var b = new THREE.Vector3( -x, -y, -z );
......
......@@ -69,6 +69,23 @@ test( "setX,setY,setZ,setW", function() {
ok( a.w == w, "Passed!" );
});
test( "setComponent,getComponent", function() {
var a = new THREE.Vector4();
ok( a.x == 0, "Passed!" );
ok( a.y == 0, "Passed!" );
ok( a.z == 0, "Passed!" );
ok( a.w == 1, "Passed!" );
a.setComponent( 0, 1 );
a.setComponent( 1, 2 );
a.setComponent( 2, 3 );
a.setComponent( 3, 4 );
ok( a.getComponent( 0 ) == 1, "Passed!" );
ok( a.getComponent( 1 ) == 2, "Passed!" );
ok( a.getComponent( 2 ) == 3, "Passed!" );
ok( a.getComponent( 3 ) == 4, "Passed!" );
});
test( "add", function() {
var a = new THREE.Vector4( x, y, z, w );
var b = new THREE.Vector4( -x, -y, -z, -w );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册