divide fix & API add (#5082)

This commit is contained in:
ChiaNing
2019-08-05 13:30:37 +08:00
committed by Weiliang Wang
parent 932663c8f4
commit c31e03e599
12 changed files with 291 additions and 38 deletions
+72 -2
View File
@@ -110,6 +110,17 @@ export class Vec4 extends ValueType {
return out;
}
/**
* @zh 逐元素向量除法
*/
public static divide <Out extends IVec4Like> (out: Out, a: Out, b: Out) {
out.x = a.x / b.x;
out.y = a.y / b.y;
out.z = a.z / b.z;
out.w = a.w / b.w;
return out;
}
/**
* @zh 逐元素向量向上取整
*/
@@ -459,13 +470,23 @@ export class Vec4 extends ValueType {
return new Vec4(this.x, this.y, this.z, this.w);
}
public set (other: Vec4);
public set (x?: number, y?: number, z?: number, w?: number);
/**
* 设置当前向量使其与指定向量相等。
* @param other 相比较的向量。
* @returns `this`
*/
public set (other: Vec4);
/**
* 设置当前向量的具体分量值。
* @param x 要设置的 x 分量的值
* @param y 要设置的 y 分量的值
* @param z 要设置的 z 分量的值
* @param w 要设置的 w 分量的值
* @returns `this`
*/
public set (x?: number, y?: number, z?: number, w?: number);
public set (x?: number | Vec4, y?: number, z?: number, w?: number) {
if (x && typeof x === 'object') {
this.x = x.x;
@@ -494,6 +515,15 @@ export class Vec4 extends ValueType {
Math.abs(this.w - other.w) <= epsilon * Math.max(1.0, Math.abs(this.w), Math.abs(other.w)));
}
/**
* 判断当前向量是否在误差范围内与指定分量的向量相等。
* @param x 相比较的向量的 x 分量。
* @param y 相比较的向量的 y 分量。
* @param z 相比较的向量的 z 分量。
* @param w 相比较的向量的 w 分量。
* @param epsilon 允许的误差,应为非负数。
* @returns 当两向量的各分量都在指定的误差范围内分别相等时,返回 `true`;否则返回 `false`。
*/
public equals4f (x: number, y: number, z: number, w:number, epsilon = EPSILON) {
return (Math.abs(this.x - x) <= epsilon * Math.max(1.0, Math.abs(this.x), Math.abs(x)) &&
Math.abs(this.y - y) <= epsilon * Math.max(1.0, Math.abs(this.y), Math.abs(y)) &&
@@ -510,6 +540,14 @@ export class Vec4 extends ValueType {
return this.x === other.x && this.y === other.y && this.z === other.z && this.w === other.w;
}
/**
* 判断当前向量是否与指定分量的向量相等。
* @param x 指定向量的 x 分量。
* @param y 指定向量的 y 分量。
* @param z 指定向量的 z 分量。
* @param w 指定向量的 w 分量。
* @returns 两向量的各分量都分别相等时返回 `true`;否则返回 `false`。
*/
public strictEquals4f (x: number, y: number, z: number, w:number) {
return this.x === x && this.y === y && this.z === z && this.w === w;
}
@@ -565,6 +603,13 @@ export class Vec4 extends ValueType {
return this;
}
/**
* 向量加法。将当前向量与指定分量的向量相加
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
* @param z 指定的向量的 z 分量。
* @param w 指定的向量的 w 分量。
*/
public add4f (x:number, y:number, z:number, w:number) {
this.x = this.x + x;
this.y = this.y + y;
@@ -585,6 +630,13 @@ export class Vec4 extends ValueType {
return this;
}
/**
* 向量减法。将当前向量减去指定分量的向量
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
* @param z 指定的向量的 z 分量。
* @param w 指定的向量的 w 分量。
*/
public subtract4f (x:number, y:number, z:number, w:number) {
this.x = this.x - x;
this.y = this.y - y;
@@ -619,6 +671,13 @@ export class Vec4 extends ValueType {
return this;
}
/**
* 向量乘法。将当前向量与指定分量的向量相乘的结果赋值给当前向量。
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
* @param z 指定的向量的 z 分量。
* @param w 指定的向量的 w 分量。
*/
public multiply4f (x:number, y:number, z:number, w:number) {
this.x = this.x * x;
this.y = this.y * y;
@@ -627,6 +686,10 @@ export class Vec4 extends ValueType {
return this;
}
/**
* 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
* @param other 指定的向量
*/
public divide (other: Vec4) {
this.x = this.x / other.x;
this.y = this.y / other.y;
@@ -635,6 +698,13 @@ export class Vec4 extends ValueType {
return this;
}
/**
* 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
* @param z 指定的向量的 z 分量。
* @param w 指定的向量的 w 分量。
*/
public divide4f (x:number, y:number, z:number, w:number) {
this.x = this.x / x;
this.y = this.y / y;