Skip to content

Commit

Permalink
Merge branch 'vector-index-accessors' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Dec 21, 2012
2 parents 2613df2 + d23fc1b commit a1ac92d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/math/Vector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -263,3 +275,8 @@ THREE.Vector2.prototype = {
}

};

THREE.Vector2.__indexToName = {
0: 'x',
1: 'y'
};
18 changes: 18 additions & 0 deletions src/math/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -579,3 +591,9 @@ THREE.Vector3.prototype = {
}

};

THREE.Vector3.__indexToName = {
0: 'x',
1: 'y',
2: 'z'
};
19 changes: 19 additions & 0 deletions src/math/Vector4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -494,3 +506,10 @@ THREE.Vector4.prototype = {
}

};

THREE.Vector4.__indexToName = {
0: 'x',
1: 'y',
2: 'z',
3: 'w'
};
11 changes: 11 additions & 0 deletions test/unit/math/Vector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
14 changes: 14 additions & 0 deletions test/unit/math/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
17 changes: 17 additions & 0 deletions test/unit/math/Vector4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit a1ac92d

Please sign in to comment.