fn decide_on_matches<'a>(matches: Vec<Match2D<'a>>, res_consider: &mut VecDeque<Match2D<'a>>) {
    for current_match in matches {
        // Determine the number of pixels this glyph sequence matched.
        let current_matching = current_match
            .tokens
            .iter()
            .map(|z| z.glyph.total())
            .fold(0, |x, a| x + a);
        // Now, we need to decide whether this block of glyphs is better than the ones currently
        // in res_consider.

        // Options:
        //   - No overlap, always add this glyph.
        //   - Overlap, decide which glyph is the best, remove the other.

        // Check if this overlaps with others in the consideration buffer;
        let mut do_insert = true;
        *res_consider = res_consider
            .drain(..)
            .filter(|m| {
                if do_insert == false {
                    return true; // already discarded current glyph, keep everything.
                }

                // Check if this block overlaps the match were checking against.
                if m.location.overlaps(&current_match.location) {
                    // We overlap, and the current glyph sequence is still under consideration;
                    // Decide if better, more matching pixels is better, likely a longer
                    // word, or more complex glyph got matched.
                    let mlen = m
                        .tokens
                        .iter()
                        .map(|z| z.glyph.total())
                        .fold(0, |x, a| x + a);

                    // Make the decision.
                    let new_is_better = current_matching > mlen;

                    if !new_is_better {
                        // new is not better than what we have
                        do_insert = false; // ensure we don't insert.
                        return true; // keep old
                    } else {
                        return false; // drop old.
                    }
                }
                return true; // no overlap, always keep m under consideration.
            })
            .collect::<_>();

        if do_insert {
            // We should insert our current entry.
            res_consider.push_back(current_match.clone());
        }
    }
}
/// Helper to decide on matches that overlap with other matches.
Helper to decide on matches that overlap with other matches.
Helper to decide on matches that overlap with other matches .
fn decide_on_matches<'a>(matches: Vec<Match2D<'a>>, res_consider: &mut VecDeque<Match2D<'a>>) {
    for current_match in matches {
        // Determine the number of pixels this glyph sequence matched.
        let current_matching = current_match
            .tokens
            .iter()
            .map(|z| z.glyph.total())
            .fold(0, |x, a| x + a);
        // Now, we need to decide whether this block of glyphs is better than the ones currently
        // in res_consider.
        // Options:
        //   - No overlap, always add this glyph.
        //   - Overlap, decide which glyph is the best, remove the other.
        // Check if this overlaps with others in the consideration buffer;
        let mut do_insert = true;
        *res_consider = res_consider
            .drain(..)
            .filter(|m| {
                if do_insert == false {
                    return true; // already discarded current glyph, keep everything.
                }
                // Check if this block overlaps the match were checking against.
                if m.location.overlaps(&current_match.location) {
                    // We overlap, and the current glyph sequence is still under consideration;
                    // Decide if better, more matching pixels is better, likely a longer
                    // word, or more complex glyph got matched.
                    let mlen = m
                        .tokens
                        .iter()
                        .map(|z| z.glyph.total())
                        .fold(0, |x, a| x + a);
                    // Make the decision.
                    let new_is_better = current_matching > mlen;
                    if !new_is_better {
                        // new is not better than what we have
                        do_insert = false; // ensure we don't insert.
                        return true; // keep old
                    } else {
                        return false; // drop old.
                    }
                }
                return true; // no overlap, always keep m under consideration.
            })
            .collect::<_>();
        if do_insert {
            // We should insert our current entry.
            res_consider.push_back(current_match.clone());
        }
    }
}
fn decide_on_matches < ' a > ( matches : Vec < Match2D < ' a > > , res_consider : & mut VecDeque < Match2D < ' a > > ) { for current_match in matches { // Determine the number of pixels this glyph sequence matched. let current_matching = current_match . tokens . iter ( ) . map ( | z | z . glyph . total ( ) ) . fold ( 0 , | x , a | x + a ) ; // Now, we need to decide whether this block of glyphs is better than the ones currently // in res_consider. // Options: //   - No overlap, always add this glyph. //   - Overlap, decide which glyph is the best, remove the other. // Check if this overlaps with others in the consideration buffer; let mut do_insert = true ; * res_consider = res_consider . drain ( .. ) . filter ( | m | { if do_insert == false { return true ; // already discarded current glyph, keep everything. } // Check if this block overlaps the match were checking against. if m . location . overlaps ( & current_match . location ) { // We overlap, and the current glyph sequence is still under consideration; // Decide if better, more matching pixels is better, likely a longer // word, or more complex glyph got matched. let mlen = m . tokens . iter ( ) . map ( | z | z . glyph . total ( ) ) . fold ( 0 , | x , a | x + a ) ; // Make the decision. let new_is_better = current_matching > mlen ; if ! new_is_better { // new is not better than what we have do_insert = false ; // ensure we don't insert. return true ; // keep old } else { return false ; // drop old. } } return true ; // no overlap, always keep m under consideration. } ) . collect :: < _ > ( ) ; if do_insert { // We should insert our current entry. res_consider . push_back ( current_match . clone ( ) ) ; } } }
Helper to decide on matches that overlap with other matches.
Helper to decide on matches that overlap with other matches .
matches
Vec<Match2D<'a>>
res_consider
&mut VecDeque<Match2D<'a>>