فهرست منبع

Matrix3: Make makeTranslation() accept Vector2 (#26054)

* Matrix3: Make makeTranslation() accept Vector2

* Update Matrix3.js

* Update Matrix3.js

* Update Matrix3.tests.js

* Update Matrix3.html

* Update Matrix3.html

* Update Matrix3.html
chyy 2 سال پیش
والد
کامیت
674400e2cc
5فایلهای تغییر یافته به همراه37 افزوده شده و 7 حذف شده
  1. 3 0
      docs/api/en/math/Matrix3.html
  2. 3 0
      docs/api/it/math/Matrix3.html
  3. 3 0
      docs/api/zh/math/Matrix3.html
  4. 19 5
      src/math/Matrix3.js
  5. 9 2
      test/unit/src/math/Matrix3.tests.js

+ 3 - 0
docs/api/en/math/Matrix3.html

@@ -169,8 +169,11 @@ x, 0, 0,
 0, 0, 1 	</code>
 		</p>
 
+		<h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
 		<h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
 		<p>
+			[page:Vector2 v] a translation transform from vector.<br />
+			or<br />
 			[page:Float x] - the amount to translate in the X axis.<br />
 			[page:Float y] - the amount to translate in the Y axis.<br />
 

+ 3 - 0
docs/api/it/math/Matrix3.html

@@ -157,8 +157,11 @@ x, 0, 0,
 		</code>
 		</p>
 
+		<h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
 		<h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
 		<p>
+		[page:Vector2 v] a translation transform from vector.<br />
+		or<br />
 		[page:Float x] - la quantità da translare sull'asse X.<br />
 		[page:Float y] - la quantità da translare sull'asse Y.<br />
 

+ 3 - 0
docs/api/zh/math/Matrix3.html

@@ -151,8 +151,11 @@ x, 0, 0,
 		</code>
 		</p>
 
+		<h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
 		<h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
 		<p>
+		[page:Vector2 v] a translation transform from vector.<br />
+		or<br />
 		[page:Float x] - the amount to translate in the X axis.<br />
 		[page:Float y] - the amount to translate in the Y axis.<br />
 

+ 19 - 5
src/math/Matrix3.js

@@ -267,13 +267,27 @@ class Matrix3 {
 
 	makeTranslation( x, y ) {
 
-		this.set(
+		if ( x.isVector2 ) {
 
-			1, 0, x,
-			0, 1, y,
-			0, 0, 1
+			this.set(
 
-		);
+				1, 0, x.x,
+				0, 1, x.y,
+				0, 0, 1
+
+			);
+
+		} else {
+
+			this.set(
+
+				1, 0, x,
+				0, 1, y,
+				0, 0, 1
+
+			);
+
+		}
 
 		return this;
 

+ 9 - 2
test/unit/src/math/Matrix3.tests.js

@@ -450,8 +450,15 @@ export default QUnit.module( 'Maths', () => {
 
 		QUnit.todo( 'makeTranslation', ( assert ) => {
 
-			// makeTranslation( x, y )
-			assert.ok( false, 'everything\'s gonna be alright' );
+			const a = new Matrix3();
+			const b = new Vector2( 1, 2 );
+			const c = new Matrix3().set( 1, 0, 1, 0, 1, 2, 0, 0, 1 );
+
+			a.makeTranslation( b.x, b.y );
+			assert.ok( matrixEquals3( a, c ), 'Check translation result' );
+
+			a.makeTranslation( b );
+			assert.ok( matrixEquals3( a, c ), 'Check translation result' );
 
 		} );