修复因Vector2.add/substract/divide/mutiply导致的计算错误
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
module es {
|
||||
export class Rectangle implements IEquatable<Rectangle> {
|
||||
static emptyRectangle: Rectangle = new Rectangle();
|
||||
|
||||
/**
|
||||
* 该矩形的左上角的x坐标
|
||||
*/
|
||||
@@ -26,7 +24,7 @@ module es {
|
||||
* 返回X=0, Y=0, Width=0, Height=0的矩形
|
||||
*/
|
||||
public static get empty(): Rectangle {
|
||||
return this.emptyRectangle;
|
||||
return new Rectangle();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,8 +318,6 @@ module es {
|
||||
* @returns 矩形边框上离点最近的点
|
||||
*/
|
||||
public getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2 {
|
||||
edgeNormal = Vector2.zero;
|
||||
|
||||
// 对于每条轴,如果点在框外,就把它限制在框内,否则就不要管它
|
||||
let res = new Vector2();
|
||||
res.x = MathHelper.clamp(point.x, this.left, this.right);
|
||||
@@ -405,8 +401,8 @@ module es {
|
||||
* @param value2
|
||||
*/
|
||||
public static overlap(value1: Rectangle, value2: Rectangle): Rectangle {
|
||||
let x = Math.max(Math.max(value1.x, value2.x), 0);
|
||||
let y = Math.max(Math.max(value1.y, value2.y), 0);
|
||||
let x = Math.max(value1.x, value2.x, 0);
|
||||
let y = Math.max(value1.y, value2.y, 0);
|
||||
return new Rectangle(x, y,
|
||||
Math.max(Math.min(value1.right, value2.right) - x, 0),
|
||||
Math.max(Math.min(value1.bottom, value2.bottom) - y, 0));
|
||||
@@ -555,5 +551,9 @@ module es {
|
||||
public getHashCode(): number{
|
||||
return (this.x ^ this.y ^ this.width ^ this.height);
|
||||
}
|
||||
|
||||
public clone(): Rectangle {
|
||||
return new Rectangle(this.x, this.y, this.width, this.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ module es {
|
||||
* @param value2
|
||||
*/
|
||||
public static add(value1: Vector2, value2: Vector2) {
|
||||
let result: Vector2 = new Vector2(0, 0);
|
||||
let result: Vector2 = Vector2.zero;
|
||||
result.x = value1.x + value2.x;
|
||||
result.y = value1.y + value2.y;
|
||||
return result;
|
||||
@@ -48,7 +48,7 @@ module es {
|
||||
* @param value2
|
||||
*/
|
||||
public static divide(value1: Vector2, value2: Vector2) {
|
||||
let result: Vector2 = new Vector2(0, 0);
|
||||
let result: Vector2 = Vector2.zero;
|
||||
result.x = value1.x / value2.x;
|
||||
result.y = value1.y / value2.y;
|
||||
return result;
|
||||
@@ -258,5 +258,9 @@ module es {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public clone(): Vector2 {
|
||||
return new Vector2(this.x, this.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
module es {
|
||||
export class Vector3 {
|
||||
public x: number;
|
||||
public y: number;
|
||||
public z: number;
|
||||
|
||||
constructor(x: number, y: number, z: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user