use std::{
fs::File,
io,
io::{BufReader, ErrorKind, Read, Write},
path::Path,
};
use lin_alg::f32::Vec3;
use crate::snapshot::Snapshot;
fn write_u32_le(out: &mut Vec<u8>, v: u32) {
out.extend_from_slice(&v.to_le_bytes());
}
fn write_f32_le(out: &mut Vec<u8>, v: f32) {
out.extend_from_slice(&v.to_le_bytes());
}
fn write_vec3s(out: &mut Vec<u8>, xs: &[Vec3]) {
for p in xs {
write_f32_le(out, p.x);
write_f32_le(out, p.y);
write_f32_le(out, p.z);
}
}
fn read_vec3s(bytes: &[u8], i: &mut usize, count: usize) -> io::Result<Vec<Vec3>> {
let mut v = Vec::with_capacity(count);
for _ in 0..count {
let x = read_f32_le(bytes, i)?;
let y = read_f32_le(bytes, i)?;
let z = read_f32_le(bytes, i)?;
v.push(Vec3 { x, y, z });
}
Ok(v)
}
fn expected_len_bytes(n_atoms: usize, n_waters: usize) -> usize {
let header = 3 * 4;
let vec3s = (2 * n_atoms + 4 * n_waters) * 12;
let scalars = 6 * 4;
header + vec3s + scalars
}
fn read_exact<const N: usize>(bytes: &[u8], i: &mut usize) -> io::Result<[u8; N]> {
if *i + N > bytes.len() {
return Err(io::Error::new(
ErrorKind::UnexpectedEof,
"MDT snapshot truncated",
));
}
let mut buf = [0u8; N];
buf.copy_from_slice(&bytes[*i..*i + N]);
*i += N;
Ok(buf)
}
fn read_u32_le(bytes: &[u8], i: &mut usize) -> io::Result<u32> {
Ok(u32::from_le_bytes(read_exact::<4>(bytes, i)?))
}
fn read_f32_le(bytes: &[u8], i: &mut usize) -> io::Result<f32> {
Ok(f32::from_le_bytes(read_exact::<4>(bytes, i)?))
}
impl Snapshot {
}