// Unified wrapper around the two algorithms which handles all the stuff
// related to plane normals and fractional <-> cartesian conversions
// (reformulating everything as a problem in 1D)
Unified wrapper around the two algorithms which handles all the stuff
related to plane normals and fractional <-> cartesian conversions
(reformulating everything as a problem in 1D)
Unified wrapper around the two algorithms which handles all the stuff related to plane normals and fractional < - > cartesian conversions ( reformulating everything as a problem in 1D )
fn find_layers_impl<L: Ord>(
    coords: &Coords,
    miller: V3<i32>,
    cart_threshold: f64,
    labels: Option<&[L]>,
) -> Result<Layers, Error>
{Ok({
    let carts = coords.to_carts();
    if carts.len() == 0 {
        return Ok(Layers::NoAtoms);
    }
    let gcd = crate::miller::gcd(miller);
    ensure!(gcd == 1, "Layers can only be found along a primitive miller index");
    let normal = coords.lattice().plane_normal(miller);
    let periodic_length = coords.lattice().plane_spacing(miller);
    // Transform into units used by the bulk of the algorithm:
    let cart_values = carts.into_iter().map(|c| V3::dot(&c, &normal));
    let frac_values = cart_values.map(|x| x / periodic_length).collect::<Vec<_>>();
    let frac_threshold = cart_threshold / periodic_length;
    // Perform the bulk of the algorithm
    let layers = assign_layers_impl_frac_1d(&frac_values, frac_threshold, labels)?;
    // Convert units back
    layers.scale_gaps(periodic_length)
})}
fn find_layers_impl < L : Ord > ( coords : & Coords , miller : V3 < i32 > , cart_threshold : f64 , labels : Option < & [ L ] > , ) -> Result < Layers , Error > { Ok ( { let carts = coords . to_carts ( ) ; if carts . len ( ) == 0 { return Ok ( Layers :: NoAtoms ) ; } let gcd = crate :: miller :: gcd ( miller ) ; ensure ! ( gcd 1 " " ) ; let normal = coords . lattice ( ) . plane_normal ( miller ) ; let periodic_length = coords . lattice ( ) . plane_spacing ( miller ) ; // Transform into units used by the bulk of the algorithm: let cart_values = carts . into_iter ( ) . map ( | c | V3 :: dot ( & c , & normal ) ) ; let frac_values = cart_values . map ( | x | x / periodic_length ) . collect :: < Vec < _ > > ( ) ; let frac_threshold = cart_threshold / periodic_length ; // Perform the bulk of the algorithm let layers = assign_layers_impl_frac_1d ( & frac_values , frac_threshold , labels ) ? ; // Convert units back layers . scale_gaps ( periodic_length ) } ) }
Unified wrapper around the two algorithms which handles all the stuff
related to plane normals and fractional <-> cartesian conversions
(reformulating everything as a problem in 1D)
Unified wrapper around the two algorithms which handles all the stuff related to plane normals and fractional < - > cartesian conversions ( reformulating everything as a problem in 1D )
coords
&Coords
miller
V3<i32>
cart_threshold
f64
labels
Option<&[L]>