新增MathHelper.toInt

This commit is contained in:
YHH
2022-03-12 09:13:06 +08:00
parent 131df181e6
commit 5dca337b92
7 changed files with 22 additions and 18 deletions

View File

@@ -17,7 +17,7 @@ module es {
res.range = this._points.length - 4;
} else {
t = MathHelper.clamp01(t) * this._curveCount;
res.range = Math.floor(t);
res.range = MathHelper.toInt(t);
t -= res.range;
res.range *= 3;
}

View File

@@ -471,7 +471,7 @@ module es {
}
public static floorToInt(f: number) {
return Math.trunc(Math.floor(f));
return this.toInt(Math.floor(f));
}
/**
@@ -675,5 +675,9 @@ module es {
public static fromAngle(angle: number) {
return new Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual();
}
public static toInt(val: number){
return val>0 ? Math.floor(val):Math.ceil(val);
}
}
}

View File

@@ -146,8 +146,6 @@ module es {
* @param layerMask
*/
public static linecast(start: Vector2, end: Vector2, layerMask: number = this.allLayers, ignoredColliders: Set<Collider> = null): RaycastHit {
this._hitArray[0].reset();
this.linecastAll(start, end, this._hitArray, layerMask);
this._hitArray[0].reset();
Physics.linecastAll(
start,
@@ -156,7 +154,7 @@ module es {
layerMask,
ignoredColliders
);
return this._hitArray[0].clone();
return this._hitArray[0];
}
/**

View File

@@ -183,11 +183,11 @@ module es {
while (currentCell.x != lastCell.x || currentCell.y != lastCell.y) {
if (tMaxX < tMaxY) {
currentCell.x = MathHelper.approach(currentCell.x, lastCell.x, Math.abs(stepX));
currentCell.x = MathHelper.toInt(MathHelper.approach(currentCell.x, lastCell.x, Math.abs(stepX)));
tMaxX += tDeltaX;
} else {
currentCell.y = MathHelper.approach(currentCell.y, lastCell.y, Math.abs(stepY));
currentCell.y = MathHelper.toInt(MathHelper.approach(currentCell.y, lastCell.y, Math.abs(stepY)));
tMaxY += tDeltaY;
}
@@ -427,7 +427,7 @@ module es {
return false;
// 所有处理单元完成。对结果进行排序并将命中结果打包到结果数组中
this._cellHits.sort(RaycastResultParser.compareRaycastHits);
this._cellHits = this._cellHits.sort(RaycastResultParser.compareRaycastHits);
for (let i = 0; i < this._cellHits.length; i++) {
this._hits[this.hitCounter] = this._cellHits[i];