/// <summary> /// Extracts a double precision rectangle (RectangleD) from a byte array - assumes that /// the called has validated that there is enough space in the byte array for four /// doubles (32 bytes) /// </summary> /// <param name="value">byte array</param> /// <param name="startIndex">start index in the array</param> /// <param name="order">byte order of the doubles to be extracted</param> /// <returns>The RectangleD</returns> protected RectangleD ParseBoundingBox(byte[] value, int startIndex, ProvidedOrder order) { return(new RectangleD(EndianBitConverter.ToDouble(value, startIndex, order), EndianBitConverter.ToDouble(value, startIndex + 8, order), EndianBitConverter.ToDouble(value, startIndex + 16, order), EndianBitConverter.ToDouble(value, startIndex + 24, order))); }
/// <summary> /// Returns a double from eight bytes of a byte array /// </summary> /// <param name="value">bytes to convert</param> /// <param name="startIndex">start index in value</param> /// <param name="order">byte order of value</param> /// <returns>the double</returns> /// <exception cref="ArgumentNullException">Thrown if value is null</exception> /// <exception cref="ArgumentException">Thrown if startIndex is invalid</exception> public static double ToDouble(byte[] value, int startIndex, ProvidedOrder order) { if (value == null) { throw new ArgumentNullException("value"); } if ((startIndex + sizeof(double)) > value.Length) { throw new ArgumentException("startIndex invalid (not enough space in value to extract a double", "startIndex"); } if (BitConverter.IsLittleEndian && (order == ProvidedOrder.Big)) { byte[] toConvert = new byte[sizeof(double)]; Array.Copy(value, startIndex, toConvert, 0, sizeof(double)); Array.Reverse(toConvert); return(BitConverter.ToDouble(toConvert, 0)); } else { return(BitConverter.ToDouble(value, startIndex)); } }
/// <summary> /// Returns a double from eight bytes of a byte array /// </summary> /// <param name="value">bytes to convert</param> /// <param name="startIndex">start index in value</param> /// <param name="order">byte order of value</param> /// <returns>the double</returns> /// <exception cref="ArgumentNullException">Thrown if value is null</exception> /// <exception cref="ArgumentException">Thrown if startIndex is invalid</exception> public static double ToDouble(byte[] value, int startIndex, ProvidedOrder order) { if (value == null) { throw new ArgumentNullException("value"); } if ((startIndex + sizeof(double)) > value.Length) { throw new ArgumentException("startIndex invalid (not enough space in value to extract a double", "startIndex"); } if (BitConverter.IsLittleEndian && (order == ProvidedOrder.Big)) { byte[] toConvert = new byte[sizeof(double)]; Array.Copy(value, startIndex, toConvert, 0, sizeof(double)); Array.Reverse(toConvert); return BitConverter.ToDouble(toConvert, 0); } else { return BitConverter.ToDouble(value, startIndex); } }
/// <summary> /// Extracts a double precision rectangle (RectangleD) from a byte array - assumes that /// the called has validated that there is enough space in the byte array for four /// doubles (32 bytes) /// </summary> /// <param name="value">byte array</param> /// <param name="startIndex">start index in the array</param> /// <param name="order">byte order of the doubles to be extracted</param> /// <returns>The RectangleD</returns> protected RectangleD ParseBoundingBox(byte[] value, int startIndex, ProvidedOrder order) { return new RectangleD(EndianBitConverter.ToDouble(value, startIndex, order), EndianBitConverter.ToDouble(value, startIndex + 8, order), EndianBitConverter.ToDouble(value, startIndex + 16, order), EndianBitConverter.ToDouble(value, startIndex + 24, order)); }