fn brute_force_near_identity(
    lattice: &Lattice,
    from_fracs: &[V3],
    to_fracs: &[V3],
    tol: f64,
) -> Result<Perm, PositionMatchError>
{Ok({
    assert_eq!(from_fracs.len(), to_fracs.len());
    let n = from_fracs.len();

    const UNSET: usize = std::usize::MAX;
    assert!(n < UNSET);

    let mut perm = vec![UNSET; from_fracs.len()];

    // optimization: Rather than filling the out vector in order,
    // we find where each index belongs (e.g. we place the 0, then
    // we place the 1, etc.).
    // Then we can track the first unassigned index.
    //
    // This works best if the permutation is close to the identity.
    // (more specifically, if the max value of 'out[i] - i' is small)
    //
    // This optimization does create some data dependencies which block
    // opportunities for parallelization; but for reducing O(n^2)
    // computations down to O(n), it is worth it.
    let mut search_start = 0;

    'from: for from in 0..n {

        // Skip through things filled out of order.
        while perm[search_start] != UNSET {
            search_start += 1;
        }

        for to in search_start..n {
            if perm[to] != UNSET {
                continue;
            }

            if fracs_within(lattice, from_fracs[from], to_fracs[to], tol) {
                perm[to] = from;
                continue 'from;
            }
        }
        return Err(PositionMatchError::NoMatch(Backtrace::new()));
    }

    if perm.iter().any(|&x| x == UNSET) {
        return Err(PositionMatchError::DuplicateMatch(Backtrace::new()));
    }

    Perm::from_vec(perm).expect("(BUG) invalid perm without match error!?")
})}
// Optimized for permutations near the identity.
// NOTE: Lattice must be reduced so that the voronoi cell fits
//       within the eight unit cells around the origin
Optimized for permutations near the identity.
NOTE: Lattice must be reduced so that the voronoi cell fits
within the eight unit cells around the origin
Optimized for permutations near the identity . NOTE : Lattice must be reduced so that the voronoi cell fits within the eight unit cells around the origin
fn brute_force_near_identity(
    lattice: &Lattice,
    from_fracs: &[V3],
    to_fracs: &[V3],
    tol: f64,
) -> Result<Perm, PositionMatchError>
{Ok({
    assert_eq!(from_fracs.len(), to_fracs.len());
    let n = from_fracs.len();
    const UNSET: usize = std::usize::MAX;
    assert!(n < UNSET);
    let mut perm = vec![UNSET; from_fracs.len()];
    // optimization: Rather than filling the out vector in order,
    // we find where each index belongs (e.g. we place the 0, then
    // we place the 1, etc.).
    // Then we can track the first unassigned index.
    //
    // This works best if the permutation is close to the identity.
    // (more specifically, if the max value of 'out[i] - i' is small)
    //
    // This optimization does create some data dependencies which block
    // opportunities for parallelization; but for reducing O(n^2)
    // computations down to O(n), it is worth it.
    let mut search_start = 0;
    'from: for from in 0..n {
        // Skip through things filled out of order.
        while perm[search_start] != UNSET {
            search_start += 1;
        }
        for to in search_start..n {
            if perm[to] != UNSET {
                continue;
            }
            if fracs_within(lattice, from_fracs[from], to_fracs[to], tol) {
                perm[to] = from;
                continue 'from;
            }
        }
        return Err(PositionMatchError::NoMatch(Backtrace::new()));
    }
    if perm.iter().any(|&x| x == UNSET) {
        return Err(PositionMatchError::DuplicateMatch(Backtrace::new()));
    }
    Perm::from_vec(perm).expect("(BUG) invalid perm without match error!?")
})}
fn brute_force_near_identity ( lattice : & Lattice , from_fracs : & [ V3 ] , to_fracs : & [ V3 ] , tol : f64 , ) -> Result < Perm , PositionMatchError > { Ok ( { assert_eq ! ( from_fracs len ( ) to_fracs len ( ) ) ; let n = from_fracs . len ( ) ; const UNSET : usize = std :: usize :: MAX ; assert ! ( n UNSET ) ; let mut perm = vec ! [ UNSET from_fracs len ( ) ] ; // optimization: Rather than filling the out vector in order, // we find where each index belongs (e.g. we place the 0, then // we place the 1, etc.). // Then we can track the first unassigned index. // // This works best if the permutation is close to the identity. // (more specifically, if the max value of 'out[i] - i' is small) // // This optimization does create some data dependencies which block // opportunities for parallelization; but for reducing O(n^2) // computations down to O(n), it is worth it. let mut search_start = 0 ; ' from : for from in 0 .. n { // Skip through things filled out of order. while perm [ search_start ] != UNSET { search_start += 1 ; } for to in search_start .. n { if perm [ to ] != UNSET { continue ; } if fracs_within ( lattice , from_fracs [ from ] , to_fracs [ to ] , tol ) { perm [ to ] = from ; continue ' from ; } } return Err ( PositionMatchError :: NoMatch ( Backtrace :: new ( ) ) ) ; } if perm . iter ( ) . any ( | & x | x == UNSET ) { return Err ( PositionMatchError :: DuplicateMatch ( Backtrace :: new ( ) ) ) ; } Perm :: from_vec ( perm ) . expect ( " " ) } ) }
Optimized for permutations near the identity.
Optimized for permutations near the identity .
lattice
&Lattice
from_fracs
&[V3]
to_fracs
&[V3]
tol
f64
lattice
&Lattice
from_fracs
&[V3]
to_fracs
&[V3]
tol
f64