Skip to content

Commit

Permalink
Fix toString and update test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Dec 19, 2024
1 parent 79c0b8a commit c770e54
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cocos/core/math/mat3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,8 @@ export class Mat3 extends ValueType {
const t = this;
return `[\n${
t.m00}, ${t.m01}, ${t.m02},\n${
t.m03},\n${t.m04}, ${t.m05},\n${
t.m06}, ${t.m07},\n${t.m08}\n`
t.m03}, ${t.m04}, ${t.m05},\n${
t.m06}, ${t.m07}, ${t.m08}\n`
+ `]`;
}

Expand Down
9 changes: 5 additions & 4 deletions cocos/core/math/mat4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1825,11 +1825,12 @@ export class Mat4 extends ValueType {
* @return 当前矩阵的字符串表示。
*/
public toString (): string {
const t = this;
return `[\n${
this.m00}, ${this.m01}, ${this.m02}, ${this.m03},\n${
this.m04}, ${this.m05}, ${this.m06}, ${this.m07},\n${
this.m08}, ${this.m09}, ${this.m10}, ${this.m11},\n${
this.m12}, ${this.m13}, ${this.m14}, ${this.m15}\n`
t.m00}, ${t.m01}, ${t.m02}, ${t.m03},\n${
t.m04}, ${t.m05}, ${t.m06}, ${t.m07},\n${
t.m08}, ${t.m09}, ${t.m10}, ${t.m11},\n${
t.m12}, ${t.m13}, ${t.m14}, ${t.m15}\n`
+ ']';
}

Expand Down
16 changes: 16 additions & 0 deletions tests/core/math/mat3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,20 @@ describe('Test Mat3', () => {
log('toEuler: ', v0);
expect(Vec3.equals(v0, expect0)).toBe(true);
});

test('toString', () => {
const m = new Mat3(
12.1234, 0, 44.123433,
55.12234, 6.1230835, 12384.126,
7348.12237, 1283.8, 0.000009
);
const expect0 = `[
12.1234, 0, 44.123433,
55.12234, 6.1230835, 12384.126,
7348.12237, 1283.8, 0.000009
]`;
const s = m.toString();
log('toString: ', s);
expect(s).toBe(expect0);
});
});
16 changes: 16 additions & 0 deletions tests/core/math/mat4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,4 +631,20 @@ describe('Test Mat4', () => {
const r = Mat4.multiplyScalarAndAdd(new Mat4(), b, a, 2);
expect(Mat4.equals(r, res)).toBe(true);
});

test('toString', () => {
const m = new Mat4(
12.1234, 0.002, 44.123433, 55.12234,
6.1230835, 12384.126, 7348.12237, 283.23848943,
1283.8, 0.000009, 0.012384294, 0.18492384,
1284734.123, 0.12841203, 0, 0.00001283
);
const expect0 = `[
12.1234, 0.002, 44.123433, 55.12234,
6.1230835, 12384.126, 7348.12237, 283.23848943,
1283.8, 0.000009, 0.012384294, 0.18492384,
1284734.123, 0.12841203, 0, 0.00001283
]`;
expect(m.toString()).toBe(expect0);
});
});
2 changes: 1 addition & 1 deletion tests/core/math/rect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Test Rect', () => {
});
test('toString', () => {
const rect1 = new Rect(0, 0, 100, 100);
const res = '(0.00, 0.00, 100.00, 100.00)';
const res = '(0, 0, 100, 100)';

expect(rect1.toString()).toBe(res);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/core/math/size.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Test Size', () => {

test('toString', () => {
const size = new Size(100, 100);
expect(size.toString()).toBe('(100.00, 100.00)');
expect(size.toString()).toBe('(100, 100)');
});

});
5 changes: 5 additions & 0 deletions tests/core/math/vec2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ describe('Test Vec2', () => {
expect(vec3.y).toBe(2);
expect(vec3.z).toBe(0);
});

test('toString', () => {
const v = new Vec2(100, 100);
expect(v.toString()).toBe('(100, 100)');
});
});

function polar(angle: number, length: number) {
Expand Down
5 changes: 5 additions & 0 deletions tests/core/math/vec3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,9 @@ describe('Test Vec3', () => {
expect(vec2.x).toBe(1);
expect(vec2.y).toBe(2);
});

test('toString', () => {
const v = new Vec3(100, 100, 1283.3892389);
expect(v.toString()).toBe('(100, 100, 1283.3892389)');
});
});
5 changes: 5 additions & 0 deletions tests/core/math/vec4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,9 @@ describe('Test Vec4', () => {
expect(Vec4.equals(v4_0, v4_1)).toBeTruthy();
expect(Vec4.equals(v4_0, v4_2)).toBeFalsy();
});

test('toString', () => {
const v = new Vec4(100, 100, 1283.3892389, 0);
expect(v.toString()).toBe('(100, 100, 1283.3892389, 0)');
});
});

0 comments on commit c770e54

Please sign in to comment.