diff --git a/maraiah/fixed.rs b/maraiah/fixed.rs index 94875d9..394e93f 100644 --- a/maraiah/fixed.rs +++ b/maraiah/fixed.rs @@ -623,6 +623,14 @@ define_fixed_types! { struct FixedLong(i64, 8) : u64, i128, 32; fixed_long_tests } +impl FixedLong +{ + /// Creates a value of this type from a `Unit`. + #[inline] + pub fn from_unit(n: Unit) -> Self {Self(i64::from(n.to_bits()) << 22)} + +} + #[test] #[should_panic] #[allow(unused_must_use)] diff --git a/maraiah/map/data.rs b/maraiah/map/data.rs index 1f3bba9..5bcf963 100644 --- a/maraiah/map/data.rs +++ b/maraiah/map/data.rs @@ -152,6 +152,7 @@ impl EntryData } /// The abstract type of an entry. +#[derive(Debug, Eq, PartialEq)] pub enum EntryType { Other, Map, diff --git a/maraiah/map/epnt.rs b/maraiah/map/epnt.rs index a68f8ab..8c5bfc2 100644 --- a/maraiah/map/epnt.rs +++ b/maraiah/map/epnt.rs @@ -22,7 +22,7 @@ pub fn read(b: &[u8]) -> ResultS<(Endpoint, usize)> /// Converts a vector of `Endpoint`s to a vector of `Point`s. pub fn to_pnts(v: &[Endpoint]) -> Vec { - v.iter().map(|p| p.pos).collect() + v.iter().map(|p| p.into()).collect() } /// A pre-processed point in world-space. diff --git a/maraiah/map/pnts.rs b/maraiah/map/pnts.rs index 212ae5e..4b095d2 100644 --- a/maraiah/map/pnts.rs +++ b/maraiah/map/pnts.rs @@ -1,5 +1,6 @@ //! `Point` type. +use super::epnt; use crate::{err::*, fixed::Unit}; /// Reads a `Point` object. @@ -27,6 +28,21 @@ pub fn write_o(v: Point) -> Vec /// Reads a `PNTS` chunk. pub fn read(b: &[u8]) -> ResultS<(Point, usize)> {Ok((read_o(b)?, 4))} +impl From<&Point> for Point +{ + fn from(pnts: &Point) -> Self {*pnts} +} + +impl From for Point +{ + fn from(epnt: epnt::Endpoint) -> Self {epnt.pos} +} + +impl From<&epnt::Endpoint> for Point +{ + fn from(epnt: &epnt::Endpoint) -> Self {epnt.pos} +} + /// A point in world-space. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]