/// <summary> /// Create a new <see cref="UniPoint"/> structure from bytes. /// </summary> /// <param name="bytes">The bytes to convert.</param> /// <param name="isIntBytes">True if the bytes represent 2 32-bit integers.</param> /// <returns></returns> public static UniPoint FromBytes(byte[] bytes, bool isIntBytes) { var up = new UniPoint(); if (isIntBytes && bytes.Length >= sizeof(int) * 2) { up._x = BitConverter.ToInt32(bytes, 0); up._y = BitConverter.ToInt32(bytes, sizeof(int)); return(up); } else if (bytes.Length >= sizeof(float) * 2) { if (bytes.Length >= (sizeof(double) * 2)) { up._x = BitConverter.ToDouble(bytes, 0); up._y = BitConverter.ToDouble(bytes, sizeof(double)); return(up); } else { up._x = BitConverter.ToSingle(bytes, 0); up._y = BitConverter.ToSingle(bytes, sizeof(float)); return(up); } } else { throw new ArgumentException("Not enough bytes", nameof(bytes)); } }
/// <summary> /// Create a new <see cref="UniPoint"/> from a pointer. /// </summary> /// <param name="ptr"></param> /// <returns></returns> public unsafe static UniPoint FromPointer(float *ptr) { var up = new UniPoint(); up._x = *ptr; up._y = *(ptr + sizeof(float)); return(up); }