//! `Point` type. use super::epnt; use crate::{err::*, fixed::Unit}; /// Reads a `Point` object. pub fn read_o(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_o(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_o(b)?, 4))} impl From<&Point> for Point { fn from(pnts: &Point) -> Self {*pnts} } impl From for Point { fn from(epnt: epnt::Endpoint) -> Self {epnt.pos} } impl From<&epnt::Endpoint> for Point { fn from(epnt: &epnt::Endpoint) -> Self {epnt.pos} } /// 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