-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
320 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/geom/src/Matrix/service/MatirxConcatService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Matrix } from "../../Matrix"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("Matrix.js concat test", () => | ||
{ | ||
it("concat test case1", () => | ||
{ | ||
const matrix1 = new Matrix(2, 1, -1, 1, 0, 5); | ||
const matrix2 = new Matrix(1.3, 0.75, 0, -1.5, 10, -10); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=2.5999999046325684, b=0, c=-1.2999999523162842, d=-2.25, tx=10, ty=-17.5)" | ||
); | ||
}); | ||
|
||
it("concat test case2", () => | ||
{ | ||
const matrix1 = new Matrix(2, 1, -1, 1, 0, 5); | ||
const matrix2 = new Matrix(0, 0.75, 0, -1.5, 10, -10); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=0, b=0, c=0, d=-2.25, tx=10, ty=-17.5)" | ||
); | ||
}); | ||
|
||
it("concat test case3", () => | ||
{ | ||
const matrix1 = new Matrix(2, 1, -1, 1, 0, 5); | ||
const matrix2 = new Matrix(1.3, 0, 0, -1.5, 10, -10); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=2.5999999046325684, b=-1.5, c=-1.2999999523162842, d=-1.5, tx=10, ty=-17.5)" | ||
); | ||
}); | ||
|
||
it("concat test case4", () => | ||
{ | ||
const matrix1 = new Matrix(2, 1, -1, 1, 0, 5); | ||
const matrix2 = new Matrix(1.3, 0.75, 0, 0, 10, -10); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=2.5999999046325684, b=1.5, c=-1.2999999523162842, d=-0.75, tx=10, ty=-10)" | ||
); | ||
}); | ||
|
||
it("concat test case5", () => | ||
{ | ||
const matrix1 = new Matrix(2, 1, -1, 1, 0, 5); | ||
const matrix2 = new Matrix(1.3, 0.75, 0, -1.5, 0, -10); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=2.5999999046325684, b=0, c=-1.2999999523162842, d=-2.25, tx=0, ty=-17.5)" | ||
); | ||
}); | ||
|
||
it("concat test case6", () => | ||
{ | ||
const matrix1 = new Matrix(2, 1, -1, 1, 0, 5); | ||
const matrix2 = new Matrix(1.3, 0.75, 0, -1.5, 10, 0); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=2.5999999046325684, b=0, c=-1.2999999523162842, d=-2.25, tx=10, ty=-7.5)" | ||
); | ||
}); | ||
|
||
it("concat test case7", () => | ||
{ | ||
const matrix1 = new Matrix(1,0,0,1,0,0); | ||
const matrix2 = new Matrix(1.3, 0.75, 0, -1.5, 10, -10); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=1.2999999523162842, b=0.75, c=0, d=-1.5, tx=10, ty=-10)" | ||
); | ||
}); | ||
|
||
it("concat test case8", () => | ||
{ | ||
const matrix1 = new Matrix(1,0,0,1,10,10); | ||
const matrix2 = new Matrix(1.3, 0.75, 0, -1.5, 10, -10); | ||
matrix1.concat(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=1.2999999523162842, b=0.75, c=0, d=-1.5, tx=23, ty=-17.5)" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Matrix } from "../../Matrix"; | ||
|
||
/** | ||
* @description 指定のMatrixを連結 | ||
* Concatenate specified Matrix | ||
* | ||
* @param {Matrix} matrix1 | ||
* @param {Matrix} matrix2 | ||
* @return {void} | ||
* @method | ||
* @public | ||
*/ | ||
export const execute = (matrix1: Matrix, matrix2: Matrix): void => | ||
{ | ||
const matrixArray1 = matrix1._$matrix; | ||
const matrixArray2 = matrix2._$matrix; | ||
|
||
let a = matrixArray1[0] * matrixArray2[0]; | ||
let b = 0.0; | ||
let c = 0.0; | ||
let d = matrixArray1[3] * matrixArray2[3]; | ||
let tx = matrixArray1[4] * matrixArray2[0] + matrixArray2[4]; | ||
let ty = matrixArray1[5] * matrixArray2[3] + matrixArray2[5]; | ||
|
||
if (matrixArray1[1] || matrixArray1[2] || matrixArray2[1] || matrixArray2[2]) { | ||
a += matrixArray1[1] * matrixArray2[2]; | ||
d += matrixArray1[2] * matrixArray2[1]; | ||
b += matrixArray1[0] * matrixArray2[1] + matrixArray1[1] * matrixArray2[3]; | ||
c += matrixArray1[2] * matrixArray2[0] + matrixArray1[3] * matrixArray2[2]; | ||
tx += matrixArray1[5] * matrixArray2[2]; | ||
ty += matrixArray1[4] * matrixArray2[1]; | ||
} | ||
|
||
matrixArray1[0] = a; | ||
matrixArray1[1] = b; | ||
matrixArray1[2] = c; | ||
matrixArray1[3] = d; | ||
matrixArray1[4] = tx; | ||
matrixArray1[5] = ty; | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/geom/src/Matrix/service/MatrixCopyFromService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Matrix } from "../../Matrix"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("Matrix.js copyFrom", () => | ||
{ | ||
it("copy test case1", () => | ||
{ | ||
const matrix1 = new Matrix(); | ||
expect(matrix1.toString()).toBe( | ||
"(a=1, b=0, c=0, d=1, tx=0, ty=0)" | ||
); | ||
|
||
const matrix2 = new Matrix(1, 2, 3, 4, 5, 6); | ||
matrix1.copyFrom(matrix2); | ||
expect(matrix1.toString()).toBe( | ||
"(a=1, b=2, c=3, d=4, tx=5, ty=6)" | ||
); | ||
|
||
matrix1.a = 1; | ||
matrix1.b = 0; | ||
matrix1.c = 0; | ||
matrix1.d = 1; | ||
matrix1.tx = 100; | ||
matrix1.ty = 200; | ||
expect(matrix1.toString()).toBe( | ||
"(a=1, b=0, c=0, d=1, tx=100, ty=200)" | ||
); | ||
|
||
expect(matrix2.toString()).toBe( | ||
"(a=1, b=2, c=3, d=4, tx=5, ty=6)" | ||
); | ||
}); | ||
}); |
Oops, something went wrong.