use crate::*;
use super::{
super::{byte_reader::*, utils::*},
types::*,
};
use std::io::Read;
#[inline(always)]
pub fn collect_index_line(line: &[u8]) -> Option<[usize; 3]> {
let mut words = to_words_skip_empty(line);
if words.next()? != b"3" {
return None;
}
let a = from_ascii(words.next()?)?;
let b = from_ascii(words.next()?)?;
let c = from_ascii(words.next()?)?;
Some([a, b, c])
}
#[inline(always)]
pub fn read_face_type<BR, R>(read: &mut R, t: FaceType) -> PlyResult<usize>
where
BR: IsByteReader,
R: Read,
{
Ok(match t {
FaceType::Char => BR::read_i8(read)? as usize,
FaceType::UChar => BR::read_u8(read)? as usize,
FaceType::Short => BR::read_i16(read)? as usize,
FaceType::UShort => BR::read_u16(read)? as usize,
FaceType::Int => BR::read_i32(read)? as usize,
FaceType::UInt => BR::read_u32(read)? as usize,
})
}
#[inline(always)]
pub fn read_vertex_type<BR, R>(read: &mut R, t: VertexType) -> PlyResult<f64>
where
BR: IsByteReader,
R: Read,
{
Ok(match t {
VertexType::Float => BR::read_f32(read)? as f64,
VertexType::Double => BR::read_f64(read)?,
})
}
#[inline(always)]
pub fn point_with_order<P>(fst: f64, snd: f64, third: f64, order: VertexOrder) -> P
where
P: IsBuildable3D,
{
match order {
VertexOrder::Xyz => P::new(fst, snd, third),
VertexOrder::Xzy => P::new(fst, third, snd),
VertexOrder::Yxz => P::new(snd, fst, third),
VertexOrder::Yzx => P::new(snd, third, fst),
VertexOrder::Zxy => P::new(third, fst, snd),
VertexOrder::Zyx => P::new(third, snd, fst),
}
}