public void CopyConstructorWorks() {
			 var source = new Int16Array(new short[] { 3, 8, 4 });
			 var arr = new Int16Array(source);
			 Assert.IsTrue(arr != source, "New object");
			 Assert.IsTrue((object)arr is Int16Array, "is Int16Array");
			 AssertContent(arr, new[] { 3, 8, 4 }, "content");
		}
		public void ArrayBufferWithOffsetConstructorWorks() {
			var buf = new ArrayBuffer(80);
			var arr = new Int16Array(buf, 16);
			Assert.IsTrue((object)arr is Int16Array);
			Assert.IsTrue(arr.Buffer == buf, "buffer");
			Assert.AreEqual(arr.Length, 32, "length");
		}
		private void AssertContent(Int16Array actual, int[] expected, string message) {
			if (actual.Length != expected.Length) {
				Assert.Fail(message + ": Expected length " + expected.Length + ", actual: " + actual.Length);
				return;
			}
			for (int i = 0; i < expected.Length; i++) {
				if (actual[i] != expected[i]) {
					Assert.Fail(message + ": Position " + i + ": expected " + expected[i] + ", actual: " + actual[i]);
					return;
				}
			}
			Assert.IsTrue(true, message);
		}
		public void TypePropertiesAreCorrect() {
			Assert.AreEqual(typeof(Int16Array).FullName, "Int16Array", "FullName");

			var interfaces = typeof(Int16Array).GetInterfaces();
			Assert.AreEqual(interfaces.Length, 3, "Interface count should be 3");
			Assert.IsTrue(interfaces.Contains(typeof(IEnumerable<short>)), "Interfaces should contain IEnumerable<short>");
			Assert.IsTrue(interfaces.Contains(typeof(ICollection<short>)), "Interfaces should contain ICollection<short>");
			Assert.IsTrue(interfaces.Contains(typeof(IList<short>)), "Interfaces should contain IList<short>");

			object arr = new Int16Array(0);
			Assert.IsTrue(arr is Int16Array, "Is Int16Array");
			Assert.IsTrue(arr is IEnumerable<short>, "Is IEnumerable<short>");
			Assert.IsTrue(arr is ICollection<short>, "Is ICollection<short>");
			Assert.IsTrue(arr is IList<short>, "Is IList<short>");
		}
Пример #5
0
        public static Func <int, T> GetGetter <T>(IArrowArray array)
        {
            if (array is null)
            {
                return(null);
            }

            // TODO: determine fastest way to read out a value from the array.

            if (typeof(T) == typeof(bool))
            {
                var booleanArray = new BooleanArray(array.Data);
                return((Func <int, T>)(object) new Func <int, bool>(
                           index => booleanArray.GetBoolean(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(bool?))
            {
                var booleanArray = new BooleanArray(array.Data);
                return((Func <int, T>)(object) new Func <int, bool?>(booleanArray.GetBoolean));
            }

            if (typeof(T) == typeof(sbyte))
            {
                var int8Array = new Int8Array(array.Data);
                return((Func <int, T>)(object) new Func <int, sbyte>(
                           index => int8Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(sbyte?))
            {
                var int8Array = new Int8Array(array.Data);
                return((Func <int, T>)(object) new Func <int, sbyte?>(int8Array.GetValue));
            }

            if (typeof(T) == typeof(byte))
            {
                var uint8Array = new UInt8Array(array.Data);
                return((Func <int, T>)(object) new Func <int, byte>(
                           index => uint8Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(byte?))
            {
                var uint8Array = new UInt8Array(array.Data);
                return((Func <int, T>)(object) new Func <int, byte?>(uint8Array.GetValue));
            }

            if (typeof(T) == typeof(short))
            {
                var int16Array = new Int16Array(array.Data);
                return((Func <int, T>)(object) new Func <int, short>(
                           index => int16Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(short?))
            {
                var int16Array = new Int16Array(array.Data);
                return((Func <int, T>)(object) new Func <int, short?>(int16Array.GetValue));
            }

            if (typeof(T) == typeof(ushort))
            {
                var uint16Array = new UInt16Array(array.Data);
                return((Func <int, T>)(object) new Func <int, ushort>(
                           index => uint16Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(ushort?))
            {
                var uint16Array = new UInt16Array(array.Data);
                return((Func <int, T>)(object) new Func <int, ushort?>(uint16Array.GetValue));
            }

            if (typeof(T) == typeof(int))
            {
                var int32Array = new Int32Array(array.Data);
                return((Func <int, T>)(object) new Func <int, int>(
                           index => int32Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(int?))
            {
                var int32Array = new Int32Array(array.Data);
                return((Func <int, T>)(object) new Func <int, int?>(int32Array.GetValue));
            }

            if (typeof(T) == typeof(uint))
            {
                var uint32Array = new UInt32Array(array.Data);
                return((Func <int, T>)(object) new Func <int, uint>(
                           index => uint32Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(uint?))
            {
                var uint32Array = new UInt32Array(array.Data);
                return((Func <int, T>)(object) new Func <int, uint?>(uint32Array.GetValue));
            }

            if (typeof(T) == typeof(long))
            {
                var int64Array = new Int64Array(array.Data);
                return((Func <int, T>)(object) new Func <int, long>(
                           index => int64Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(long?))
            {
                var int64Array = new Int64Array(array.Data);
                return((Func <int, T>)(object) new Func <int, long?>(int64Array.GetValue));
            }

            if (typeof(T) == typeof(ulong))
            {
                var uint64Array = new UInt64Array(array.Data);
                return((Func <int, T>)(object) new Func <int, ulong>(
                           index => uint64Array.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(ulong?))
            {
                var uint64Array = new UInt64Array(array.Data);
                return((Func <int, T>)(object) new Func <int, ulong?>(uint64Array.GetValue));
            }

            if (typeof(T) == typeof(double))
            {
                var doubleArray = new DoubleArray(array.Data);
                return((Func <int, T>)(object) new Func <int, double>(
                           index => doubleArray.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(double?))
            {
                var doubleArray = new DoubleArray(array.Data);
                return((Func <int, T>)(object) new Func <int, double?>(doubleArray.GetValue));
            }

            if (typeof(T) == typeof(float))
            {
                var floatArray = new FloatArray(array.Data);
                return((Func <int, T>)(object) new Func <int, float>(
                           index => floatArray.GetValue(index).GetValueOrDefault()));
            }
            if (typeof(T) == typeof(float?))
            {
                var floatArray = new FloatArray(array.Data);
                return((Func <int, T>)(object) new Func <int, float?>(floatArray.GetValue));
            }

            if (typeof(T) == typeof(DateTime))
            {
                if (array.Data.DataType.TypeId == ArrowTypeId.Date32)
                {
                    var date32Array = new Date32Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTime>(
                               index => date32Array.GetDate(index).GetValueOrDefault().DateTime));
                }
                else if (array.Data.DataType.TypeId == ArrowTypeId.Date64)
                {
                    var date64Array = new Date64Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTime>(
                               index => date64Array.GetDate(index).GetValueOrDefault().DateTime));
                }
            }
            if (typeof(T) == typeof(DateTime?))
            {
                if (array.Data.DataType.TypeId == ArrowTypeId.Date32)
                {
                    var date32Array = new Date32Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTime?>(
                               index => date32Array.GetDate(index)?.DateTime));
                }
                else if (array.Data.DataType.TypeId == ArrowTypeId.Date64)
                {
                    var date64Array = new Date64Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTime?>(
                               index => date64Array.GetDate(index)?.DateTime));
                }
            }

            if (typeof(T) == typeof(DateTimeOffset))
            {
                if (array.Data.DataType.TypeId == ArrowTypeId.Date32)
                {
                    var date32Array = new Date32Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTimeOffset>(
                               index => date32Array.GetDate(index).GetValueOrDefault()));
                }
                else if (array.Data.DataType.TypeId == ArrowTypeId.Date64)
                {
                    var date64Array = new Date64Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTimeOffset>(
                               index => date64Array.GetDate(index).GetValueOrDefault()));
                }
            }
            if (typeof(T) == typeof(DateTimeOffset?))
            {
                if (array.Data.DataType.TypeId == ArrowTypeId.Date32)
                {
                    var date32Array = new Date32Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTimeOffset?>(
                               date32Array.GetDate));
                }
                else if (array.Data.DataType.TypeId == ArrowTypeId.Date64)
                {
                    var date64Array = new Date64Array(array.Data);
                    return((Func <int, T>)(object) new Func <int, DateTimeOffset?>(
                               date64Array.GetDate));
                }
            }

            if (typeof(T) == typeof(TimeSpan))
            {
                var timestampArray = new TimestampArray(array.Data);
                return((Func <int, T>)(object) new Func <int, TimeSpan>(
                           index => timestampArray.GetTimestamp(index).GetValueOrDefault().TimeOfDay));
            }
            if (typeof(T) == typeof(TimeSpan?))
            {
                var timestampArray = new TimestampArray(array.Data);
                return((Func <int, T>)(object) new Func <int, TimeSpan?>(
                           index => timestampArray.GetTimestamp(index)?.TimeOfDay));
            }

            if (typeof(T) == typeof(byte[]))
            {
                var binaryArray = new BinaryArray(array.Data);
                return((Func <int, T>)(object) new Func <int, byte[]>(
                           // TODO: how to avoid this allocation/copy?
                           index => binaryArray.GetBytes(index).ToArray()));
            }

            if (typeof(T) == typeof(string))
            {
                var stringArray = new StringArray(array.Data);
                return((Func <int, T>)(object) new Func <int, string>(
                           index => stringArray.GetString(index)));
            }

            // It's something else we don't yet support.
            switch (array.Data.DataType.TypeId)
            {
            case ArrowTypeId.Decimal:
            case ArrowTypeId.Dictionary:
            case ArrowTypeId.FixedSizedBinary:
            case ArrowTypeId.HalfFloat:
            case ArrowTypeId.Interval:
            case ArrowTypeId.List:
            case ArrowTypeId.Map:
            case ArrowTypeId.Null:
            case ArrowTypeId.Struct:
            case ArrowTypeId.Time32:
            case ArrowTypeId.Time64:
            case ArrowTypeId.Union:
            default:
                // TODO: support additional types?
                throw new NotSupportedException(
                          $"Not supported array type: {array.Data.DataType.TypeId}");
            }
        }
		public void SubarrayWithBeginAndEndWorks() {
			var source = new Int16Array(10);
			var arr = source.Subarray(3, 7);
			Assert.IsFalse(arr == source, "Should be a new array");
			Assert.IsTrue(arr.Buffer == source.Buffer, "Should be the same buffer");
			Assert.AreEqual(arr.ByteOffset, 6, "ByteOffset should be correct");
			Assert.AreEqual(arr.Length, 4, "Length should be correct");
		}
Пример #7
0
        public static Int16Array Int16ArrayFrom()
        {
            var array = new short[50];

            return(Int16Array.From(array));
        }
Пример #8
0
 public void Visit(Int16Array array) => CreateBuffers(array);
Пример #9
0
        public static void TestUseCase()
        {
            var isSpecialTypeName = BrowserHelper.IsPhantomJs();

            var v1       = new Float32Array(1);
            var thisType = "Float32Array";

            Assert.True(v1 != null, thisType + " created");
            var thisName = isSpecialTypeName ? "Object" : thisType;

            Assert.AreEqual(thisName, v1.GetType().FullName, thisType + " class name");

            var v2 = new Float64Array(1);

            thisType = "Float64Array";
            Assert.True(v2 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v2.GetType().FullName, thisType + " class name");

            var v3 = new Int16Array(1);

            thisType = "Int16Array";
            Assert.True(v3 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v3.GetType().FullName, thisType + " class name");

            var v4 = new Int32Array(1);

            thisType = "Int32Array";
            Assert.True(v4 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v4.GetType().FullName, thisType + " class name");

            var v5 = new Int8Array(1);

            thisType = "Int8Array";
            Assert.True(v5 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v5.GetType().FullName, thisType + " class name");

            var v6 = new Uint16Array(1);

            thisType = "Uint16Array";
            Assert.True(v6 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v6.GetType().FullName, thisType + " class name");

            var v7 = new Uint32Array(1);

            thisType = "Uint32Array";
            Assert.True(v7 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v7.GetType().FullName, thisType + " class name");

            var v8 = new Uint8Array(1);

            thisType = "Uint8Array";
            Assert.True(v8 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v8.GetType().FullName, thisType + " class name");

            var v9 = new Uint8ClampedArray(1);

            thisType = "Uint8ClampedArray";
            Assert.True(v9 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            Assert.AreEqual(thisName, v9.GetType().FullName, thisType + " class name");
        }
Пример #10
0
 public bool Get(string name, Int16Array data)
 {
     var ss = new ScriptString(name);
     return Global_GetAnyData(ss.ThisPtr, data.ThisPtr);
 }
Пример #11
0
        public void LengthWorks()
        {
            var arr = new Int16Array(13);

            Assert.AreEqual(13, arr.Length, "Length");
        }
		public void GetEnumeratorWorks() {
			var arr = new Int16Array(new short[] { 3, 6, 2, 9, 5 });
			var l = new List<int>();
			var enm = arr.GetEnumerator();
			while (enm.MoveNext()) {
				l.Add(enm.Current);
			}
			Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 });
		}
		public void ForeachWorks() {
			var arr = new Int16Array(new short[] { 3, 6, 2, 9, 5 });
			var l = new List<int>();
			foreach (var i in arr) {
				l.Add(i);
			}
			Assert.AreEqual(l, new[] { 3, 6, 2, 9, 5 });
		}
		public void ContainsWorks() {
			var arr = new Int16Array(new short[] { 3, 6, 2, 9, 5 });
			Assert.IsTrue (arr.Contains(9), "9");
			Assert.IsFalse(arr.Contains(1), "1");
		}
		public void IndexOfWorks() {
			var arr = new Int16Array(new short[] { 3, 6, 2, 9, 5 });
			Assert.AreEqual(arr.IndexOf(9), 3, "9");
			Assert.AreEqual(arr.IndexOf(1), -1, "1");
		}
		public void ByteLengthPropertyWorks() {
			var arr = new Int16Array(23);
			Assert.AreEqual(arr.ByteLength, 46, "Should be correct");
		}
		public void ByteOffsetPropertyWorks() {
			var buf = new ArrayBuffer(100);
			var arr = new Int16Array(buf, 32);
			Assert.AreEqual(arr.ByteOffset, 32, "Should be correct");
		}
		public void BufferPropertyWorks() {
			var buf = new ArrayBuffer(100);
			var arr = new Int16Array(buf);
			Assert.IsTrue(arr.Buffer == buf, "Should be correct");
		}
Пример #19
0
 /// <summary>
 /// Creates a new Int16Array out of the specified Int16Array.
 /// </summary>
 /// <param name="typedArray">Int16Array to use as initial contents to the new array.</param>
 public Int16Array(Int16Array typedArray)
 {
 }
Пример #20
0
        public static void TestUseCase(Assert assert)
        {
            assert.Expect(18);

            var isSpecialTypeName = BrowserHelper.IsPhantomJs();

            var v1       = new Float32Array(1);
            var thisType = "Float32Array";

            assert.Ok(v1 != null, thisType + " created");
            var thisName = isSpecialTypeName ? "Object" : thisType;

            assert.Equal(v1.GetClassName(), thisName, thisType + " class name");

            var v2 = new Float64Array(1);

            thisType = "Float64Array";
            assert.Ok(v2 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v2.GetClassName(), thisName, thisType + " class name");

            var v3 = new Int16Array(1);

            thisType = "Int16Array";
            assert.Ok(v3 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v3.GetClassName(), thisName, thisType + " class name");

            var v4 = new Int32Array(1);

            thisType = "Int32Array";
            assert.Ok(v4 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v4.GetClassName(), thisName, thisType + " class name");

            var v5 = new Int8Array(1);

            thisType = "Int8Array";
            assert.Ok(v5 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v5.GetClassName(), thisName, thisType + " class name");

            var v6 = new Uint16Array(1);

            thisType = "Uint16Array";
            assert.Ok(v6 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v6.GetClassName(), thisName, thisType + " class name");

            var v7 = new Uint32Array(1);

            thisType = "Uint32Array";
            assert.Ok(v7 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v7.GetClassName(), thisName, thisType + " class name");

            var v8 = new Uint8Array(1);

            thisType = "Uint8Array";
            assert.Ok(v8 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v8.GetClassName(), thisName, thisType + " class name");

            var v9 = new Uint8ClampedArray(1);

            thisType = "Uint8ClampedArray";
            assert.Ok(v9 != null, thisType + " created");
            thisName = isSpecialTypeName ? "Object" : thisType;
            assert.Equal(v9.GetClassName(), thisName, thisType + " class name");
        }
		public void LengthConstructorWorks() {
			var arr = new Int16Array(13);
			Assert.IsTrue((object)arr is Int16Array, "is Int16Array");
			Assert.AreEqual(arr.Length, 13, "Length");
		}
Пример #22
0
        public void ByteLengthPropertyWorks()
        {
            var arr = new Int16Array(23);

            Assert.AreEqual(46, arr.ByteLength, "Should be correct");
        }
		public void SetNormalArrayWorks() {
			var arr = new Int16Array(4);
			arr.Set(new short[] { 3, 6, 7 });
			AssertContent(arr, new[] { 3, 6, 7, 0 }, "Content");
		}
Пример #24
0
 /// <summary>
 /// Creates a new Int16Array out of the specified Int16Array.
 /// </summary>
 /// <param name="typedArray">Int16Array to use as initial contents to the new array.</param>
 public Int16Array(Int16Array typedArray)
 {
 }
Пример #25
0
 public void Visit(Int16Array array) => CompareArrays(array);
Пример #26
0
        public static void TestUseCase(Assert assert)
        {
            var isToStringToTypeNameLogic = !BrowserHelper.IsChrome();

            assert.Expect(153);

            var v1 = new Float32Array(10);

            assert.Ok(v1 != null, "Float32Array created");

            v1[1] = 11;
            v1[5] = 5;
            v1[9] = 99;
            assert.Equal(v1[1], 11, "Float32Array indexier works 1");
            assert.Equal(v1[9], 99, "Float32Array indexier works 9");

            // Check just a select number of references inside the Prototype inheritance.
            assert.Ok(v1.Buffer != null, "Float32Array Buffer");
            assert.Equal(v1.ByteLength, 40, "Float32Array ByteLength");
            assert.Equal(v1.ByteOffset, 0, "Float32Array ByteOffset");
            assert.Equal(v1.Length, 10, "Float32Array Length");

            /*
             * Commented out. Reason: Only Firefox implements them.
             * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
             * var mA = v1.Join();
             * v1.Reverse();
             * var mB = v1.Slice();
             * var mC = v1.Sort();
             */

            var expectedToStringFloat32Array1 = isToStringToTypeNameLogic ? "[object Float32Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v1.ToLocaleString(), expectedToStringFloat32Array1, "Float32Array ToLocaleString");
            assert.Equal(v1.ToString(), expectedToStringFloat32Array1, "Float32Array ToString");

            // Some browsers do not support SubArray() with no parameters.
            // At least 'begin' must be provided.
            var subArray11 = v1.SubArray(1);
            var expectedToStringFloat32Array2 = isToStringToTypeNameLogic ? "[object Float32Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray11 != null, "Float32Array SubArray1");
            assert.Equal(subArray11.Length, 9, "Float32Array SubArray1 Length");
            assert.Equal(subArray11.ToString(), expectedToStringFloat32Array2, "Float32Array SubArray1 ToString");
            assert.Equal(subArray11.ByteOffset, 4, "Float32Array SubArray1 ByteOffset");

            var subArray12 = subArray11.SubArray(2, 6);
            var expectedToStringFloat32Array3 = isToStringToTypeNameLogic ? "[object Float32Array]" : "0,0,5,0";

            assert.Ok(subArray12 != null, "Float32Array SubArray2");
            assert.Equal(subArray12.Length, 4, "Float32Array SubArray2 Length");
            assert.Equal(subArray12.ToString(), expectedToStringFloat32Array3, "Float32Array SubArray2 ToString");
            assert.Equal(subArray12.ByteOffset, 12, "Float32Array SubArray2 ByteOffset");

            var v2 = new Float64Array(10);

            assert.Ok(v2 != null, "Float64Array created");

            v2[1] = 11;
            v2[5] = 5;
            v2[9] = 99;
            assert.Equal(v2[1], 11, "Float64Array indexier works 1");
            assert.Equal(v2[9], 99, "Float64Array indexier works 9");

            assert.Ok(v2.Buffer != null, "Float64Array Buffer");
            assert.Equal(v2.ByteLength, 80, "Float64Array ByteLength");
            assert.Equal(v2.ByteOffset, 0, "Float64Array ByteOffset");
            assert.Equal(v2.Length, 10, "Float64Array Length");

            var expectedToStringFloat64Array1 = isToStringToTypeNameLogic ? "[object Float64Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v2.ToLocaleString(), expectedToStringFloat64Array1, "Float64Array ToLocaleString");
            assert.Equal(v2.ToString(), expectedToStringFloat64Array1, "Float64Array ToString");

            var subArray21 = v2.SubArray(1);
            var expectedToStringFloat64Array2 = isToStringToTypeNameLogic ? "[object Float64Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray21 != null, "Float64Array SubArray1");
            assert.Equal(subArray21.Length, 9, "Float64Array SubArray1 Length");
            assert.Equal(subArray21.ToString(), expectedToStringFloat64Array2, "Float64Array SubArray1 ToString");
            assert.Equal(subArray21.ByteOffset, 8, "Float64Array SubArray1 ByteOffset");

            var subArray22 = subArray21.SubArray(2, 6);
            var expectedToStringFloat64Array3 = isToStringToTypeNameLogic ? "[object Float64Array]" : "0,0,5,0";

            assert.Ok(subArray22 != null, "Float64Array SubArray2");
            assert.Equal(subArray22.Length, 4, "Float64Array SubArray2 Length");
            assert.Equal(subArray22.ToString(), expectedToStringFloat64Array3, "Float64Array SubArray2 ToString");
            assert.Equal(subArray22.ByteOffset, 24, "Float64Array SubArray2 ByteOffset");

            var v3 = new Int16Array(10);

            assert.Ok(v3 != null, "Int16Array created");

            v3[1] = 11;
            v3[5] = 5;
            v3[9] = 99;
            assert.Equal(v3[1], 11, "Int16Array indexier works 1");
            assert.Equal(v3[9], 99, "Int16Array indexier works 9");

            assert.Ok(v3.Buffer != null, "Int16Array Buffer");
            assert.Equal(v3.ByteLength, 20, "Int16Array ByteLength");
            assert.Equal(v3.ByteOffset, 0, "Int16Array ByteOffset");
            assert.Equal(v3.Length, 10, "Int16Array Length");

            var expectedToStringInt16Array1 = isToStringToTypeNameLogic ? "[object Int16Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v3.ToLocaleString(), expectedToStringInt16Array1, "Int16Array ToLocaleString");
            assert.Equal(v3.ToString(), expectedToStringInt16Array1, "Int16Array ToString");

            var subArray31 = v3.SubArray(1);
            var expectedToStringInt16Array2 = isToStringToTypeNameLogic ? "[object Int16Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray31 != null, "Int16Array SubArray1");
            assert.Equal(subArray31.Length, 9, "Int16Array SubArray1 Length");
            assert.Equal(subArray31.ToString(), expectedToStringInt16Array2, "Int16Array SubArray1 ToString");
            assert.Equal(subArray31.ByteOffset, 2, "Int16Array SubArray1 ByteOffset");

            var subArray32 = subArray31.SubArray(2, 6);
            var expectedToStringInt16Array3 = isToStringToTypeNameLogic ? "[object Int16Array]" : "0,0,5,0";

            assert.Ok(subArray32 != null, "Int16Array SubArray2");
            assert.Equal(subArray32.Length, 4, "Int16Array SubArray2 Length");
            assert.Equal(subArray32.ToString(), expectedToStringInt16Array3, "Int16Array SubArray2 ToString");
            assert.Equal(subArray32.ByteOffset, 6, "Int16Array SubArray2 ByteOffset");

            var v4 = new Int32Array(10);

            assert.Ok(v4 != null, "Int32Array created");

            v4[1] = 11;
            v4[5] = 5;
            v4[9] = 99;
            assert.Equal(v4[1], 11, "Int32Array indexier works 1");
            assert.Equal(v4[9], 99, "Int32Array indexier works 9");

            assert.Ok(v4.Buffer != null, "Int32Array Buffer");
            assert.Equal(v4.ByteLength, 40, "Int32Array ByteLength");
            assert.Equal(v4.ByteOffset, 0, "Int32Array ByteOffset");
            assert.Equal(v4.Length, 10, "Int32Array Length");

            var expectedToStringInt32Array1 = isToStringToTypeNameLogic ? "[object Int32Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v4.ToLocaleString(), expectedToStringInt32Array1, "Int32Array ToLocaleString");
            assert.Equal(v4.ToString(), expectedToStringInt32Array1, "Int32Array ToString");

            var subArray41 = v4.SubArray(1);
            var expectedToStringInt32Array2 = isToStringToTypeNameLogic ? "[object Int32Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray41 != null, "Int32Array SubArray1");
            assert.Equal(subArray41.Length, 9, "Int32Array SubArray1 Length");
            assert.Equal(subArray41.ToString(), expectedToStringInt32Array2, "Int32Array SubArray1 ToString");
            assert.Equal(subArray41.ByteOffset, 4, "Int32Array SubArray1 ByteOffset");

            var subArray42 = subArray41.SubArray(2, 6);
            var expectedToStringInt32Array3 = isToStringToTypeNameLogic ? "[object Int32Array]" : "0,0,5,0";

            assert.Ok(subArray42 != null, "Int32Array SubArray2");
            assert.Equal(subArray42.Length, 4, "Int32Array SubArray2 Length");
            assert.Equal(subArray42.ToString(), expectedToStringInt32Array3, "Int32Array SubArray2 ToString");
            assert.Equal(subArray42.ByteOffset, 12, "Int32Array SubArray2 ByteOffset");

            var v5 = new Int8Array(10);

            assert.Ok(v5 != null, "Int8Array created");

            v5[1] = 11;
            v5[5] = 5;
            v5[9] = 99;
            assert.Equal(v5[1], 11, "Int8Array indexier works 1");
            assert.Equal(v5[9], 99, "Int8Array indexier works 9");

            assert.Ok(v5.Buffer != null, "Int8Array Buffer");
            assert.Equal(v5.ByteLength, 10, "Int8Array ByteLength");
            assert.Equal(v5.ByteOffset, 0, "Int8Array ByteOffset");
            assert.Equal(v5.Length, 10, "Int8Array Length");

            var expectedToStringInt8Array1 = isToStringToTypeNameLogic ? "[object Int8Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v5.ToLocaleString(), expectedToStringInt8Array1, "Int8Array ToLocaleString");
            assert.Equal(v5.ToString(), expectedToStringInt8Array1, "Int8Array ToString");

            var subArray51 = v5.SubArray(1);
            var expectedToStringInt8Array2 = isToStringToTypeNameLogic ? "[object Int8Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray51 != null, "Int8Array SubArray1");
            assert.Equal(subArray51.Length, 9, "Int8Array SubArray1 Length");
            assert.Equal(subArray51.ToString(), expectedToStringInt8Array2, "Int8Array SubArray1 ToString");
            assert.Equal(subArray51.ByteOffset, 1, "Int8Array SubArray1 ByteOffset");

            var subArray52 = subArray51.SubArray(2, 6);
            var expectedToStringInt8Array3 = isToStringToTypeNameLogic ? "[object Int8Array]" : "0,0,5,0";

            assert.Ok(subArray52 != null, "Int8Array SubArray2");
            assert.Equal(subArray52.Length, 4, "Int8Array SubArray2 Length");
            assert.Equal(subArray52.ToString(), expectedToStringInt8Array3, "Int8Array SubArray2 ToString");
            assert.Equal(subArray52.ByteOffset, 3, "Int8Array SubArray2 ByteOffset");

            var v6 = new Uint16Array(10);

            assert.Ok(v6 != null, "Uint16Array created");

            v6[1] = 11;
            v6[5] = 5;
            v6[9] = 99;
            assert.Equal(v6[1], 11, "Uint16Array indexier works 1");
            assert.Equal(v6[9], 99, "Uint16Array indexier works 9");

            assert.Ok(v6.Buffer != null, "Uint16Array Buffer");
            assert.Equal(v6.ByteLength, 20, "Uint16Array ByteLength");
            assert.Equal(v6.ByteOffset, 0, "Uint16Array ByteOffset");
            assert.Equal(v6.Length, 10, "Uint16Array Length");

            var expectedToStringUint16Array1 = isToStringToTypeNameLogic ? "[object Uint16Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v6.ToLocaleString(), expectedToStringUint16Array1, "Uint16Array ToLocaleString");
            assert.Equal(v6.ToString(), expectedToStringUint16Array1, "Uint16Array ToString");

            var subArray61 = v6.SubArray(1);
            var expectedToStringUint16Array2 = isToStringToTypeNameLogic ? "[object Uint16Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray61 != null, "Uint16Array SubArray1");
            assert.Equal(subArray61.Length, 9, "Uint16Array SubArray1 Length");
            assert.Equal(subArray61.ToString(), expectedToStringUint16Array2, "Uint16Array SubArray1 ToString");
            assert.Equal(subArray61.ByteOffset, 2, "Uint16Array SubArray1 ByteOffset");

            var subArray62 = subArray61.SubArray(2, 6);
            var expectedToStringUint16Array3 = isToStringToTypeNameLogic ? "[object Uint16Array]" : "0,0,5,0";

            assert.Ok(subArray62 != null, "Uint16Array SubArray2");
            assert.Equal(subArray62.Length, 4, "Uint16Array SubArray2 Length");
            assert.Equal(subArray62.ToString(), expectedToStringUint16Array3, "Uint16Array SubArray2 ToString");
            assert.Equal(subArray62.ByteOffset, 6, "Uint16Array SubArray2 ByteOffset");

            var v7 = new Uint32Array(10);

            assert.Ok(v7 != null, "Uint32Array created");

            v7[1] = 11;
            v7[5] = 5;
            v7[9] = 99;
            assert.Equal(v7[1], 11, "Uint32Array indexier works 1");
            assert.Equal(v7[9], 99, "Uint32Array indexier works 9");

            assert.Ok(v7.Buffer != null, "Uint32Array Buffer");
            assert.Equal(v7.ByteLength, 40, "Uint32Array ByteLength");
            assert.Equal(v7.ByteOffset, 0, "Uint32Array ByteOffset");
            assert.Equal(v7.Length, 10, "Uint32Array Length");

            var expectedToStringUint32Array1 = isToStringToTypeNameLogic ? "[object Uint32Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v7.ToLocaleString(), expectedToStringUint32Array1, "Uint32Array ToLocaleString");
            assert.Equal(v7.ToString(), expectedToStringUint32Array1, "Uint32Array ToString");

            var subArray71 = v7.SubArray(1);
            var expectedToStringUint32Array2 = isToStringToTypeNameLogic ? "[object Uint32Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray71 != null, "Uint32Array SubArray1");
            assert.Equal(subArray71.Length, 9, "Uint32Array SubArray1 Length");
            assert.Equal(subArray71.ToString(), expectedToStringUint32Array2, "Uint32Array SubArray1 ToString");
            assert.Equal(subArray71.ByteOffset, 4, "Uint32Array SubArray1 ByteOffset");

            var subArray72 = subArray71.SubArray(2, 6);
            var expectedToStringUint32Array3 = isToStringToTypeNameLogic ? "[object Uint32Array]" : "0,0,5,0";

            assert.Ok(subArray72 != null, "Uint32Array SubArray2");
            assert.Equal(subArray72.Length, 4, "Uint32Array SubArray2 Length");
            assert.Equal(subArray72.ToString(), expectedToStringUint32Array3, "Uint32Array SubArray2 ToString");
            assert.Equal(subArray72.ByteOffset, 12, "Uint32Array SubArray2 ByteOffset");

            var v8 = new Uint8Array(10);

            assert.Ok(v8 != null, "Uint8Array created");

            v8[1] = 11;
            v8[5] = 5;
            v8[9] = 99;
            assert.Equal(v8[1], 11, "Uint8Array indexier works 1");
            assert.Equal(v8[9], 99, "Uint8Array indexier works 9");

            assert.Ok(v8.Buffer != null, "Uint8Array Buffer");
            assert.Equal(v8.ByteLength, 10, "Uint8Array ByteLength");
            assert.Equal(v8.ByteOffset, 0, "Uint8Array ByteOffset");
            assert.Equal(v8.Length, 10, "Uint8Array Length");

            var expectedToStringUint8Array1 = isToStringToTypeNameLogic ? "[object Uint8Array]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v8.ToLocaleString(), expectedToStringUint8Array1, "Uint8Array ToLocaleString");
            assert.Equal(v8.ToString(), expectedToStringUint8Array1, "Uint8Array ToString");

            var subArray81 = v8.SubArray(1);
            var expectedToStringUint8Array2 = isToStringToTypeNameLogic ? "[object Uint8Array]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray81 != null, "Uint8Array SubArray1");
            assert.Equal(subArray81.Length, 9, "Uint8Array SubArray1 Length");
            assert.Equal(subArray81.ToString(), expectedToStringUint8Array2, "Uint8Array SubArray1 ToString");
            assert.Equal(subArray81.ByteOffset, 1, "Uint8Array SubArray1 ByteOffset");

            var subArray82 = subArray81.SubArray(2, 6);
            var expectedToStringUint8Array3 = isToStringToTypeNameLogic ? "[object Uint8Array]" : "0,0,5,0";

            assert.Ok(subArray82 != null, "Uint8Array SubArray2");
            assert.Equal(subArray82.Length, 4, "Uint8Array SubArray2 Length");
            assert.Equal(subArray82.ToString(), expectedToStringUint8Array3, "Uint8Array SubArray2 ToString");
            assert.Equal(subArray82.ByteOffset, 3, "Uint8Array SubArray2 ByteOffset");

            var v9 = new Uint8ClampedArray(10);

            assert.Ok(v9 != null, "Uint8ClampedArray created");

            v9[1] = 11;
            v9[5] = 5;
            v9[9] = 99;
            assert.Equal(v9[1], 11, "Uint8ClampedArray indexier works 1");
            assert.Equal(v9[9], 99, "Uint8ClampedArray indexier works 9");

            assert.Ok(v9.Buffer != null, "Uint8ClampedArray Buffer");
            assert.Equal(v9.ByteLength, 10, "Uint8ClampedArray ByteLength");
            assert.Equal(v9.ByteOffset, 0, "Uint8ClampedArray ByteOffset");
            assert.Equal(v9.Length, 10, "Uint8ClampedArray Length");

            var expectedToStringUint8ClampedArray1 = isToStringToTypeNameLogic ? "[object Uint8ClampedArray]" : "0,11,0,0,0,5,0,0,0,99";

            assert.Equal(v9.ToLocaleString(), expectedToStringUint8ClampedArray1, "Uint8ClampedArray ToLocaleString");
            assert.Equal(v9.ToString(), expectedToStringUint8ClampedArray1, "Uint8ClampedArray ToString");

            var subArray91 = v9.SubArray(1);
            var expectedToStringUint8ClampedArray2 = isToStringToTypeNameLogic ? "[object Uint8ClampedArray]" : "11,0,0,0,5,0,0,0,99";

            assert.Ok(subArray91 != null, "Uint8ClampedArray SubArray1");
            assert.Equal(subArray91.Length, 9, "Uint8ClampedArray SubArray1 Length");
            assert.Equal(subArray91.ToString(), expectedToStringUint8ClampedArray2, "Uint8ClampedArray SubArray1 ToString");
            assert.Equal(subArray91.ByteOffset, 1, "Uint8ClampedArray SubArray1 ByteOffset");

            var subArray92 = subArray91.SubArray(2, 6);
            var expectedToStringUint8ClampedArray3 = isToStringToTypeNameLogic ? "[object Uint8ClampedArray]" : "0,0,5,0";

            assert.Ok(subArray92 != null, "Uint8ClampedArray SubArray2");
            assert.Equal(subArray92.Length, 4, "Uint8ClampedArray SubArray2 Length");
            assert.Equal(subArray92.ToString(), expectedToStringUint8ClampedArray3, "Uint8ClampedArray SubArray2 ToString");
            assert.Equal(subArray92.ByteOffset, 3, "Uint8ClampedArray SubArray2 ByteOffset");
        }
		public void IndexingWorks() {
			var arr = new Int16Array(3);
			arr[1] = 42;
			AssertContent(arr, new[] { 0, 42, 0 }, "Content");
			Assert.AreEqual(arr[1], 42, "[1]");
		}
Пример #28
0
 private static void SetTypedArrayShort(JSObject obj)
 {
     short[] buffer = Enumerable.Repeat((short)0x20, 13).ToArray();
     obj.SetObjectProperty("typedArray", Int16Array.From(buffer));
 }
Пример #29
0
        private ArrayBuffer ConvertVertices <T>(T[] data, VertexFormat vertexFormat)
        {
            ArrayBuffer  buffer     = new ArrayBuffer(data.Length * vertexFormat.Stride);
            Int8Array    byteView   = new Int8Array(buffer);
            Uint8Array   ubyteView  = new Uint8Array(buffer);
            Int16Array   shortView  = new Int16Array(buffer);
            Uint16Array  ushortView = new Uint16Array(buffer);
            Int32Array   intView    = new Int32Array(buffer);
            Uint32Array  uintView   = new Uint32Array(buffer);
            Float32Array floatView  = new Float32Array(buffer);
            //Float64Array doubleView = new Float64Array(buffer);

            var attributeNames = GetOwnPropertyNames(data[0]).Where(p => p[0] != '$').ToArray();

            var attributeNameIndex = 0;

            foreach (var vertexAttribute in vertexFormat.Attributes)
            {
                var attributeName         = attributeNames[attributeNameIndex++];
                var attributeElementNames = GetOwnPropertyNames(data[0][attributeName]).Where(p => p[0] != '$').ToArray();
                //Output.WriteLine($"attributeName: {attributeName} | attributeElementNames: {string.Join(", ", attributeElementNames)}"); // Debug

                for (uint i = 0; i < data.Length; i++)
                {
                    uint offset = (uint)(vertexAttribute.Offset + i * vertexFormat.Stride);
                    for (uint j = 0; j < vertexAttribute.Count; j++)
                    {
                        switch (vertexAttribute.Type)
                        {
                        case DataType.Byte:
                            byteView[offset / (uint)vertexAttribute.Type.Size() + j] = (sbyte)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                            break;

                        case DataType.UnsignedByte:
                            ubyteView[offset / (uint)vertexAttribute.Type.Size() + j] = (byte)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                            break;

                        case DataType.Short:
                            shortView[offset / (uint)vertexAttribute.Type.Size() + j] = (short)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                            break;

                        case DataType.UnsignedShort:
                            ushortView[offset / (uint)vertexAttribute.Type.Size() + j] = (ushort)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                            break;

                        case DataType.Int:
                            intView[offset / (uint)vertexAttribute.Type.Size() + j] = (int)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                            break;

                        case DataType.UnsignedInt:
                            uintView[offset / (uint)vertexAttribute.Type.Size() + j] = (uint)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                            break;

                        case DataType.Float:
                            floatView[offset / (uint)vertexAttribute.Type.Size() + j] = (float)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                            break;

                        //case DataType.Double:
                        //	doubleView[offset / (uint)vertexAttribute.Type.Size() + j] = (double)(attributeElementNames.Length == 0 ? data[i][attributeName] : data[i][attributeName][attributeElementNames[j]]);
                        //	break;
                        default:
                            throw new IllegalValueException(typeof(DataType), vertexAttribute.Type);
                        }
                    }
                }
            }

            return(buffer);
        }
Пример #30
0
        public static void CoreTypes()
        {
            var arr = new Uint8ClampedArray(50);

            Assert.Equal(50, arr.Length);
            Assert.Equal(TypedArrayTypeCode.Uint8ClampedArray, arr.GetTypedArrayType());

            var arr1 = new Uint8Array(50);

            Assert.Equal(50, arr1.Length);
            Assert.Equal(TypedArrayTypeCode.Uint8Array, arr1.GetTypedArrayType());

            var arr2 = new Uint16Array(50);

            Assert.Equal(50, arr2.Length);
            Assert.Equal(TypedArrayTypeCode.Uint16Array, arr2.GetTypedArrayType());

            var arr3 = new Uint32Array(50);

            Assert.Equal(50, arr3.Length);
            Assert.Equal(TypedArrayTypeCode.Uint32Array, arr3.GetTypedArrayType());

            var arr4 = new Int8Array(50);

            Assert.Equal(50, arr4.Length);
            Assert.Equal(TypedArrayTypeCode.Int8Array, arr4.GetTypedArrayType());

            var arr5 = new Int16Array(50);

            Assert.Equal(50, arr5.Length);
            Assert.Equal(TypedArrayTypeCode.Int16Array, arr5.GetTypedArrayType());

            var arr6 = new Int32Array(50);

            Assert.Equal(50, arr6.Length);
            Assert.Equal(TypedArrayTypeCode.Int32Array, arr6.GetTypedArrayType());

            var arr7 = new Float32Array(50);

            Assert.Equal(50, arr7.Length);
            Assert.Equal(TypedArrayTypeCode.Float32Array, arr7.GetTypedArrayType());

            var arr8 = new Float64Array(50);

            Assert.Equal(50, arr8.Length);
            Assert.Equal(TypedArrayTypeCode.Float64Array, arr8.GetTypedArrayType());

            var sharedArr40 = new SharedArrayBuffer(40);
            var sharedArr50 = new SharedArrayBuffer(50);

            var arr9 = new Uint8ClampedArray(sharedArr50);

            Assert.Equal(50, arr9.Length);

            var arr10 = new Uint8Array(sharedArr50);

            Assert.Equal(50, arr10.Length);

            var arr11 = new Uint16Array(sharedArr50);

            Assert.Equal(25, arr11.Length);

            var arr12 = new Uint32Array(sharedArr40);

            Assert.Equal(10, arr12.Length);

            var arr13 = new Int8Array(sharedArr50);

            Assert.Equal(50, arr13.Length);

            var arr14 = new Int16Array(sharedArr40);

            Assert.Equal(20, arr14.Length);

            var arr15 = new Int32Array(sharedArr40);

            Assert.Equal(10, arr15.Length);

            var arr16 = new Float32Array(sharedArr40);

            Assert.Equal(10, arr16.Length);

            var arr17 = new Float64Array(sharedArr40);

            Assert.Equal(5, arr17.Length);
        }
		public void SetNormalArrayWithOffsetWorks() {
			var arr = new Int16Array(6);
			arr.Set(new short[] { 3, 6, 7 }, 2);
			AssertContent(arr, new[] { 0, 0, 3, 6, 7, 0 }, "Content");
		}
Пример #32
0
        private void CopyVertexElement <T>(T[] vertices, int startVertex, int numVertices, ArrayBuffer buf, string property, int offset, VertexElementFormat format, int stride)
        {
            // Note that this implementation assumes vertex element format matches the actual struct implementation
            // E.g. Vector4 element must map to a Vector4 field
            // TODO: This could be made more robust by trying to guess how many bytes each property is
            // E.g. if we have Short4 format and 2 fields, assume both are 32-bit instead of 4 16-bit fields
            switch (format)
            {
            case VertexElementFormat.Byte4:
                // assumes struct with 4 byte fields
                var props = object.GetOwnPropertyNames(vertices[0][property]).Where(p => p[0] != '$').ToArray();
                for (var i = 0; i < numVertices; i++)
                {
                    var byte4      = vertices[startVertex + i][property];
                    var startIndex = offset + i * stride;
                    var byteView   = new Uint8Array(buf, (uint)startIndex);
                    byteView[0] = (byte)byte4[props[0]];
                    byteView[1] = (byte)byte4[props[1]];
                    byteView[2] = (byte)byte4[props[2]];
                    byteView[3] = (byte)byte4[props[3]];
                }
                break;

            case VertexElementFormat.Color:
                // assumes struct field with uint field
                props = object.GetOwnPropertyNames(vertices[0][property]).Where(p => p[0] != '$').ToArray();
                for (var i = 0; i < numVertices; i++)
                {
                    var color      = vertices[startVertex + i][property];
                    var startIndex = offset + i * stride;
                    var uintView   = new Uint32Array(buf, (uint)startIndex);
                    uintView[0] = (uint)color[props[0]];
                }
                break;

            case VertexElementFormat.HalfVector2:
            case VertexElementFormat.HalfVector4:
                // TODO
                throw new NotImplementedException();

            case VertexElementFormat.NormalizedShort2:
            case VertexElementFormat.Short2:
            case VertexElementFormat.NormalizedShort4:
            case VertexElementFormat.Short4:
                // assumes struct field with n short fields
                props = object.GetOwnPropertyNames(vertices[0][property]).Where(p => p[0] != '$').ToArray();
                for (var i = 0; i < numVertices; i++)
                {
                    var shorts     = vertices[startVertex + i][property];
                    var startIndex = offset + i * stride;
                    var shortView  = new Int16Array(buf, (uint)startIndex);
                    for (var ci = 0; ci < props.Length; ci++)
                    {
                        shortView[(uint)ci] = (short)shorts[props[ci]];
                    }
                }
                break;

            case VertexElementFormat.Single:
                // assumes direct float field
                props = object.GetOwnPropertyNames(vertices[0][property]).Where(p => p[0] != '$').ToArray();
                for (var i = 0; i < numVertices; i++)
                {
                    var floatVal   = vertices[startVertex + i][property];
                    var startIndex = offset + i * stride;
                    var floatView  = new Float32Array(buf, (uint)startIndex);
                    floatView[0] = (float)floatVal;
                }
                break;

            case VertexElementFormat.Vector2:
            case VertexElementFormat.Vector3:
            case VertexElementFormat.Vector4:
                // assumes struct field with n float fields
                props = object.GetOwnPropertyNames(vertices[0][property]).Where(p => p[0] != '$').ToArray();
                for (var i = 0; i < numVertices; i++)
                {
                    var startIndex = offset + i * stride;
                    var floatView  = new Float32Array(buf, (uint)startIndex);
                    var vec        = vertices[startVertex + i][property];
                    for (var ci = 0; ci < props.Length; ci++)
                    {
                        floatView[(uint)ci] = (float)vec[props[ci]];
                    }
                }

                break;
            }
        }
		public void LengthWorks() {
			var arr = new Int16Array(13);
			Assert.AreEqual(arr.Length, 13, "Length");
		}