优化vector2构造函数

This commit is contained in:
yhh
2021-05-24 17:20:27 +08:00
parent 9c7703eb2d
commit da3ab02a8d
20 changed files with 177 additions and 109 deletions

View File

@@ -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);