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
+57 -3
View File
@@ -102,6 +102,15 @@ export class Vec2 extends ValueType {
return out;
}
/**
* @zh 逐元素向量除法
*/
public static divide <Out extends IVec2Like> (out: Out, a: Out, b: Out) {
out.x = a.x / b.x;
out.y = a.y / b.y;
return out;
}
/**
* @zh 逐元素向量向上取整
*/
@@ -401,13 +410,21 @@ export class Vec2 extends ValueType {
return new Vec2(this.x, this.y);
}
public set (other: Vec2);
public set (x?:number, y?:number);
/**
* 设置当前向量使其与指定向量相等。
* @param other 相比较的向量。
* @returns `this`
*/
public set (other: Vec2);
/**
* 设置当前向量的具体分量值。
* @param x 要设置的 x 分量的值
* @param y 要设置的 y 分量的值
* @returns `this`
*/
public set (x?:number, y?:number);
public set (x?: number | Vec2, y?: number) {
if (x && typeof x === 'object') {
this.x = x.x;
@@ -422,7 +439,7 @@ export class Vec2 extends ValueType {
/**
* 判断当前向量是否在误差范围内与指定向量相等。
* @param other 相比较的向量。
* @param variance 允许的误差,应为非负数。
* @param epsilon 允许的误差,应为非负数。
* @returns 当两向量的各分量都在指定的误差范围内分别相等时,返回 `true`;否则返回 `false`。
*/
public equals (other: Vec2, epsilon = EPSILON) {
@@ -434,6 +451,13 @@ export class Vec2 extends ValueType {
);
}
/**
* 判断当前向量是否在误差范围内与指定分量的向量相等。
* @param x 相比较的向量的 x 分量。
* @param y 相比较的向量的 y 分量。
* @param epsilon 允许的误差,应为非负数。
* @returns 当两向量的各分量都在指定的误差范围内分别相等时,返回 `true`;否则返回 `false`。
*/
public equals2f (x: number, y: number, epsilon = EPSILON) {
return (
Math.abs(this.x - x) <=
@@ -452,6 +476,12 @@ export class Vec2 extends ValueType {
return other && this.x === other.x && this.y === other.y;
}
/**
* 判断当前向量是否与指定分量的向量相等。
* @param x 指定向量的 x 分量。
* @param y 指定向量的 y 分量。
* @returns 两向量的各分量都分别相等时返回 `true`;否则返回 `false`。
*/
public strictEquals2f (x:number, y:number) {
return this.x === x && this.y === y;
}
@@ -499,6 +529,11 @@ export class Vec2 extends ValueType {
return this;
}
/**
* 向量加法。将当前向量与指定分量的向量相加
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public add2f (x:number, y:number) {
this.x = this.x + x;
this.y = this.y + y;
@@ -515,6 +550,11 @@ export class Vec2 extends ValueType {
return this;
}
/**
* 向量减法。将当前向量减去指定分量的向量
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public subtract2f (x:number, y:number) {
this.x = this.x - x;
this.y = this.y - y;
@@ -543,18 +583,32 @@ export class Vec2 extends ValueType {
return this;
}
/**
* 向量乘法。将当前向量与指定分量的向量相乘的结果赋值给当前向量。
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public multiply2f (x:number, y:number) {
this.x = this.x * x;
this.y = this.y * y;
return this;
}
/**
* 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
* @param other 指定的向量
*/
public divide (other: Vec2) {
this.x = this.x / other.x;
this.y = this.y / other.y;
return this;
}
/**
* 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public divide2f (x:number, y:number) {
this.x = this.x / x;
this.y = this.y / y;