pub fn partition_into_contiguous_layers(
        &self,
        normal: V3<i32>,
        mut coords: Coords,
    ) -> Vec<Coords> {
        let axis = {
            require_simple_axis_normal(normal, coords.lattice())
                .expect("method has not been updated to support other normal vectors")
        };

        { // scope fracs_mut()
            let fracs = coords.fracs_mut();

            // reduce into first unit cell to make most layers contiguous
            for v in &mut fracs[..] {
                // (note: this might produce exactly 1.0)
                v[axis] -= f64::floor(v[axis]);
            }

            // Due to the type "invariants," (scare quotes due to public fields)
            // only the first layer is capable of crossing the periodic boundary,
            // and all misplaced images must be at the beginning.  Ideally, if we
            // looked at successive differences within the layer, we would see a
            // bunch of small positive values with a single large negative value.
            //
            // (however, we can't say this must be EXACTLY true, because `structure`
            //  might have gone through some small numerical changes in the time
            //  between the LayersPerUnitCell was computed and this method was called.
            //  We'll have to settle for "approximately" true.)
            let first_group = &self.groups[0];
            let diffs = {
                first_group.windows(2)
                    .map(|w| fracs[w[1]][axis] - fracs[w[0]][axis])
                    .collect::<Vec<_>>()
            };
            use std::f64::INFINITY;
            let min_diff = diffs.iter().cloned().fold(INFINITY, f64::min);
            let min_diff_pos = diffs.iter().position(|&x| x == min_diff).unwrap();

            // (min_diff is the index of the atom *before* the big negative difference
            //  meaning it is the last one we want to touch)
            for &atom in &first_group[..=min_diff_pos] {
                fracs[atom][axis] -= 1.0;
            }

            // sanity check.  All remaining diffs should be "pretty much nonnegative".
            let new_min = {
                first_group.windows(2)
                    .map(|w| fracs[w[1]][axis] - fracs[w[0]][axis])
                    .fold(INFINITY, f64::min)
            };
            assert!(
                -1e-1 < new_min,
                "(BUG) either a bug occurred in partition_into_contiguous_layers, \
                or it was given a bad structure. (new_diff = {})", new_min);
        } // scope fracs_mut()

        let part = self.get_part();
        let vec = coords.into_unlabeled_partitions(&part).collect::<Vec<_>>();
        vec
    }
/// Partition into structures where each layer's structure has contiguous
/// cartesian coordinates along the normal axis. (be aware this means that images
/// will be taken!)
Partition into structures where each layer's structure has contiguous
cartesian coordinates along the normal axis. (be aware this means that images
will be taken!)
Partition into structures where each layer ' s structure has contiguous cartesian coordinates along the normal axis . ( be aware this means that images will be taken! )
pub fn partition_into_contiguous_layers(
        &self,
        normal: V3<i32>,
        mut coords: Coords,
    ) -> Vec<Coords> {
        let axis = {
            require_simple_axis_normal(normal, coords.lattice())
                .expect("method has not been updated to support other normal vectors")
        };
        { // scope fracs_mut()
            let fracs = coords.fracs_mut();
            // reduce into first unit cell to make most layers contiguous
            for v in &mut fracs[..] {
                // (note: this might produce exactly 1.0)
                v[axis] -= f64::floor(v[axis]);
            }
            // Due to the type "invariants," (scare quotes due to public fields)
            // only the first layer is capable of crossing the periodic boundary,
            // and all misplaced images must be at the beginning.  Ideally, if we
            // looked at successive differences within the layer, we would see a
            // bunch of small positive values with a single large negative value.
            //
            // (however, we can't say this must be EXACTLY true, because `structure`
            //  might have gone through some small numerical changes in the time
            //  between the LayersPerUnitCell was computed and this method was called.
            //  We'll have to settle for "approximately" true.)
            let first_group = &self.groups[0];
            let diffs = {
                first_group.windows(2)
                    .map(|w| fracs[w[1]][axis] - fracs[w[0]][axis])
                    .collect::<Vec<_>>()
            };
            use std::f64::INFINITY;
            let min_diff = diffs.iter().cloned().fold(INFINITY, f64::min);
            let min_diff_pos = diffs.iter().position(|&x| x == min_diff).unwrap();
            // (min_diff is the index of the atom *before* the big negative difference
            //  meaning it is the last one we want to touch)
            for &atom in &first_group[..=min_diff_pos] {
                fracs[atom][axis] -= 1.0;
            }
            // sanity check.  All remaining diffs should be "pretty much nonnegative".
            let new_min = {
                first_group.windows(2)
                    .map(|w| fracs[w[1]][axis] - fracs[w[0]][axis])
                    .fold(INFINITY, f64::min)
            };
            assert!(
                -1e-1 < new_min,
                "(BUG) either a bug occurred in partition_into_contiguous_layers, \
                or it was given a bad structure. (new_diff = {})", new_min);
        } // scope fracs_mut()
        let part = self.get_part();
        let vec = coords.into_unlabeled_partitions(&part).collect::<Vec<_>>();
        vec
    }
pub fn partition_into_contiguous_layers ( & self , normal : V3 < i32 > , mut coords : Coords , ) -> Vec < Coords > { let axis = { require_simple_axis_normal ( normal , coords . lattice ( ) ) . expect ( " " ) } ; { // scope fracs_mut() let fracs = coords . fracs_mut ( ) ; // reduce into first unit cell to make most layers contiguous for v in & mut fracs [ .. ] { // (note: this might produce exactly 1.0) v [ axis ] -= f64 :: floor ( v [ axis ] ) ; } // Due to the type "invariants," (scare quotes due to public fields) // only the first layer is capable of crossing the periodic boundary, // and all misplaced images must be at the beginning.  Ideally, if we // looked at successive differences within the layer, we would see a // bunch of small positive values with a single large negative value. // // (however, we can't say this must be EXACTLY true, because `structure` //  might have gone through some small numerical changes in the time //  between the LayersPerUnitCell was computed and this method was called. //  We'll have to settle for "approximately" true.) let first_group = & self . groups [ 0 ] ; let diffs = { first_group . windows ( 2 ) . map ( | w | fracs [ w [ 1 ] ] [ axis ] - fracs [ w [ 0 ] ] [ axis ] ) . collect :: < Vec < _ > > ( ) } ; use std :: f64 :: INFINITY ; let min_diff = diffs . iter ( ) . cloned ( ) . fold ( INFINITY , f64 :: min ) ; let min_diff_pos = diffs . iter ( ) . position ( | & x | x == min_diff ) . unwrap ( ) ; // (min_diff is the index of the atom *before* the big negative difference //  meaning it is the last one we want to touch) for & atom in & first_group [ .. = min_diff_pos ] { fracs [ atom ] [ axis ] -= 1.0 ; } // sanity check.  All remaining diffs should be "pretty much nonnegative". let new_min = { first_group . windows ( 2 ) . map ( | w | fracs [ w [ 1 ] ] [ axis ] - fracs [ w [ 0 ] ] [ axis ] ) . fold ( INFINITY , f64 :: min ) } ; assert ! ( 1e-1 new_min " \
 " new_min ) ; } // scope fracs_mut() let part = self . get_part ( ) ; let vec = coords . into_unlabeled_partitions ( & part ) . collect :: < Vec < _ > > ( ) ; vec }
Partition into structures where each layer's structure has contiguous
cartesian coordinates along the normal axis.
Partition into structures where each layer ' s structure has contiguous cartesian coordinates along the normal axis .
&self
normal
V3<i32>
coords
Coords
&self
normal
V3<i32>
coords
Coords