mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-23 05:07:46 +00:00
Support half2 reading/writing
This commit is contained in:
parent
fd43401eae
commit
47649dfff5
1 changed files with 26 additions and 1 deletions
|
@ -62,6 +62,19 @@ impl MDL {
|
||||||
f16::from_f32(vec[3]).to_bits()])
|
f16::from_f32(vec[3]).to_bits()])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn read_half2(cursor: &mut Cursor<ByteSpan>) -> Option<[f32; 2]> {
|
||||||
|
Some([
|
||||||
|
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
|
||||||
|
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32()
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn write_half2<T: BinWriterExt>(cursor: &mut T, vec: &[f32; 2]) -> BinResult<()> {
|
||||||
|
cursor.write_le::<[u16; 2]>(&[
|
||||||
|
f16::from_f32(vec[0]).to_bits(),
|
||||||
|
f16::from_f32(vec[1]).to_bits()])
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn read_uint(cursor: &mut Cursor<ByteSpan>) -> BinResult<[u8; 4]> {
|
pub(crate) fn read_uint(cursor: &mut Cursor<ByteSpan>) -> BinResult<[u8; 4]> {
|
||||||
cursor.read_le::<[u8; 4]>()
|
cursor.read_le::<[u8; 4]>()
|
||||||
}
|
}
|
||||||
|
@ -134,6 +147,19 @@ mod tests {
|
||||||
assert_eq!(MDL::read_half4(&mut read_cursor).unwrap(), a);
|
assert_eq!(MDL::read_half4(&mut read_cursor).unwrap(), a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn half2() {
|
||||||
|
let a = [0.0, 1.0];
|
||||||
|
|
||||||
|
let mut v = vec![];
|
||||||
|
let mut cursor = Cursor::new(&mut v);
|
||||||
|
|
||||||
|
MDL::write_half2(&mut cursor, &a).unwrap();
|
||||||
|
|
||||||
|
let mut read_cursor = Cursor::new(v.as_slice());
|
||||||
|
assert_eq!(MDL::read_half2(&mut read_cursor).unwrap(), a);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn uint() {
|
fn uint() {
|
||||||
let a = [5u8, 0u8, 3u8, 15u8];
|
let a = [5u8, 0u8, 3u8, 15u8];
|
||||||
|
@ -187,7 +213,6 @@ mod tests {
|
||||||
assert_delta!(tangent, a, 0.001);
|
assert_delta!(tangent, a, 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pad_slice() {
|
fn pad_slice() {
|
||||||
let a = [3.0, 0.0, -1.0];
|
let a = [3.0, 0.0, -1.0];
|
||||||
|
|
Loading…
Add table
Reference in a new issue