pub fn output_fn_cosine_formatter(
    prefix: &str,
    num_cosines: usize,
    precision: usize,
) -> impl Clone + FnMut(Option<&[f64]>) -> String {
    let mut past_directions = VecDeque::<Vec<_>>::new();

    let word_len = precision + 3; // fit sign, leading 0/1, decimal point.
    let total_len = prefix.len() + (1 + word_len) * num_cosines; // fit words and spaces
    let prefix = prefix.to_string();

    move |direction| {

        let mut s = String::new();
        if !past_directions.is_empty() {
            write!(&mut s, "{}", prefix).unwrap();
            let latest = direction.expect("called with None after first call!?");
            for other in &past_directions {
                write!(
                    &mut s, " {:>+word$.prec$}",
                    vdot(latest, other),
                    prec=precision,
                    word=word_len,
                ).unwrap();
            }
        }
        let out_string = format!("{:<w$}", s, w=total_len);

        if let Some(direction) = direction {
            let max_cosines = 3;
            let mut buf = match past_directions.len().cmp(&max_cosines) {
                std::cmp::Ordering::Less => vec![],
                std::cmp::Ordering::Equal => past_directions.pop_back().unwrap(),
                std::cmp::Ordering::Greater => unreachable!(),
            };
            buf.clear();
            buf.extend(direction.iter().cloned());
            past_directions.push_front(buf);
        }
        out_string
    }
}
/// Helper for producing a column with the cosines between succesive directions, just like
/// the one produced by `basic_output_fn`.
///
/// The word "cos: " is included in the output, since it is hidden on the first iteration.
Helper for producing a column with the cosines between succesive directions, just like
the one produced by `basic_output_fn`.

The word "cos: " is included in the output, since it is hidden on the first iteration.
Helper for producing a column with the cosines between succesive directions just like the one produced by ` basic_output_fn ` . The word " cos : " is included in the output since it is hidden on the first iteration .
pub fn output_fn_cosine_formatter(
    prefix: &str,
    num_cosines: usize,
    precision: usize,
) -> impl Clone + FnMut(Option<&[f64]>) -> String {
    let mut past_directions = VecDeque::<Vec<_>>::new();
    let word_len = precision + 3; // fit sign, leading 0/1, decimal point.
    let total_len = prefix.len() + (1 + word_len) * num_cosines; // fit words and spaces
    let prefix = prefix.to_string();
    move |direction| {
        let mut s = String::new();
        if !past_directions.is_empty() {
            write!(&mut s, "{}", prefix).unwrap();
            let latest = direction.expect("called with None after first call!?");
            for other in &past_directions {
                write!(
                    &mut s, " {:>+word$.prec$}",
                    vdot(latest, other),
                    prec=precision,
                    word=word_len,
                ).unwrap();
            }
        }
        let out_string = format!("{:<w$}", s, w=total_len);
        if let Some(direction) = direction {
            let max_cosines = 3;
            let mut buf = match past_directions.len().cmp(&max_cosines) {
                std::cmp::Ordering::Less => vec![],
                std::cmp::Ordering::Equal => past_directions.pop_back().unwrap(),
                std::cmp::Ordering::Greater => unreachable!(),
            };
            buf.clear();
            buf.extend(direction.iter().cloned());
            past_directions.push_front(buf);
        }
        out_string
    }
}
pub fn output_fn_cosine_formatter ( prefix : & str , num_cosines : usize , precision : usize , ) -> impl Clone + FnMut ( Option < & [ f64 ] > ) -> String { let mut past_directions = VecDeque :: < Vec < _ > > :: new ( ) ; let word_len = precision + 3 ; // fit sign, leading 0/1, decimal point. let total_len = prefix . len ( ) + ( 1 + word_len ) * num_cosines ; // fit words and spaces let prefix = prefix . to_string ( ) ; move | direction | { let mut s = String :: new ( ) ; if ! past_directions . is_empty ( ) { write ! ( mut s " " prefix ) . unwrap ( ) ; let latest = direction . expect ( " " ) ; for other in & past_directions { write ! ( mut s " " vdot ( latest other ) prec precision word word_len ) . unwrap ( ) ; } } let out_string = format ! ( " " s w total_len ) ; if let Some ( direction ) = direction { let max_cosines = 3 ; let mut buf = match past_directions . len ( ) . cmp ( & max_cosines ) { std :: cmp :: Ordering :: Less => vec ! [ ] , std :: cmp :: Ordering :: Equal => past_directions . pop_back ( ) . unwrap ( ) , std :: cmp :: Ordering :: Greater => unreachable ! ( ) , } ; buf . clear ( ) ; buf . extend ( direction . iter ( ) . cloned ( ) ) ; past_directions . push_front ( buf ) ; } out_string } }
Helper for producing a column with the cosines between succesive directions, just like
the one produced by `basic_output_fn`.
Helper for producing a column with the cosines between succesive directions just like the one produced by ` basic_output_fn ` .
prefix
&str
num_cosines
usize
precision
usize
prefix
&str
num_cosines
usize
precision
usize