Maraiah/maraiah/map/epnt.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

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 03:17:56 -07:00
use bitflags::bitflags;
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
{
read_data! {
endian: BIG, buf: b, size: 16, start: 0, data {
2019-04-01 03:17:56 -07:00
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-04-01 03:17:56 -07:00
Ok((Endpoint{flags, hei_hi, hei_lo, pos, support}, 16))
}
/// 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
{
v.iter().map(|p| p.pos).collect()
}
/// 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-04-01 03:17:56 -07:00
pub struct Endpoint
{
2019-04-01 05:29:51 -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
}
bitflags! {
/// Flags for `Endpoint`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
pub struct EndpointFlags: u16
{
const SOLID = 1;
const SAME_HEIGHT = 1 << 1;
const TRANSPARENT = 1 << 2;
}
2019-04-01 00:39:47 -07:00
}
// EOF