Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added set() to vector API.

  • Loading branch information...
commit bcddb83947f1355eda2706526409a04110ba1d74 1 parent 0e84c50
Alan K modeswitch authored
13 src/vector/vector2.js
@@ -79,16 +79,11 @@ define( function ( require ) {
79 79 return result;
80 80 },
81 81
82   - dproject: function( v1, v2, result ) {
83   - if( vector2.angle( v1, v2 ) >= constants.TAU/4 ) {
84   - result = vector2.zero;
85   - } else {
86   - result = result || Vector2();
87   - vector2.project( v1, v2, result );
88   - }
89   - return result;
  82 + set: function( v, x, y ) {
  83 + v[0] = x;
  84 + v[1] = y;
90 85 },
91   -
  86 +
92 87 subtract: function( v1, v2, result ) {
93 88 result = result || Vector2();
94 89
6 src/vector/vector3.js
@@ -77,6 +77,12 @@ define( function ( require ) {
77 77
78 78 return result;
79 79 },
  80 +
  81 + set: function( v, x, y, z ) {
  82 + v[0] = x;
  83 + v[1] = y;
  84 + v[2] = z;
  85 + },
80 86
81 87 subtract: function( v1, v2, result ) {
82 88 result = result || Vector3();
7 src/vector/vector4.js
@@ -70,6 +70,13 @@ define( function ( require ) {
70 70
71 71 return result;
72 72 },
  73 +
  74 + set: function( v, x, y, z, w ) {
  75 + v[0] = x;
  76 + v[1] = y;
  77 + v[2] = z;
  78 + v[3] = w;
  79 + },
73 80
74 81 // Computes v1 - v2
75 82 subtract: function( v1, v2, result ) {
11 test/vector/vector2.js
@@ -268,13 +268,12 @@
268 268 ), 'project y-axis onto y=x' );
269 269 });
270 270
271   - test( 'direct projection', function() {
  271 + test( 'set()', function() {
272 272 expect( 1 );
273 273
274   - var v1 = math.Vector2( 1, 0 );
275   - var v2 = math.Vector2( -1, -1 );
276   -
277   - ok( math.vector2.equal( math.vector2.dproject( v1, v2 ), math.vector2.zero ), 'direct projection is zero' );
  274 + var v = new math.Vector2( 1, 2 );
  275 + math.vector2.set( v, 4, 5 );
  276 + ok( math.vector2.equal( v, [4, 5] ), 'v is set' );
278 277 });
279   -
  278 +
280 279 }());
8 test/vector/vector3.js
@@ -272,5 +272,13 @@
272 272 ' Right angle axis test = pi/2'
273 273 );
274 274 });
  275 +
  276 + test( 'set()', function() {
  277 + expect( 1 );
  278 +
  279 + var v = new math.Vector3( 1, 2, 3 );
  280 + math.vector3.set( v, 4, 5, 6 );
  281 + ok( math.vector3.equal( v, [4, 5, 6] ), 'v is set' );
  282 + });
275 283
276 284 }());
8 test/vector/vector4.js
@@ -259,5 +259,13 @@
259 259 ' Right angle axis test = pi/2'
260 260 );
261 261 });
  262 +
  263 + test( 'set()', function() {
  264 + expect( 1 );
  265 +
  266 + var v = new math.Vector4( 1, 2, 3, 4 );
  267 + math.vector4.set( v, 4, 5, 6, 7 );
  268 + ok( math.vector4.equal( v, [4, 5, 6, 7] ), 'v is set' );
  269 + });
262 270
263 271 }());

0 comments on commit bcddb83

Please sign in to comment.
Something went wrong with that request. Please try again.