mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
add approx functions (#252)
This commit is contained in:
@@ -69,6 +69,58 @@ export function approx (a: number, b: number, maxDiff?: number): boolean {
|
||||
return mathAbs(a - b) <= maxDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Tests whether or not the first argument is approximately greater than or equal to the second
|
||||
* @zh 测试第一个参数是否近似大于或等于第二个参数
|
||||
* @param a The first number to test
|
||||
* @param b The second number to test
|
||||
* @param maxDiff Maximum difference (default: EPSILON)
|
||||
* @return True if a is approximately greater than or equal to b, false otherwise
|
||||
*/
|
||||
export function approxGE (a: number, b: number, maxDiff?: number): boolean {
|
||||
maxDiff = maxDiff || EPSILON;
|
||||
return a >= b - maxDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Tests whether or not the first argument is approximately less than or equal to the second
|
||||
* @zh 测试第一个参数是否近似小于或等于第二个参数
|
||||
* @param a The first number to test
|
||||
* @param b The second number to test
|
||||
* @param maxDiff Maximum difference (default: EPSILON)
|
||||
* @return True if a is approximately less than or equal to b, false otherwise
|
||||
*/
|
||||
export function approxLE (a: number, b: number, maxDiff?: number): boolean {
|
||||
maxDiff = maxDiff || EPSILON;
|
||||
return a <= b + maxDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Tests whether or not the first argument is approximately greater than the second
|
||||
* @zh 测试第一个参数是否近似大于第二个参数
|
||||
* @param a The first number to test
|
||||
* @param b The second number to test
|
||||
* @param maxDiff Maximum difference (default: EPSILON)
|
||||
* @return True if a is approximately greater than b, false otherwise
|
||||
*/
|
||||
export function approxGT (a: number, b: number, maxDiff?: number): boolean {
|
||||
maxDiff = maxDiff || EPSILON;
|
||||
return a > b + maxDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Tests whether or not the first argument is approximately less than the second
|
||||
* @zh 测试第一个参数是否近似小于第二个参数
|
||||
* @param a The first number to test
|
||||
* @param b The second number to test
|
||||
* @param maxDiff Maximum difference (default: EPSILON)
|
||||
* @return True if a is approximately less than b, false otherwise
|
||||
*/
|
||||
export function approxLT (a: number, b: number, maxDiff?: number): boolean {
|
||||
maxDiff = maxDiff || EPSILON;
|
||||
return a < b - maxDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Clamps a value between a minimum float and maximum float value.<br/>
|
||||
* @zh 返回最小浮点数和最大浮点数之间的一个数值。可以使用 clamp 函数将不断变化的数值限制在范围内。
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
import { ccclass, type, serializable, editable, range } from 'cc.decorator';
|
||||
import { repeat } from '../core/math';
|
||||
import { approxGE, approxLT, repeat } from '../core/math';
|
||||
import CurveRange from './animator/curve-range';
|
||||
import type { ParticleSystem } from './particle-system';
|
||||
|
||||
@@ -108,7 +108,7 @@ export default class Burst {
|
||||
let preFrameTime = repeat(psys.time - psys.startDelay.evaluate(0, 1), psys.duration) - dt;
|
||||
preFrameTime = (preFrameTime > 0.0) ? preFrameTime : 0.0;
|
||||
const curFrameTime = repeat(psys.time - psys.startDelay.evaluate(0, 1), psys.duration);
|
||||
if (this._curTime >= preFrameTime && this._curTime < curFrameTime) {
|
||||
if (approxGE(this._curTime, preFrameTime) && approxLT(this._curTime, curFrameTime)) {
|
||||
psys.emit(this.count.evaluate(this._curTime / psys.duration, 1), dt - (curFrameTime - this._curTime));
|
||||
this._curTime += this.repeatInterval;
|
||||
--this._remainingCount;
|
||||
|
||||
Reference in New Issue
Block a user