mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
[v3.8.6] Fix toString for math types (#18060)
This commit is contained in:
@@ -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`
|
||||
+ `]`;
|
||||
}
|
||||
|
||||
|
||||
@@ -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`
|
||||
+ ']';
|
||||
}
|
||||
|
||||
|
||||
@@ -917,6 +917,14 @@ export class Quat extends ValueType {
|
||||
const { x, y, z, w } = self;
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Return the information of the quaternion in string.
|
||||
* @zh 返回当前四元数的字符串表示。
|
||||
*/
|
||||
public toString (): string {
|
||||
return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;
|
||||
}
|
||||
}
|
||||
|
||||
const qt_1 = new Quat();
|
||||
|
||||
@@ -387,7 +387,7 @@ export class Rect extends ValueType {
|
||||
*/
|
||||
public toString (): string {
|
||||
const self = this;
|
||||
return `(${self.x.toFixed(2)}, ${self.y.toFixed(2)}, ${self.width.toFixed(2)}, ${self.height.toFixed(2)})`;
|
||||
return `(${self.x}, ${self.y}, ${self.width}, ${self.height})`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -165,7 +165,7 @@ export class Size extends ValueType {
|
||||
* @returns The information of the current size in string
|
||||
*/
|
||||
public toString (): string {
|
||||
return `(${this.width.toFixed(2)}, ${this.height.toFixed(2)})`;
|
||||
return `(${this.width}, ${this.height})`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -561,7 +561,7 @@ export class Vec2 extends ValueType {
|
||||
* @returns The string with vector information
|
||||
*/
|
||||
public toString (): string {
|
||||
return `(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`;
|
||||
return `(${this.x}, ${this.y})`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1007,7 +1007,7 @@ export class Vec3 extends ValueType {
|
||||
* @returns The string with vector information
|
||||
*/
|
||||
public toString (): string {
|
||||
return `(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.z.toFixed(2)})`;
|
||||
return `(${this.x}, ${this.y}, ${this.z})`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -715,7 +715,7 @@ export class Vec4 extends ValueType {
|
||||
* @returns The string with vector information
|
||||
*/
|
||||
public toString (): string {
|
||||
return `(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.z.toFixed(2)}, ${this.w.toFixed(2)})`;
|
||||
return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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)');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)');
|
||||
});
|
||||
});
|
||||
@@ -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)');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user