private static IEnumerable <Index2D> Spiral(Index2D lowerBounds, Index2D upperBounds)
            {
                Contracts.Requires.That(lowerBounds.X <= upperBounds.X);
                Contracts.Requires.That(lowerBounds.Y <= upperBounds.Y);
                Contracts.Requires.That(MiddleIndex.Get(lowerBounds, upperBounds, RoundUp) == Index2D.Zero);

                return(new Spiral2D(new Spiral2D.Options()
                {
                    Spirals = Math.Max(
                        Math.Max(Math.Abs(lowerBounds.X), Math.Abs(lowerBounds.Y)),
                        Math.Max(Math.Abs(upperBounds.X), Math.Abs(upperBounds.Y))),
                }));
            }
            private static IEnumerable <Index3D> SpiralColumns(Index3D lowerBounds, Index3D upperBounds)
            {
                Contracts.Requires.That(lowerBounds.X <= upperBounds.X);
                Contracts.Requires.That(lowerBounds.Y <= upperBounds.Y);
                Contracts.Requires.That(lowerBounds.Z <= upperBounds.Z);
                Contracts.Requires.That(MiddleIndex.Get(lowerBounds, upperBounds, RoundUp) == Index3D.Zero);

                foreach (var index in Spiral(lowerBounds.ProjectDownYAxis(), upperBounds.ProjectDownYAxis()))
                {
                    yield return(new Index3D(index.X, 0, index.Y));

                    int  yUp          = 1;
                    int  yDown        = -1;
                    bool continueLoop = true;
                    while (continueLoop)
                    {
                        continueLoop = false;

                        if (yUp <= upperBounds.Y)
                        {
                            yield return(new Index3D(index.X, yUp, index.Y));

                            yUp++;
                            continueLoop = true;
                        }

                        if (yDown >= lowerBounds.Y)
                        {
                            yield return(new Index3D(index.X, yDown, index.Y));

                            yDown--;
                            continueLoop = true;
                        }
                    }
                }
            }
    public static Index2D GetMiddleIndex(this IIndexingBounds <Index2D> bounds, bool roundUp = false)
    {
        Contracts.Requires.That(bounds != null);

        return(MiddleIndex.Get(bounds.LowerBounds, bounds.UpperBounds, roundUp));
    }
Exemple #4
0
    public static Index1D GetMiddleIndex <T>(this T[] array, bool roundUp = false)
    {
        Contracts.Requires.That(array != null);

        return(MiddleIndex.Get(array.GetLowerBounds(), array.GetUpperBounds(), roundUp));
    }