Skip to content

Commit

Permalink
#154 update: 変数名を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Jul 23, 2024
1 parent f9b3e0c commit 59d0210
Show file tree
Hide file tree
Showing 30 changed files with 320 additions and 270 deletions.
113 changes: 0 additions & 113 deletions __tests__/next2d/geom/MatrixTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,88 +48,7 @@ describe("Matrix.js namespace test", () =>



describe("Matrix.js concat test", () =>
{
it("concat test1", () =>
{
let m1 = new Matrix(2, 1, -1, 1, 0, 5);
let m2 = new Matrix(1.3, 0.75, 0, -1.5, 10, -10);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=2.5999999046325684, b=0, c=-1.2999999523162842, d=-2.25, tx=10, ty=-17.5)"
);
});

it("concat test2", () =>
{
let m1 = new Matrix(2, 1, -1, 1, 0, 5);
let m2 = new Matrix(0, 0.75, 0, -1.5, 10, -10);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=0, b=0, c=0, d=-2.25, tx=10, ty=-17.5)"
);
});

it("concat test3", () =>
{
let m1 = new Matrix(2, 1, -1, 1, 0, 5);
let m2 = new Matrix(1.3, 0, 0, -1.5, 10, -10);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=2.5999999046325684, b=-1.5, c=-1.2999999523162842, d=-1.5, tx=10, ty=-17.5)"
);
});

it("concat test4", () =>
{
let m1 = new Matrix(2, 1, -1, 1, 0, 5);
let m2 = new Matrix(1.3, 0.75, 0, 0, 10, -10);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=2.5999999046325684, b=1.5, c=-1.2999999523162842, d=-0.75, tx=10, ty=-10)"
);
});

it("concat test5", () =>
{
let m1 = new Matrix(2, 1, -1, 1, 0, 5);
let m2 = new Matrix(1.3, 0.75, 0, -1.5, 0, -10);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=2.5999999046325684, b=0, c=-1.2999999523162842, d=-2.25, tx=0, ty=-17.5)"
);
});

it("concat test6", () =>
{
let m1 = new Matrix(2, 1, -1, 1, 0, 5);
let m2 = new Matrix(1.3, 0.75, 0, -1.5, 10, 0);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=2.5999999046325684, b=0, c=-1.2999999523162842, d=-2.25, tx=10, ty=-7.5)"
);
});

it("concat test7", () =>
{
let m1 = new Matrix(1,0,0,1,0,0);
let m2 = new Matrix(1.3, 0.75, 0, -1.5, 10, -10);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=1.2999999523162842, b=0.75, c=0, d=-1.5, tx=10, ty=-10)"
);
});

it("concat test8", () =>
{
let m1 = new Matrix(1,0,0,1,10,10);
let m2 = new Matrix(1.3, 0.75, 0, -1.5, 10, -10);
m1.concat(m2);
expect(m1.toString()).toBe(
"(a=1.2999999523162842, b=0.75, c=0, d=-1.5, tx=23, ty=-17.5)"
);
});
});

describe("Matrix.js rotate test", () =>
{
Expand Down Expand Up @@ -2794,39 +2713,7 @@ describe("Matrix.js BugFix", () =>
});
});

describe("Matrix.js copyFrom", () =>
{
it("copy test case1", () =>
{

const defaultMatrix = new Matrix();
expect(defaultMatrix.toString()).toBe(
"(a=1, b=0, c=0, d=1, tx=0, ty=0)"
);

const matrix = new Matrix(1, 2, 3, 4, 5, 6);
defaultMatrix.copyFrom(matrix);
expect(defaultMatrix.toString()).toBe(
"(a=1, b=2, c=3, d=4, tx=5, ty=6)"
);

defaultMatrix.a = 1;
defaultMatrix.b = 0;
defaultMatrix.c = 0;
defaultMatrix.d = 1;
defaultMatrix.tx = 100;
defaultMatrix.ty = 200;
expect(defaultMatrix.toString()).toBe(
"(a=1, b=0, c=0, d=1, tx=100, ty=200)"
);

expect(matrix.toString()).toBe(
"(a=1, b=2, c=3, d=4, tx=5, ty=6)"
);

});

});

describe("Matrix.js setTo", () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@ import type { ColorTransform } from "../../ColorTransform";
* @description 指定のColorTransformを連結
* Concatenate the specified ColorTransform
*
* @param {ColorTransform} src
* @param {ColorTransform} dst
* @param {ColorTransform} color_transform1
* @param {ColorTransform} color_transform2
* @return {void}
* @method
* @public
*/
export const execute = (src: ColorTransform, dst: ColorTransform): void =>
{
const multiColor = src._$multiplication(
src._$colorTransform,
dst._$colorTransform
export const execute = (
color_transform1: ColorTransform,
color_transform2: ColorTransform
): void => {

const multiColor = color_transform1._$multiplication(
color_transform1._$colorTransform,
color_transform2._$colorTransform
);

// update
src._$colorTransform[0] = multiColor[0];
src._$colorTransform[1] = multiColor[1];
src._$colorTransform[2] = multiColor[2];
src._$colorTransform[3] = multiColor[3];
src._$colorTransform[4] = multiColor[4];
src._$colorTransform[5] = multiColor[5];
src._$colorTransform[6] = multiColor[6];
src._$colorTransform[7] = multiColor[7];
color_transform1._$colorTransform[0] = multiColor[0];
color_transform1._$colorTransform[1] = multiColor[1];
color_transform1._$colorTransform[2] = multiColor[2];
color_transform1._$colorTransform[3] = multiColor[3];
color_transform1._$colorTransform[4] = multiColor[4];
color_transform1._$colorTransform[5] = multiColor[5];
color_transform1._$colorTransform[6] = multiColor[6];
color_transform1._$colorTransform[7] = multiColor[7];

// pool
src._$poolBuffer(multiColor);
color_transform1._$poolBuffer(multiColor);
};
31 changes: 4 additions & 27 deletions packages/geom/src/Matrix.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Point } from "./Point";
import { execute as matrixCloneService } from "../src/Matrix/service/MatrixCloneService";
import { execute as matirxConcatService } from "../src/Matrix/service/MatirxConcatService";

/**
* @type {Float32Array[]}
Expand Down Expand Up @@ -286,38 +287,14 @@ export class Matrix
* Concatenates a matrix with the current matrix,
* effectively combining the geometric effects of the two.
*
* @param {Matrix} m
* @param {Matrix} matrix
* @return {void}
* @method
* @public
*/
concat (m: Matrix): void
concat (matrix: Matrix): void
{
const matrix = this._$matrix;
const target = m._$matrix;

let a = matrix[0] * target[0];
let b = 0.0;
let c = 0.0;
let d = matrix[3] * target[3];
let tx = matrix[4] * target[0] + target[4];
let ty = matrix[5] * target[3] + target[5];

if (matrix[1] || matrix[2] || target[1] || target[2]) {
a += matrix[1] * target[2];
d += matrix[2] * target[1];
b += matrix[0] * target[1] + matrix[1] * target[3];
c += matrix[2] * target[0] + matrix[3] * target[2];
tx += matrix[5] * target[2];
ty += matrix[4] * target[1];
}

this._$matrix[0] = a;
this._$matrix[1] = b;
this._$matrix[2] = c;
this._$matrix[3] = d;
this._$matrix[4] = tx;
this._$matrix[5] = ty;
matirxConcatService(this, matrix);
}

/**
Expand Down
85 changes: 85 additions & 0 deletions packages/geom/src/Matrix/service/MatirxConcatService.test.ts
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)"
);
});
});
40 changes: 40 additions & 0 deletions packages/geom/src/Matrix/service/MatirxConcatService.ts
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 packages/geom/src/Matrix/service/MatrixCopyFromService.test.ts
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)"
);
});
});
Loading

0 comments on commit 59d0210

Please sign in to comment.