예제 #1
0
 /// <summary>
 /// Returns a 16-byte set representation of this color.
 /// Inverts <see cref="FromBytes(byte[], int)"/>.
 /// </summary>
 /// <param name="outputBytes">The output byte array.</param>
 /// <param name="offset">The starting offset in the output array.</param>
 public void ToBytes(byte[] outputBytes, int offset)
 {
     PrimitiveConversionHelper.Float32ToBytes(R, outputBytes, offset);
     PrimitiveConversionHelper.Float32ToBytes(G, outputBytes, offset + 4);
     PrimitiveConversionHelper.Float32ToBytes(B, outputBytes, offset + (4 + 4));
     PrimitiveConversionHelper.Float32ToBytes(A, outputBytes, offset + (4 + 4 + 4));
 }
 public static void TestBits()
 {
     if (!BitConverter.IsLittleEndian)
     {
         Assert.Fail("BitConverter identifies this system as big endian, which is not currently supported by the engine!");
     }
     else
     {
         byte[] bI = PrimitiveConversionHelper.Int32ToBytes(1 + 512);
         Assert.That(bI.Length == 4, "Bit length (int->bytes)");
         Assert.That(bI[0] == 1, "Bit contents (int->bytes)[0]");
         Assert.That(bI[1] == 2, "Bit contents (int->bytes)[1]");
         Assert.That(bI[2] == 0, "Bit contents (int->bytes)[2]");
         Assert.That(bI[3] == 0, "Bit contents (int->bytes)[3]");
         byte[] bF = PrimitiveConversionHelper.Float32ToBytes(127.125f);
         Assert.That(bF.Length == 4, "Bit length (float->bytes)");
         Assert.That(bF[0] == 0, "Bit contents (float->bytes)[0]");
         Assert.That(bF[1] == 64, "Bit contents (float->bytes)[1]");
         Assert.That(bF[2] == 254, "Bit contents (float->bytes)[2]");
         Assert.That(bF[3] == 66, "Bit contents (float->bytes)[3]");
         Assert.That(PrimitiveConversionHelper.BytesToDouble64(PrimitiveConversionHelper.Double64ToBytes(1.73e5)) == 1.73e5, "Double parseback validity");
     }
 }
예제 #3
0
 /// <summary>
 /// Write a float (4 bytes).
 /// </summary>
 /// <param name="x">The data.</param>
 public void WriteFloat(float x)
 {
     PrimitiveConversionHelper.Float32ToBytes(x, HelperBytes, 0);
     Internal.Write(HelperBytes, 0, 4);
 }