示例#1
0
    public static void Set <T>(this T[,,,] array, Index4D index, T value)
    {
        Contracts.Requires.That(array != null);
        Contracts.Requires.That(array.IsIndexValid(index));

        array[index.X, index.Y, index.Z, index.W] = value;
    }
示例#2
0
    public static T Get <T>(this T[,,,] array, Index4D index)
    {
        Contracts.Requires.That(array != null);
        Contracts.Requires.That(array.IsIndexValid(index));

        return(array[index.X, index.Y, index.Z, index.W]);
    }
示例#3
0
        /// <summary>
        /// Handles the array resizing if necessary when an index is accessed.
        /// </summary>
        /// <param name="index">The index being accessed.</param>
        /// <returns>The adjusted index to be used for accessing the backing array.</returns>
        private Index4D HandleArrayResizing(Index4D index)
        {
            int x = index.X;
            int y = index.Y;
            int z = index.Z;
            int w = index.W;

            if (this.IsIndexInCurrentBounds(index))
            {
                x += this.xOrigin;
                y += this.yOrigin;
                z += this.zOrigin;
                w += this.wOrigin;
                return(new Index4D(x, y, z, w));
            }

            // determine size of new array
            int xOffset, yOffset, zOffset, wOffset;
            int xNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.X), ref x, ref this.xOrigin, out xOffset);
            int yNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.Y), ref y, ref this.yOrigin, out yOffset);
            int zNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.Z), ref z, ref this.zOrigin, out zOffset);
            int wNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.W), ref w, ref this.wOrigin, out wOffset);

            // copy old array into new array
            T[,,,] newArray = new T[xNewSize, yNewSize, zNewSize, wNewSize];
            foreach (KeyValuePair <Index4D, T> pair in this.array.GetIndexValuePairs())
            {
                newArray[pair.Key.X + xOffset, pair.Key.Y + yOffset, pair.Key.Z + zOffset, pair.Key.W + wOffset] = pair.Value;
            }

            this.array = newArray;
            return(new Index4D(x, y, z, w));
        }
示例#4
0
        public IndexingBounds4D(Index4D lowerBounds, Index4D dimensions)
        {
            Contracts.Requires.That(dimensions.IsAllPositiveOrZero());

            this.LowerBounds = lowerBounds;
            this.Dimensions  = dimensions;
            this.UpperBounds = lowerBounds + dimensions - new Index4D(1);
        }
示例#5
0
 /// <inheritdoc />
 protected override void SerializeValues(
     TIndexable value, Index4D lowerBounds, Index4D dimensions, byte[] buffer, ref int index)
 {
     foreach (var valueIndex in Index.Range(lowerBounds, dimensions))
     {
         this.ValueSerializer.Serialize(value[valueIndex], buffer, ref index);
     }
 }
示例#6
0
 /// <inheritdoc />
 protected override void DeserializeValues(
     Index4D lowerBounds, Index4D dimensions, byte[] buffer, ref int index, TIndexable result)
 {
     foreach (var resultIndex in Index.Range(lowerBounds, dimensions))
     {
         result[resultIndex] = this.ValueSerializer.Deserialize(buffer, ref index);
     }
 }
示例#7
0
        public static Index4D Get(Index4D index1, Index4D index2, bool roundUp = false)
        {
            int x = MathUtilities.IntegerMidpoint(index1.X, index2.X, roundUp);
            int y = MathUtilities.IntegerMidpoint(index1.Y, index2.Y, roundUp);
            int z = MathUtilities.IntegerMidpoint(index1.Z, index2.Z, roundUp);
            int w = MathUtilities.IntegerMidpoint(index1.W, index2.W, roundUp);

            return(new Index4D(x, y, z, w));
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultidirectionalDynamicArray4D{TValue}"/> class.
        /// </summary>
        /// <param name="dimensions">The dimensions of the array.</param>
        public MultidirectionalDynamicArray4D(Index4D dimensions)
        {
            Contracts.Requires.That(dimensions.IsAllPositive());

            this.array   = new T[dimensions.X, dimensions.Y, dimensions.Z, dimensions.W];
            this.xOrigin = dimensions.X / 2;
            this.yOrigin = dimensions.Y / 2;
            this.zOrigin = dimensions.Z / 2;
            this.wOrigin = dimensions.W / 2;
        }
示例#9
0
        /// <inheritdoc />
        protected override int SerializeValues(
            TIndexable value, Index4D lowerBounds, Index4D dimensions, Action <byte> writeByte)
        {
            int serializedLength = 0;

            foreach (var valueIndex in Index.Range(lowerBounds, dimensions))
            {
                serializedLength += this.ValueSerializer.Serialize(value[valueIndex], writeByte);
            }

            return(serializedLength);
        }
示例#10
0
        /// <inheritdoc />
        public override T this[Index4D index]
        {
            get
            {
                IReadOnlyIndexableContracts.IndexerGet(this, index);

                return(this.array[index.X, index.Y, index.Z, index.W]);
            }

            set
            {
                IIndexableContracts.IndexerSet(this, index);

                this.array[index.X, index.Y, index.Z, index.W] = value;
            }
        }
示例#11
0
        /// <summary>
        /// Generates a sequence of indices that are contained within a specified range.
        /// </summary>
        /// <param name="startIndex">The starting index.</param>
        /// <param name="dimensions">The dimensions of the range to generate.</param>
        /// <returns>An enumerable sequence of the indices inside of the specified range.</returns>
        public static IEnumerable <Index4D> Range(Index4D startIndex, Index4D dimensions)
        {
            Contracts.Requires.That(dimensions.IsAllPositiveOrZero());

            Index4D lastIndex = startIndex + dimensions;

            for (int iW = startIndex.W; iW < lastIndex.W; iW++)
            {
                for (int iZ = startIndex.Z; iZ < lastIndex.Z; iZ++)
                {
                    for (int iY = startIndex.Y; iY < lastIndex.Y; iY++)
                    {
                        for (int iX = startIndex.X; iX < lastIndex.X; iX++)
                        {
                            yield return(new Index4D(iX, iY, iZ, iW));
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Handles the array resizing if necessary when an index is accessed.
        /// </summary>
        /// <param name="index">The index being accessed.</param>
        private void HandleArrayResizing(Index4D index)
        {
            if (this.IsIndexInCurrentBounds(index))
            {
                return;
            }

            // determine size of new array
            int xNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.X), index.X);
            int yNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.Y), index.Y);
            int zNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.Z), index.Z);
            int wNewSize = DynamicArrayUtilities.HandleAxis(this.GetCurrentLength(Axis4D.W), index.W);

            // copy old array into new array
            T[,,,] newArray = new T[xNewSize, yNewSize, zNewSize, wNewSize];

            foreach (KeyValuePair <Index4D, T> entry in this)
            {
                newArray[entry.Key.X, entry.Key.Y, entry.Key.Z, entry.Key.W] =
                    this.array[entry.Key.X, entry.Key.Y, entry.Key.Z, entry.Key.W];
            }

            this.array = newArray;
        }
	/// <summary>
	/// Determines whether the specified index is within the current bounds.
	/// </summary>
	/// <param name="bounds">The bounds to check against.</param>
	/// <param name="index">The index to check.</param>
	/// <returns>
	///   <c>true</c> if the index is within the current bounds; otherwise, <c>false</c>.
	/// </returns>
	public static bool IsIndexInCurrentBounds(this IDynamicIndexingBounds<Index4D> bounds, Index4D index)
	{
		Contracts.Requires.That(bounds != null);

		return index.IsIn(bounds.CurrentLowerBounds, bounds.CurrentUpperBounds);
	}
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Array4D{TValue}"/> class.
 /// </summary>
 /// <param name="dimensions">The dimensions of the array.</param>
 public Array4D(Index4D dimensions)
     : this(new T[dimensions.X, dimensions.Y, dimensions.Z, dimensions.W])
 {
     Contracts.Requires.That(dimensions.IsAllPositiveOrZero());
 }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstantArray4D{TValue}"/> class.
 /// </summary>
 /// <param name="dimensions">The dimensions of the indexable.</param>
 /// <param name="value">The value the indexable will always return.</param>
 /// <param name="setThrowsException">
 /// True if attempting to set the value at an index should throw an exception,
 /// false to just ignore the attempt.
 /// </param>
 public ConstantArray4D(Index4D dimensions, T value, bool setThrowsException = true)
     : base(dimensions, value, setThrowsException)
 {
 }
 /// <inheritdoc />
 protected override Array4D <T> Create(Index4D dimensions) => new Array4D <T>(dimensions);
示例#17
0
 public IndexingBounds4D(Index4D dimensions)
     : this(Index4D.Zero, dimensions)
 {
 }
 /// <inheritdoc />
 public virtual bool TryGetValue(Index4D index, out T value) =>
 ReadOnlyIndexableUtilities.TryGetValue(this, index, out value);
 /// <inheritdoc />
 public abstract T this[Index4D index] {
     get; set;
 }
        /// <inheritdoc />
        public override bool IsIndexValid(Index4D index)
        {
            IReadOnlyIndexableContracts.IsIndexValid(this, index);

            return(index.IsAllPositiveOrZero());
        }
示例#21
0
 public static Vector4 ToXenkoVector(this Index4D index) => new Vector4(index.X, index.Y, index.Z, index.W);
示例#22
0
 /// <inheritdoc />
 protected override DynamicArray4D <T> Create(Index4D dimensions) => new DynamicArray4D <T>(dimensions);
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicArray4D{TValue}"/> class.
        /// </summary>
        /// <param name="dimensions">The dimensions of the array.</param>
        public DynamicArray4D(Index4D dimensions)
        {
            Contracts.Requires.That(dimensions.IsAllPositive());

            this.array = new T[dimensions.X, dimensions.Y, dimensions.Z, dimensions.W];
        }
示例#24
0
    /// <summary>
    /// Determines whether the specified index is valid to use with this array's indexer.
    /// </summary>
    /// <typeparam name="T">The type of values stored in the array.</typeparam>
    /// <param name="array">The array.</param>
    /// <param name="index">The index to check.</param>
    /// <returns>True if the index is valid to use, otherwise false.</returns>
    public static bool IsIndexValid <T>(this T[,,,] array, Index4D index)
    {
        Contracts.Requires.That(array != null);

        return(index.IsIn(array.GetLowerBounds(), array.GetUpperBounds()));
    }
示例#25
0
 /// <inheritdoc />
 protected override MultidirectionalDynamicArray4D <T> Create(Index4D dimensions) =>
 new MultidirectionalDynamicArray4D <T>(dimensions);
示例#26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReadOnlyConstantArray4D{TValue}"/> class.
 /// </summary>
 /// <param name="dimensions">The dimensions of the indexable.</param>
 /// <param name="value">The value the indexable will always return.</param>
 public ReadOnlyConstantArray4D(Index4D dimensions, T value)
     : base(dimensions, value)
 {
 }
        /// <inheritdoc />
        public virtual bool IsIndexValid(Index4D index)
        {
            IReadOnlyIndexableContracts.IsIndexValid(this, index);

            return(this.IsIndexInBounds(index));
        }
 public Array4DSerializer(
     IConstantSerializerDeserializer <T> valueSerializer, Index4D dimensions)
     : base(valueSerializer, new IndexableSerializerOptions <Index4D>(Index4D.Zero, dimensions))
 {
 }
 /// <inheritdoc />
 public virtual bool TrySetValue(Index4D index, T value) =>
 IndexableUtilities.TrySetValue(this, index, value);
 /// <inheritdoc />
 protected override Index4D Subtract(Index4D lhs, Index4D rhs) => lhs - rhs;