Esempio n. 1
0
        /// <summary>
        /// A helper method to determine if all the indexable arrays have the same dimensions and that their lower bounds are zero.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="arrays">The indexable arrays to check.</param>
        /// <returns>True if all the indexable arrays have the same dimensions and bounds; otherwise false.</returns>
        private static bool AreAllSameDimensionsAndZeroBoundedHelper <T>(IEnumerable <IBoundedReadOnlyIndexable <Index3D, T> > arrays)
        {
            if (arrays == null)
            {
                return(false);
            }

            IBoundedReadOnlyIndexable <Index3D, T> firstValue = arrays.FirstOrDefault();

            if (firstValue == null)
            {
                return(false);
            }

            Index3D dimensions = firstValue.Dimensions;

            foreach (var value in arrays)
            {
                if (value == null ||
                    value.Dimensions != dimensions ||
                    value.LowerBounds != Index3D.Zero)
                {
                    return(false);
                }
            }

            return(true);
        }
        public ContourChunkView(ChunkKey key, IBoundedReadOnlyIndexable <Index3D, TChunk> chunks)
        {
            IContourChunkViewContracts.Constructor(key, chunks);

            this.Key    = key;
            this.Chunks = chunks;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an <see cref="IBoundedReadOnlyIndexable{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 IBoundedReadOnlyIndexable <Index3D, T> Create <T>(
            IBoundedReadOnlyIndexable <Index3D, T>[,,] arrays, Index3D originOffset)
        {
            Contracts.Requires.That(arrays != null);
            Contracts.Requires.That(AreAllSameDimensionsAndZeroBounded(arrays));

            return(new ReadOnlyCompositeArray3D <T>(arrays, originOffset));
        }
 public static void Constructor <TChunk>(
     ChunkKey key, IBoundedReadOnlyIndexable <Index3D, TChunk> chunks)
     where TChunk : IKeyed <ChunkKey>
 {
     Contracts.Requires.That(chunks.AllAndSelfNotNull());
     Contracts.Requires.That(chunks.LowerBounds == new Index3D(-1));
     Contracts.Requires.That(chunks.UpperBounds == new Index3D(1));
     Contracts.Requires.That(chunks.Dimensions == new Index3D(3));
     Contracts.Requires.That(
         Index.Range(new Index3D(-1), new Index3D(3)).All(
             index => chunks[index].Key == new ChunkKey(key.Index + index)),
         $"Each chunk's offset in {nameof(chunks)} must match its Key's offset to {nameof(key)}.");
 }
            public ContourableVoxelView(
                IDisposableValue <IReadOnlyVoxelGridChunk[, , ]> voxelChunkPins,
                Index3D voxelChunkDimensionsInVoxels,
                Index3D stageVoxelIndexOfViewOrigin)
            {
                Contracts.Requires.That(voxelChunkPins != null);

                this.voxelChunkDimensionsInVoxels = voxelChunkDimensionsInVoxels;
                this.stageVoxelIndexOfViewOrigin  = stageVoxelIndexOfViewOrigin;
                this.pins = voxelChunkPins;

                this.voxels = CompositeArray.Create(
                    voxelChunkPins.Value.ConvertAll(chunk => chunk.VoxelsLocalView),
                    this.voxelChunkDimensionsInVoxels);
            }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadOnlyCompositeArray3D{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 ReadOnlyCompositeArray3D(IBoundedReadOnlyIndexable <Index3D, T>[,,] arrays, Index3D originOffset)
        {
            Contracts.Requires.That(arrays != null);
            Contracts.Requires.That(CompositeArray.AreAllSameDimensionsAndZeroBounded(arrays));

            this.arrays = arrays;
            IBoundedReadOnlyIndexable <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;
        }
Esempio n. 7
0
 /// <summary>
 /// Determines if all the indexable arrays have the same dimensions and that their lower bounds are <see cref="Index3D.Zero"/>.
 /// </summary>
 /// <typeparam name="T">The type of the value.</typeparam>
 /// <param name="arrays">The indexable arrays to check.</param>
 /// <returns>True if all the indexable arrays have the same dimensions and bounds; otherwise false.</returns>
 public static bool AreAllSameDimensionsAndZeroBounded <T>(IBoundedReadOnlyIndexable <Index3D, T>[,] arrays)
 {
     return(AreAllSameDimensionsAndZeroBoundedHelper(arrays.Cast <IBoundedReadOnlyIndexable <Index3D, T> >()));
 }