8 if (weight == 0)
return;
9 if (mean == 0) e.(a) *= (value ** weight);
10 else e.(a) += (value ** mean) * weight;
17 if (e.(c) == 0)
return 0;
18 if (mean == 0)
return (e.(a) ** (1.0 / e.(c)));
19 else return ((e.(a) / e.(c)) ** (1.0 / mean));
22#define MEAN_ACCUMULATE(s, prefix, v, w) mean_accumulate(s, prefix##_accumulator, prefix##_count, prefix##_mean, v, w)
23#define MEAN_EVALUATE(s, prefix) mean_evaluate(s, prefix##_accumulator, prefix##_count, prefix##_mean)
24#define MEAN_DECLARE(prefix, m) float prefix##_mean = m; .float prefix##_count, prefix##_accumulator
35float angc(
float a1,
float a2)
54float fsnap(
float val,
float fsize)
56 return rint(val / fsize) * fsize;
64 vret.x =
rint(point.x / fsize) * fsize;
65 vret.y =
rint(point.y / fsize) * fsize;
66 vret.z =
ceil(point.z / fsize) * fsize;
74 return f0 * (1 - ratio) +
f1 * ratio;
78float lerp(
float t0,
float f0,
float t1,
float f1,
float t)
94 return f0 * (1 - ratio) +
f1 * ratio;
107 return v0 + (v1 - v0) * ((t - t0) / (t1 - t0));
113 return (c - 2 * b + a) * (t * t)
121 return (c - 2 * b + a) * (2 * t)
128 return (((startspeedfactor + endspeedfactor - 2
129 ) * spd - 2 * startspeedfactor - endspeedfactor + 3
130 ) * spd + startspeedfactor
137 if (startspeedfactor < 0 || endspeedfactor < 0)
return false;
148 if (startspeedfactor <= 3 && endspeedfactor <= 3)
return true;
151 float se = startspeedfactor + endspeedfactor;
152 float s_e = startspeedfactor - endspeedfactor;
153 if (3 * (se - 4) * (se - 4) + s_e * s_e <= 12)
202 return f / (
fabs(f) + 1);
215 return (a < c) ?
bound(a, b, c) :
bound(c, b, a);
221 float eps = (
max(a, -a) +
max(b, -b)) * 0.001;
222 return a - b < eps && b - a < eps;
229 return a - b < eps && b - a < eps;
235 float eps = (
max(a, -a) +
max(c, -c)) * 0.001;
236 if (a > c) eps = -eps;
237 return b ==
median(a - eps, b, c + eps);
243 if (halflifedist > 0)
return (0.5 ** ((
bound(mindist, d, maxdist) - mindist) / halflifedist));
244 else if (halflifedist < 0)
return (0.5 ** ((
bound(mindist, d, maxdist) - maxdist) / halflifedist));
248#define power2of(e) (2 ** e)
257 if (e > 4194304)
return 23;
259 if (e > 2097152)
return 22;
262 if (e > 524288)
return 20;
264 if (e > 262144)
return 19;
268 if (e > 65536)
return 17;
270 if (e > 32768)
return 16;
273 if (e > 8192)
return 14;
275 if (e > 4096)
return 13;
280 if (e > 1024)
return 11;
282 if (e > 512)
return 10;
285 if (e > 128)
return 8;
287 if (e > 64)
return 7;
291 if (e > 16)
return 5;
327 D = b * b - 4 * a * c;
333 v.x = ((-b) - D) / (2 * a);
334 v.y = ((-b) + D) / (2 * a);
338 v.x = (-b + D) / (2 * a);
339 v.y = (-b - D) / (2 * a);
348 if (a > 0) v.y = D / (2 * a);
349 else v.y = -D / (2 * a);
363float map_ranges(
float value,
float src_min,
float src_max,
float dest_min,
float dest_max) {
364 float src_diff = src_max - src_min;
365 float dest_diff = dest_max - dest_min;
366 float ratio = (value - src_min) / src_diff;
367 return dest_min + dest_diff * ratio;
372float map_bound_ranges(
float value,
float src_min,
float src_max,
float dest_min,
float dest_max) {
373 if (value <= src_min)
return dest_min;
374 if (value >= src_max)
return dest_max;
375 return map_ranges(value, src_min, src_max, dest_min, dest_max);
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
const float FLOAT_EPSILON
ERASEABLE float mean_evaluate(entity e,.float a,.float c, float mean)
ERASEABLE float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
ERASEABLE float lerpratio(float f0, float f1, float ratio)
ERASEABLE void mean_accumulate(entity e,.float a,.float c, float mean, float value, float weight)
ERASEABLE float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float spd)
ERASEABLE float lerp3ratio(float f0, float f1, float f2, float ratio)
ERASEABLE float log2of(float e)
ERASEABLE float map_ranges(float value, float src_min, float src_max, float dest_min, float dest_max)
Maps values between the src and dest range: src_min to dest_min, src_max to dest_max,...
ERASEABLE float angc(float a1, float a2)
ERASEABLE float float2range11(float f)
continuous function mapping all reals into -1..1
ERASEABLE vector lerpv3ratio(vector f0, vector f1, vector f2, float ratio)
ERASEABLE vector vsnap(vector point, float fsize)
ERASEABLE vector lerpv(float t0, vector v0, float t1, vector v1, float t)
ERASEABLE float fsnap(float val, float fsize)
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
ERASEABLE float float2range01(float f)
continuous function mapping all reals into 0..1
ERASEABLE vector bezier_quadratic_getderivative(vector a, vector b, vector c, float t)
ERASEABLE float almost_equals(float a, float b)
ERASEABLE vector bezier_quadratic_getpoint(vector a, vector b, vector c, float t)
ERASEABLE float median(float a, float b, float c)
ERASEABLE float map_bound_ranges(float value, float src_min, float src_max, float dest_min, float dest_max)
Same as map_ranges except that values outside the source range are clamped to min or max.
ERASEABLE bool cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor)
ERASEABLE float almost_in_bounds(float a, float b, float c)
ERASEABLE vector lerpvratio(vector f0, vector f1, float ratio)
ERASEABLE float lerp(float t0, float f0, float t1, float f1, float t)
ERASEABLE float almost_equals_eps(float a, float b, float times_eps)
spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2 f1points f2