2019-04-10 01:36:19 -07:00
|
|
|
//! `Endpoint` type.
|
2019-04-01 00:39:47 -07:00
|
|
|
|
2019-04-01 01:50:05 -07:00
|
|
|
use super::pnts;
|
2019-06-13 18:09:07 -07:00
|
|
|
use crate::{err::*, fixed::Unit};
|
2019-04-01 00:39:47 -07:00
|
|
|
|
|
|
|
/// Reads an `EPNT` chunk.
|
2019-04-01 03:17:56 -07:00
|
|
|
pub fn read(b: &[u8]) -> ResultS<(Endpoint, usize)>
|
2019-04-01 00:39:47 -07:00
|
|
|
{
|
2019-07-05 20:21:11 -07:00
|
|
|
read_data! {
|
|
|
|
endian: BIG, buf: b, size: 16, start: 0, data {
|
|
|
|
let flags = u16[0] flag EndpointFlags;
|
|
|
|
let hei_hi = Unit[2];
|
|
|
|
let hei_lo = Unit[4];
|
|
|
|
let pos = pnts::read_o[6; 4];
|
|
|
|
let support = u16[10];
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 00:39:47 -07:00
|
|
|
|
2019-07-05 20:21:11 -07:00
|
|
|
Ok((Endpoint{flags, hei_hi, hei_lo, pos, support}, 16))
|
2019-04-01 03:17:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Converts a vector of `Endpoint`s to a vector of `Point`s.
|
2019-04-01 06:05:06 -07:00
|
|
|
pub fn to_pnts(v: &[Endpoint]) -> Vec<pnts::Point>
|
2019-04-01 03:17:56 -07:00
|
|
|
{
|
2019-07-05 20:21:11 -07:00
|
|
|
v.iter().map(|p| p.pos).collect()
|
2019-04-01 03:17:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A pre-processed point in world-space.
|
|
|
|
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
2019-04-01 05:29:51 -07:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
2019-06-25 03:52:21 -07:00
|
|
|
pub struct Endpoint {
|
2019-07-05 20:21:11 -07:00
|
|
|
pub flags: EndpointFlags,
|
|
|
|
pub hei_hi: Unit,
|
|
|
|
pub hei_lo: Unit,
|
|
|
|
pub pos: pnts::Point,
|
|
|
|
pub support: u16,
|
2019-04-01 03:17:56 -07:00
|
|
|
}
|
|
|
|
|
2019-07-02 21:34:14 -07:00
|
|
|
c_bitfield! {
|
2019-07-05 20:21:11 -07:00
|
|
|
/// Flags for `Endpoint`.
|
|
|
|
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
|
|
|
pub struct EndpointFlags: u16 {
|
|
|
|
SOLID = 0,
|
|
|
|
SAME_HEIGHT = 1,
|
|
|
|
TRANSPARENT = 2,
|
|
|
|
}
|
2019-04-01 00:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// EOF
|