Beispiel #1
0
        public static IEnumerable <TSource> SubArraySmart <TSource>(
            this IEnumerable <TSource> enumerable,
            int startIndex, int cycles, int stepsize = 1
            )
        {
            TSource[] final = new TSource[cycles];

            int currentIndex = startIndex;

            for (int i = 0; i < cycles; i++)
            {
                //{TODO} Allow this to handle negative indexes
                currentIndex =
                    MathE.ClampWrap(
                        startIndex + (i * stepsize),
                        0,
                        enumerable.Count()
                        );

                //(startIndex + (i * stepsize))
                //%
                //enumerable.Count(); //Allows our copies to wrap around the array

                final[i] = enumerable.ElementAt(currentIndex);
            }

            return(final.AsEnumerable());
        }
Beispiel #2
0
        public static IEnumerable <TSource> SubArraySmart <TSource>(
            this IEnumerable <TSource> enumerable,
            int startIndex, int cycles, int stepsize = 1
            )
        {
            TSource[] final = new TSource[cycles];

            int currentIndex = startIndex;

            for (int i = 0; i < cycles; i++)
            {
                currentIndex =
                    MathE.ClampWrap(
                        startIndex + (i * stepsize),
                        0,
                        enumerable.Count()
                        );
                final[i] = enumerable.ElementAt(currentIndex);
            }

            return(final.AsEnumerable());
        }