//! `Point` type. use crate::durandal::{err::*, fixed::Unit}; /// Reads a `Point` object. pub fn read_point(b: &[u8]) -> ResultS { read_data! { endian: BIG, buf: b, size: 4, start: 0, data { let x = Unit[0]; let y = Unit[2]; } } Ok(Point{x, y}) } /// Writes a `Point` object. pub fn write_point(v: Point) -> Vec { let mut o = Vec::with_capacity(4); o.extend(&v.x.to_be_bytes()); o.extend(&v.y.to_be_bytes()); o } /// Reads a `PNTS` chunk. pub fn read(b: &[u8]) -> ResultS<(Point, usize)> { Ok((read_point(b)?, 4)) } /// A point in world-space. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] pub struct Point { pub x: Unit, pub y: Unit, } // EOF