Ejemplo n.º 1
0
        public static float Wrap01(float value)
        {
            int   n      = Mathf.FloorToInt(value);
            float result = value - n;

            GLDebug.Assert(InRange01(result), "result is not in [0, 1)");
            return(result);
        }
Ejemplo n.º 2
0
        private static IEnumerable <T> PermutationsImpl <T>(int n, Func <int[], T> select)
        {
            if (n == 0)
            {
                yield break;
            }

            var permuation = RangeArray(n);

            if (n == 1)
            {
                yield return(select(permuation.Copy()));

                yield break;
            }

            while (true)
            {
                int index = n - 2;

                GLDebug.Assert(index >= 0, "index must be greater than or equal to 0");
                GLDebug.Assert(index + 1 < permuation.Length, "index + 1 must be smaller than permution length, but index == " + index);

                while (permuation[index] >= permuation[index + 1])                 //while we overflow, we carry over
                {
                    index--;

                    if (index < 0)
                    {
                        yield break;
                    }
                }

                // Find the right most index where the value
                // is smaller than at the current index
                int index2 = n - 1;

                while (permuation[index] >= permuation[index2])
                {
                    index2--;
                }

                Swap(permuation, index, index2);

                ReverseRange(permuation, index + 1, n);

                yield return(select(permuation.Copy()));
            }
        }
Ejemplo n.º 3
0
        public static float Wlerp01(float v1, float v2, float t)
        {
            GLDebug.Assert(InRange(v1, 0, 1), "v1 is not in [0, 1)");
            GLDebug.Assert(InRange(v2, 0, 1), "v2 is not in [0, 1)");

            if (Mathf.Abs(v1 - v2) <= 0.5f)
            {
                return(Mathf.Lerp(v1, v2, t));
            }
            else if (v1 <= v2)
            {
                return(Wrap01(Mathf.Lerp(v1 + 1, v2, t)));
            }
            else
            {
                return(Wrap01(Mathf.Lerp(v1, v2 + 1, t)));
            }
        }