protected int calculateT(ref float t) { int i; if (t >= 1f) { t = 1f; i = p.Length - 4; } else { t = MathExOps.Clamp(t, 0, 1) * (numberOfNodes - 1); i = (int)t; t -= i; i *= 3; } return(i); }
public static IEnumerable <CurveIterator <T> > IterateEquidistant <T>(this curve <T> c, float fraction) { var d = c.distance; float length = d.length; float delta = d.length * fraction; float cd = 0; while (true) { CurveIterator <T> i; i.t = d.time(cd); i.value = c.value(i.t); i.velocity = c.velocity(i.t); yield return(i); if (cd == length) { yield break; } cd = MathExOps.Clamp(cd + delta, 0, length); } }
public static IEnumerable <CurveIterator <T> > Iterate <T>(this curve <T> c, float stepMultiplier) { float sl = c.length; float islsl = 1 / (sl * sl); float t = 0; while (true) { CurveIterator <T> i; i.t = t; i.value = c.value(t); i.velocity = c.velocity(t); yield return(i); if (t == 1) { yield break; } float dt = MathExOps.Clamp(MathTypeTag <T> .Get().scalar(i.velocity) * islsl * stepMultiplier, islsl, 1); t = MathExOps.Clamp01(t + dt); } }
public static int Clamp(this vec2 v, int f) { return(MathExOps.Clamp(f, (int)v.x, (int)v.y)); }
public static vec2i Clamp(this vec2i v, vec2i min, vec2i max) { return(MathExOps.Clamp(v, min, max)); }
public static float Clamp(this vec2i v, float f) { return(MathExOps.Clamp(f, v.x, v.y)); }