优化vector2构造函数
This commit is contained in:
@@ -250,7 +250,7 @@ module es {
|
||||
*/
|
||||
public static getClosestPointOnRectangleToPoint(rect: Rectangle, point: Vector2) {
|
||||
// 对于每个轴,如果该点在盒子外面,则将在盒子上,否则不理会它
|
||||
let res = new Vector2();
|
||||
let res = es.Vector2.zero;
|
||||
res.x = MathHelper.clamp(point.x, rect.left, rect.right)
|
||||
res.y = MathHelper.clamp(point.y, rect.top, rect.bottom);
|
||||
|
||||
@@ -264,7 +264,7 @@ module es {
|
||||
*/
|
||||
public static getClosestPointOnRectangleBorderToPoint(rect: Rectangle, point: Vector2) {
|
||||
// 对于每个轴,如果该点在盒子外面,则将在盒子上,否则不理会它
|
||||
let res = new Vector2();
|
||||
let res = es.Vector2.zero;
|
||||
res.x = MathHelper.clamp(point.x, rect.left, rect.right)
|
||||
res.y = MathHelper.clamp(point.y, rect.top, rect.bottom);
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ module es {
|
||||
* @param d
|
||||
* @param intersection
|
||||
*/
|
||||
public static getRayIntersection(a: Vector2, b: Vector2, c: Vector2, d: Vector2, intersection: Vector2 = new Vector2()) {
|
||||
public static getRayIntersection(a: Vector2, b: Vector2, c: Vector2, d: Vector2, intersection: Vector2 = es.Vector2.zero) {
|
||||
let dy1 = b.y - a.y;
|
||||
let dx1 = b.x - a.x;
|
||||
let dy2 = d.y - c.y;
|
||||
@@ -99,7 +99,7 @@ module es {
|
||||
public static normalize(vec: Vector2) {
|
||||
let magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
|
||||
if (magnitude > MathHelper.Epsilon) {
|
||||
vec.divide(new Vector2(magnitude));
|
||||
vec.divideScaler(magnitude);
|
||||
} else {
|
||||
vec.x = vec.y = 0;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ module es {
|
||||
* @param matrix
|
||||
* @param result
|
||||
*/
|
||||
public static transformR(position: Vector2, matrix: Matrix2D, result: Vector2 = new Vector2()) {
|
||||
public static transformR(position: Vector2, matrix: Matrix2D, result: Vector2 = es.Vector2.zero) {
|
||||
let x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
||||
let y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
||||
result.x = x;
|
||||
|
||||
Reference in New Issue
Block a user