add Endpoint type
parent
b3ff145f63
commit
67426eea3b
|
@ -1,18 +1,52 @@
|
|||
//! `EndPoint` type.
|
||||
|
||||
use crate::durandal::err::*;
|
||||
use crate::durandal::{err::*, fixed::Unit};
|
||||
use super::pnts;
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads an `EPNT` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(pnts::Point, usize)>
|
||||
pub fn read(b: &[u8]) -> ResultS<(Endpoint, usize)>
|
||||
{
|
||||
read_data! {
|
||||
endian: BIG, buf: b, size: 16, start: 0, data {
|
||||
let pnt = pnts::read_o[6; 4];
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
Ok((pnt, 16))
|
||||
Ok((Endpoint{flags, hei_hi, hei_lo, pos, support}, 16))
|
||||
}
|
||||
|
||||
/// Converts a vector of `Endpoint`s to a vector of `Point`s.
|
||||
pub fn to_pnts(v: &Vec<Endpoint>) -> Vec<pnts::Point>
|
||||
{
|
||||
v.iter().map(|p| p.pos).collect()
|
||||
}
|
||||
|
||||
/// A pre-processed point in world-space.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Endpoint
|
||||
{
|
||||
flags: EndpointFlags,
|
||||
hei_hi: Unit,
|
||||
hei_lo: Unit,
|
||||
pos: pnts::Point,
|
||||
support: u16,
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -32,7 +32,7 @@ pub fn read_chunks(b: &[u8], old: bool, siz_cnk: usize)
|
|||
b"PICT" => Chunk::Pict(pict::load_pict(data)?),
|
||||
b"Minf" => Chunk::Minf(read_chunk_minf(data)?),
|
||||
b"iidx" => Chunk::Iidx(rd_array(data, map::iidx::read)?),
|
||||
b"EPNT" => Chunk::Pnts(rd_array(data, map::epnt::read)?),
|
||||
b"EPNT" => Chunk::Epnt(rd_array(data, map::epnt::read)?),
|
||||
b"PNTS" => Chunk::Pnts(rd_array(data, map::pnts::read)?),
|
||||
b"LINS" => Chunk::Lins(rd_array(data, map::lins::read)?),
|
||||
b"SIDS" => Chunk::Sids(rd_array(data, read_chunk_sids)?),
|
||||
|
@ -145,6 +145,7 @@ pub enum Chunk
|
|||
/** A `PICT` chunk. */ Pict(image::Image8),
|
||||
/** A `Minf` chunk. */ Minf(map::minf::Minf),
|
||||
/** An `iidx` chunk. */ Iidx(Vec<u16>),
|
||||
/** An `EPNT` chunk. */ Epnt(Vec<map::epnt::Endpoint>),
|
||||
/** A `PNTS` chunk. */ Pnts(Vec<map::pnts::Point>),
|
||||
/** A `LINS` chunk. */ Lins(Vec<map::lins::Line>),
|
||||
/** A `SIDS` chunk. */ Sids(Vec<map::sids::Side>),
|
||||
|
|
Loading…
Reference in New Issue