/// <summary>
        /// Initializes a new instance of the <see cref="OffsetArray2D{TValue}"/> class.
        /// </summary>
        /// <param name="array">The array to wrap.</param>
        /// <param name="offset">The offset of the zero origin.</param>
        public OffsetArray2D(IBoundedIndexable <Index2D, T> array, Index2D offset)
        {
            Contracts.Requires.That(array != null);

            this.array  = array;
            this.offset = offset;
        }
            public static IReadOnlySet <Index3D> CreateCenteredSpiral(IBoundedIndexable <Index3D, bool> shape)
            {
                Contracts.Requires.That(shape != null);

                shape = OffsetArray.CenterOnZero(shape, RoundUp);
                return(Create(shape, SpiralColumns(shape.LowerBounds, shape.UpperBounds)));
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="Composite3By3By3Array3D{TValue}"/> class.
        /// </summary>
        /// <param name="arrays">The indexable arrays to make the composite indexable out of.</param>
        public Composite3By3By3Array3D(IBoundedIndexable <Index3D, T>[,,] arrays)
        {
            Contracts.Requires.That(arrays != null);
            Contracts.Requires.That(arrays.GetLength(0) == 3);
            Contracts.Requires.That(arrays.GetLength(1) == 3);
            Contracts.Requires.That(arrays.GetLength(2) == 3);
            Contracts.Requires.That(CompositeArray.AreAllSameDimensionsAndZeroBounded(arrays));

            this.arrays = arrays;
            IBoundedIndexable <Index3D, T> array = this.arrays[1, 1, 1];

            this.singleArrayLengthX = array.GetLength(Axis3D.X);
            this.singleArrayLengthY = array.GetLength(Axis3D.Y);
            this.singleArrayLengthZ = array.GetLength(Axis3D.Z);
            Index3D indexingOffset = new Index3D(this.singleArrayLengthX, this.singleArrayLengthY, this.singleArrayLengthZ);

            this.dimensions  = array.Dimensions + (indexingOffset * 2);
            this.lowerBounds = array.LowerBounds - indexingOffset;
            this.upperBounds = array.UpperBounds + indexingOffset;

            this.lowerLimitX = array.LowerBounds.X;
            this.lowerLimitY = array.LowerBounds.Y;
            this.lowerLimitZ = array.LowerBounds.Z;
            this.upperLimitX = array.UpperBounds.X;
            this.upperLimitY = array.UpperBounds.Y;
            this.upperLimitZ = array.UpperBounds.Z;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BoundedIndexableEnumerable{TIndex, TValue}"/> class.
        /// </summary>
        /// <param name="bounds">The bounds used to limit the enumeration.</param>
        /// <param name="enumerable">The enumerable that determines the order in which the indices are enumerated.</param>
        /// <param name="revisitPolicy">The policy for whether or not to re-yield previously enumerated indices again.</param>
        public BoundedIndexableEnumerable(
            IBoundedIndexable <TIndex, TValue> bounds,
            IEnumerable <TIndex> enumerable,
            Revisits revisitPolicy = Revisits.Yield)
        {
            Contracts.Requires.That(bounds != null);
            Contracts.Requires.That(enumerable != null);

            this.bounds     = bounds;
            this.enumerable = enumerable;

            this.maxCount = this.bounds.LowerBounds.CalculateVolume(this.bounds.UpperBounds);

            switch (revisitPolicy)
            {
            case Revisits.Yield:
                this.yieldRevisits = true;
                this.cacheRevisits = false;
                break;

            case Revisits.YieldCached:
                this.yieldRevisits = true;
                this.cacheRevisits = true;
                break;

            case Revisits.DontYield:
                this.yieldRevisits = false;
                this.cacheRevisits = false;
                break;

            default:
                throw InvalidEnumArgument.CreateException(nameof(revisitPolicy), revisitPolicy);
            }
        }
Example #5
0
        public ExteriorSkyIslandMapChunkFactory(
            IRasterChunkConfig <Index2D> config, SkyIslandMaps outOfBoundsValue, bool modifyingThrowsException)
        {
            Contracts.Requires.That(config != null);

            this.outOfBoundsChunk = new ConstantArray2D <SkyIslandMaps>(
                config.Bounds.Dimensions, outOfBoundsValue, modifyingThrowsException);
        }
        /// <summary>
        /// Creates an <see cref="IBoundedIndexable{Index3D, TValue}" /> by combing the specified instances into a composite indexable.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="arrays">The indexable arrays to combine into a composite.</param>
        /// <param name="originOffset">The origin offset for indexing into the composite.</param>
        /// <returns>The composite indexable array.</returns>
        public static IBoundedIndexable <Index3D, T> Create <T>(
            IBoundedIndexable <Index3D, T>[,,] arrays, Index3D originOffset)
        {
            Contracts.Requires.That(arrays != null);
            Contracts.Requires.That(AreAllSameDimensionsAndZeroBounded(arrays));

            return(new CompositeArray3D <T>(arrays, originOffset));
        }
Example #7
0
        public ExteriorVoxelGridChunkFactory(
            IRasterChunkConfig <Index3D> config, TerrainVoxel outOfBoundsValue, bool modifyingThrowsException)
        {
            Contracts.Requires.That(config != null);

            this.outOfBoundsChunk = new ConstantArray3D <TerrainVoxel>(
                config.Bounds.Dimensions, outOfBoundsValue, modifyingThrowsException);
        }
        public SkyIslandMapChunk(ChunkOverheadKey key, IBoundedIndexable <Index2D, SkyIslandMaps> values)
        {
            Contracts.Requires.That(values != null);

            this.Key           = key;
            this.MapsLocalView = values;
            this.MapsStageView = new OffsetArray2D <SkyIslandMaps>(values, values.Dimensions * key.Index);
        }
        public VoxelGridChunk(ChunkKey key, IBoundedIndexable <Index3D, TerrainVoxel> voxels)
        {
            Contracts.Requires.That(voxels != null);

            this.Key             = key;
            this.VoxelsLocalView = voxels;
            this.VoxelsStageView = new OffsetArray3D <TerrainVoxel>(voxels, voxels.Dimensions * key.Index);
        }
        /// <summary>
        /// Creates an <see cref="IBoundedIndexable{Index3D, TValue}"/> by combing the specified instances into a 3 by 1 by 3 indexable.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="arrays">The indexable arrays to combine into a composite.</param>
        /// <returns>The composite indexable array.</returns>
        /// <remarks>
        /// The resulting composite is 3 times wider in both horizontal directions than it is tall. The (0, 0, 0,) origin of the
        /// composite is automatically aligned to the (0, 0, 0) origin of the center most indexable in the composite.
        /// </remarks>
        public static IBoundedIndexable <Index3D, T> Create <T>(IBoundedIndexable <Index3D, T>[,] arrays)
        {
            Contracts.Requires.That(arrays != null);
            Contracts.Requires.That(arrays.GetLength(0) == 3);
            Contracts.Requires.That(arrays.GetLength(1) == 3);
            Contracts.Requires.That(AreAllSameDimensionsAndZeroBounded(arrays));

            return(new Composite3By3Array3D <T>(arrays));
        }
Example #11
0
        public static IBoundedIndexable <Index3D, T> CenterOnZero <T>(
            IBoundedIndexable <Index3D, T> array, bool roundUp = false)
        {
            Contracts.Requires.That(array != null);

            var offset = -array.GetMiddleIndex(roundUp);

            return(offset != Index3D.Zero ? new OffsetArray3D <T>(array, offset) : array);
        }
        public static IVisiblyDisposable CreateCenteredSpiral <TInterest>(
            IInterestMap <Index3D, TInterest> map,
            TInterest interest,
            IObservable <Index3D> origin,
            IBoundedIndexable <Index3D, bool> shape)
        {
            Contracts.Requires.That(map != null);
            Contracts.Requires.That(origin != null);
            Contracts.Requires.That(shape != null);

            return(new AreaOfInterest3D <TInterest>(
                       map, interest, origin, Keys.CreateCenteredSpiral(shape)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CompositeArray3D{TValue}" /> class.
        /// </summary>
        /// <param name="arrays">The indexable arrays to make the composite indexable out of.</param>
        /// <param name="originOffset">The origin offset for indexing into the composite.</param>
        public CompositeArray3D(IBoundedIndexable <Index3D, T>[,,] arrays, Index3D originOffset)
        {
            Contracts.Requires.That(arrays != null);
            Contracts.Requires.That(CompositeArray.AreAllSameDimensionsAndZeroBounded(arrays));

            this.arrays = arrays;
            IBoundedIndexable <Index3D, T> singleArray = this.arrays[0, 0, 0];

            this.singleArrayLengthX = singleArray.GetLength(Axis3D.X);
            this.singleArrayLengthY = singleArray.GetLength(Axis3D.Y);
            this.singleArrayLengthZ = singleArray.GetLength(Axis3D.Z);
            this.originOffset       = originOffset;

            this.dimensions  = singleArray.Dimensions * this.arrays.GetDimensions();
            this.lowerBounds = -this.originOffset;
            this.upperBounds = this.lowerBounds + this.dimensions;
        }
            public static IReadOnlySet <TIndex> Create <TIndex>(
                IBoundedIndexable <TIndex, bool> shape,
                IEnumerable <TIndex> ordering       = null,
                IEqualityComparer <TIndex> comparer = null)
                where TIndex : struct, IIndex
            {
                Contracts.Requires.That(shape != null);

                if (ordering != null)
                {
                    ordering = ordering.Where(index =>
                    {
                        bool isInsideShape;
                        return(shape.TryGetValue(index, out isInsideShape) && isInsideShape);
                    });
                }
                else
                {
                    ordering = shape.Where(pair => pair.Value).Select(pair => pair.Key);
                }

                return(ReadOnlySet.CreateOrdered(ordering, comparer));
            }
 /// <inheritdoc />
 protected override Index2D GetLowerBounds(IBoundedIndexable <Index2D, T> value) => value.LowerBounds;
Example #16
0
        public VoxelGridChunkResources(IBoundedIndexable <Index3D, TerrainVoxel> voxels)
        {
            Contracts.Requires.That(voxels != null);

            this.Voxels = voxels;
        }
 /// <inheritdoc />
 protected override Index2D GetDimensions(IBoundedIndexable <Index2D, T> value) => value.Dimensions;
        public SkyIslandMapChunkResources(IBoundedIndexable <Index2D, SkyIslandMaps> maps)
        {
            Contracts.Requires.That(maps != null);

            this.Maps = maps;
        }