Maraiah/maraiah/map/pnts.rs

40 lines
764 B
Rust
Raw Normal View History

2019-04-01 00:39:47 -07:00
//! `Point` type.
2019-06-13 18:09:07 -07:00
use crate::{err::*, fixed::Unit};
2019-04-01 00:39:47 -07:00
/// Reads a `Point` object.
2019-04-01 01:50:05 -07:00
pub fn read_o(b: &[u8]) -> ResultS<Point>
2019-04-01 00:39:47 -07:00
{
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.
2019-04-01 01:50:05 -07:00
pub fn write_o(v: Point) -> Vec<u8>
2019-04-01 00:39:47 -07:00
{
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.
2019-04-01 06:05:06 -07:00
pub fn read(b: &[u8]) -> ResultS<(Point, usize)> {Ok((read_o(b)?, 4))}
2019-04-01 00:39:47 -07:00
/// 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