maraiah: implement some boilerplate
parent
b5d1aaaafe
commit
186020c8c2
|
@ -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)]
|
||||
|
|
|
@ -152,6 +152,7 @@ impl EntryData
|
|||
}
|
||||
|
||||
/// The abstract type of an entry.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum EntryType {
|
||||
Other,
|
||||
Map,
|
||||
|
|
|
@ -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<pnts::Point>
|
||||
{
|
||||
v.iter().map(|p| p.pos).collect()
|
||||
v.iter().map(|p| p.into()).collect()
|
||||
}
|
||||
|
||||
/// A pre-processed point in world-space.
|
||||
|
|
|
@ -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<u8>
|
|||
/// 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<epnt::Endpoint> 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)]
|
||||
|
|
Loading…
Reference in New Issue