fn dumb_nearest_distance(
    lattice: &Lattice,
    frac_a: &V3,
    frac_b: &V3,
) -> f64 {
    let diff = (frac_a - frac_b).map(|x| x - x.round());

    let mut diffs = Vec::with_capacity(27);
    for &a in &[-1., 0., 1.] {
        for &b in &[-1., 0., 1.] {
            for &c in &[-1., 0., 1.] {
                diffs.push(diff + V3([a, b, c]));
            }
        }
    }

    CoordsKind::Fracs(diffs)
        .to_carts(lattice).into_iter()
        .map(|v| v.norm())
        .min_by(|a, b| a.partial_cmp(b).unwrap())
        .unwrap()
}
// Slow, and not even always correct
Slow, and not even always correct
Slow and not even always correct
fn dumb_nearest_distance(
    lattice: &Lattice,
    frac_a: &V3,
    frac_b: &V3,
) -> f64 {
    let diff = (frac_a - frac_b).map(|x| x - x.round());
    let mut diffs = Vec::with_capacity(27);
    for &a in &[-1., 0., 1.] {
        for &b in &[-1., 0., 1.] {
            for &c in &[-1., 0., 1.] {
                diffs.push(diff + V3([a, b, c]));
            }
        }
    }
    CoordsKind::Fracs(diffs)
        .to_carts(lattice).into_iter()
        .map(|v| v.norm())
        .min_by(|a, b| a.partial_cmp(b).unwrap())
        .unwrap()
}
fn dumb_nearest_distance ( lattice : & Lattice , frac_a : & V3 , frac_b : & V3 , ) -> f64 { let diff = ( frac_a - frac_b ) . map ( | x | x - x . round ( ) ) ; let mut diffs = Vec :: with_capacity ( 27 ) ; for & a in & [ - 1. , 0. , 1. ] { for & b in & [ - 1. , 0. , 1. ] { for & c in & [ - 1. , 0. , 1. ] { diffs . push ( diff + V3 ( [ a , b , c ] ) ) ; } } } CoordsKind :: Fracs ( diffs ) . to_carts ( lattice ) . into_iter ( ) . map ( | v | v . norm ( ) ) . min_by ( | a , b | a . partial_cmp ( b ) . unwrap ( ) ) . unwrap ( ) }
Slow, and not even always correct
Slow and not even always correct
lattice
&Lattice
frac_a
&V3
frac_b
&V3
lattice
&Lattice
frac_a
&V3
frac_b
&V3