框架优化
This commit is contained in:
@@ -7,7 +7,7 @@ module es {
|
||||
* @param c
|
||||
*/
|
||||
public static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2) {
|
||||
return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0;
|
||||
return this.cross(center.sub(a), c.sub(center)) < 0;
|
||||
}
|
||||
|
||||
public static halfVector(): Vector2 {
|
||||
@@ -48,7 +48,7 @@ module es {
|
||||
public static angle(from: Vector2, to: Vector2) {
|
||||
this.normalize(from);
|
||||
this.normalize(to);
|
||||
return Math.acos(MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * MathHelper.Rad2Deg;
|
||||
return Math.acos(MathHelper.clamp(from.dot(to), -1, 1)) * MathHelper.Rad2Deg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,8 +58,8 @@ module es {
|
||||
* @param right
|
||||
*/
|
||||
public static angleBetween(self: Vector2, left: Vector2, right: Vector2) {
|
||||
let one = Vector2.subtract(left, self);
|
||||
let two = Vector2.subtract(right, self);
|
||||
const one = left.sub(self);
|
||||
const two = right.sub(self);
|
||||
return this.angle(one, two);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ module es {
|
||||
* @param radius
|
||||
*/
|
||||
public addCircleOccluder(position: Vector2, radius: number){
|
||||
let dirToCircle = Vector2.subtract(position, this._origin);
|
||||
let dirToCircle = position.sub(this._origin);
|
||||
let angle = Math.atan2(dirToCircle.y, dirToCircle.x);
|
||||
|
||||
let stepSize = Math.PI / this.lineCountForCircleApproximation;
|
||||
|
||||
@@ -13,15 +13,15 @@ module es {
|
||||
|
||||
public static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean {
|
||||
// 如果点在AB的右边,那么外边的三角形是
|
||||
if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0)
|
||||
if (Vector2Ext.cross(point.sub(a), b.sub(a)) < 0)
|
||||
return false;
|
||||
|
||||
// 如果点在BC的右边,则在三角形的外侧
|
||||
if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0)
|
||||
if (Vector2Ext.cross(point.sub(b), c.sub(b)) < 0)
|
||||
return false;
|
||||
|
||||
// 如果点在ca的右边,则在三角形的外面
|
||||
if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0)
|
||||
if (Vector2Ext.cross(point.sub(c), a.sub(c)) < 0)
|
||||
return false;
|
||||
|
||||
// 点在三角形上
|
||||
|
||||
Reference in New Issue
Block a user