pub struct PosCFromIteratorError;
display_as_debug!{PosCFromIteratorError}
+macro_rules! pos_zip_map { {
+ $( $input:expr ),* => $closure:expr
+} => {
+ PosC::try_from_iter_2(
+ izip!($( $input .coords(), )*)
+ .map($closure)
+ )
+} }
+
impl<T> PosC<T> {
pub const fn new(x: T, y: T) -> Self { PosC{ coords: [x,y] } }
pub fn both(v: T) -> Self where T: Copy { PosC::new(v,v) }
PosC::both(<T as num_traits::Zero>::zero())
}
+ fn coords(self) -> impl ExactSizeIterator<Item=T> + FusedIterator<Item=T> {
+ self.coords.into_iter()
+ }
+
#[throws(CoordinateOverflow)]
pub fn len2(self) -> f64 where PosC<T>: PosPromote {
- self.promote().coords.iter()
- .try_fold(0., |b, &c| {
+ self.promote().coords()
+ .try_fold(0., |b, c| {
let c2 = c.checked_mul(c)?;
b.checked_add(c2)
})?
type Output = Result<Self, CoordinateOverflow>;
#[throws(CoordinateOverflow)]
fn add(self, rhs: PosC<T>) -> PosC<T> {
- PosC::try_from_iter_2(
- itertools::zip_eq(
- self.coords.iter().cloned(),
- rhs .coords.iter().cloned(),
- ).map(
- |(a,b)| a.checked_add(b)
- )
- )?
+ pos_zip_map!( self, rhs => |(a,b)| a.checked_add(b) )?
}
}
pub use std::f64::consts::TAU;
pub use std::fmt::{self, Debug, Display, Formatter, Write as _};
pub use std::hash::{Hash, Hasher};
-pub use std::iter;
+pub use std::iter::{self, FusedIterator};
pub use std::mem;
pub use std::num::{TryFromIntError, Wrapping};
pub use std::ops::{Deref, DerefMut, Index, IndexMut};
pub use std::io::ErrorKind;
pub use std::io::{BufRead, BufReader, BufWriter, Read, Write};
pub use std::iter;
-pub use std::iter::repeat_with;
+pub use std::iter::{repeat_with};
pub use std::marker::PhantomData;
pub use std::num::{NonZeroUsize, TryFromIntError, Wrapping};
pub use std::os::linux::fs::MetadataExt as _; // todo why linux for st_mode??