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 27 #define crandom() (2 * (random() - 0.5)) 38 float angc(
float a1,
float a2)
57 float fsnap(
float val,
float fsize)
59 return rint(val / fsize) * fsize;
67 vret.x =
rint(point.x / fsize) * fsize;
68 vret.y =
rint(point.y / fsize) * fsize;
69 vret.z =
ceil(point.z / fsize) * fsize;
77 return f0 * (1 - ratio) + f1 * ratio;
81 float lerp(
float t0,
float f0,
float t1,
float f1,
float t)
83 return lerpratio(f0, f1, (t - t0) / (t1 - t0));
90 return ratio < mid ?
lerpratio(f0, f1, ratio / mid) : ratio > mid ?
lerpratio(f1, f2, (ratio - mid) / mid) :
f1;
97 return f0 * (1 - ratio) + f1 * ratio;
104 return ratio < mid ?
lerpvratio(f0, f1, ratio / mid) : ratio > mid ?
lerpvratio(f1, f2, (ratio - mid) / mid) :
f1;
110 return v0 + (v1 - v0) * ((t - t0) / (t1 - t0));
116 return (c - 2 * b + a) * (t * t)
124 return (c - 2 * b + a) * (2 * t)
131 return (((startspeedfactor + endspeedfactor - 2
132 ) * spd - 2 * startspeedfactor - endspeedfactor + 3
133 ) * spd + startspeedfactor
140 if (startspeedfactor < 0 || endspeedfactor < 0)
return false;
151 if (startspeedfactor <= 3 && endspeedfactor <= 3)
return true;
154 float se = startspeedfactor + endspeedfactor;
155 float s_e = startspeedfactor - endspeedfactor;
156 if (3 * (se - 4) * (se - 4) + s_e * s_e <= 12)
205 return f / (
fabs(f) + 1);
218 return (a < c) ?
bound(a, b, c) :
bound(c, b, a);
224 float eps = (
max(a, -a) +
max(b, -b)) * 0.001;
225 return a - b < eps && b - a < eps;
232 return a - b < eps && b - a < eps;
238 float eps = (
max(a, -a) +
max(c, -c)) * 0.001;
239 if (a > c) eps = -eps;
240 return b ==
median(a - eps, b, c + eps);
246 if (halflifedist > 0)
return (0.5 ** ((
bound(mindist, d, maxdist) - mindist) / halflifedist));
247 else if (halflifedist < 0)
return (0.5 ** ((
bound(mindist, d, maxdist) - maxdist) / halflifedist));
251 #define power2of(e) (2 ** e) 260 if (e > 4194304)
return 23;
262 if (e > 2097152)
return 22;
265 if (e > 524288)
return 20;
267 if (e > 262144)
return 19;
271 if (e > 65536)
return 17;
273 if (e > 32768)
return 16;
276 if (e > 8192)
return 14;
278 if (e > 4096)
return 13;
283 if (e > 1024)
return 11;
285 if (e > 512)
return 10;
288 if (e > 128)
return 8;
290 if (e > 64)
return 7;
294 if (e > 16)
return 5;
330 D = b * b - 4 * a * c;
336 v.x = ((-b) - D) / (2 * a);
337 v.y = ((-b) + D) / (2 * a);
341 v.x = (-b + D) / (2 * a);
342 v.y = (-b - D) / (2 * a);
351 if (a > 0) v.y = D / (2 * a);
352 else v.y = -D / (2 * a);
366 float map_ranges(
float value,
float src_min,
float src_max,
float dest_min,
float dest_max) {
367 float src_diff = src_max - src_min;
368 float dest_diff = dest_max - dest_min;
369 float ratio = (value - src_min) / src_diff;
370 return dest_min + dest_diff * ratio;
375 float map_bound_ranges(
float value,
float src_min,
float src_max,
float dest_min,
float dest_max) {
376 if (value <= src_min)
return dest_min;
377 if (value >= src_max)
return dest_max;
378 return map_ranges(value, src_min, src_max, dest_min, dest_max);
ERASEABLE float median(float a, float b, float c)
ERASEABLE bool cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor)
ERASEABLE float almost_in_bounds(float a, float b, float c)
ERASEABLE float float2range11(float f)
continuous function mapping all reals into -1..1
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
ERASEABLE float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d)
ERASEABLE vector lerpv(float t0, vector v0, float t1, vector v1, float t)
ERASEABLE float float2range01(float f)
continuous function mapping all reals into 0..1
ERASEABLE float log2of(float e)
ERASEABLE vector bezier_quadratic_getderivative(vector a, vector b, vector c, float t)
ERASEABLE float lerp(float t0, float f0, float t1, float f1, float t)
ERASEABLE vector bezier_quadratic_getpoint(vector a, vector b, vector c, float t)
ERASEABLE float almost_equals(float a, float b)
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, values between them to the corresponding values between and extrapolates for values outside the range.
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1
ERASEABLE vector lerpvratio(vector f0, vector f1, float ratio)
ERASEABLE float lerpratio(float f0, float f1, float ratio)
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...
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 s2loc s1 s2 f1 f1points f2
ERASEABLE vector lerpv3ratio(vector f0, vector f1, vector f2, float ratio)
ERASEABLE float mean_evaluate(entity e,.float a,.float c, float mean)
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 angc(float a1, float a2)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
ERASEABLE float lerp3ratio(float f0, float f1, float f2, float ratio)
ERASEABLE vector vsnap(vector point, float fsize)
const float FLOAT_EPSILON
ERASEABLE float almost_equals_eps(float a, float b, float times_eps)
ERASEABLE float fsnap(float val, float fsize)