fm-vector 0.1.0

A notation program's PDF read from its vectors: every notehead, stem, beam and barline where the engraver put it, read into .fmn and compiled to MusicXML, with the words from the PDF's text. No model, no server: it runs in the browser.
Documentation
//! `cargo run -p fm-vector --release --example audit -- SCORE.pdf [OUT.json [OUT.musicxml [OUT.fmn]]]`:
//! read a PDF and audit the reading against its own page (`fm_vector::audit_pdf`): the marks
//! printed against the marks written, and the readings that cannot be right. Prints one line
//! (`audited`, the PDF's suspicion, its systems, bars and unread bars, the findings by kind) and
//! its ten most suspect systems; writes the whole audit as JSON, and the reading, where asked.

fn main() {
    let a: Vec<String> = std::env::args().collect();
    if a.len() < 2 {
        eprintln!("usage: audit SCORE.pdf [OUT.json [OUT.musicxml [OUT.fmn]]]");
        std::process::exit(2);
    }
    let bytes = std::fs::read(&a[1]).expect("reading the PDF");
    let audit = match fm_vector::audit_pdf(&bytes) {
        Ok(x) => x,
        Err(e) => {
            println!("refused: {}", e.why.replace('\n', " "));
            std::process::exit(1);
        }
    };
    if let Some(out) = a.get(2) {
        std::fs::write(out, audit.to_json()).expect("writing the JSON");
    }
    if let Some(out) = a.get(3) {
        std::fs::write(out, &audit.reading.musicxml).expect("writing the MusicXML");
    }
    if let Some(out) = a.get(4) {
        std::fs::write(out, &audit.reading.fmn).expect("writing the .fmn");
    }
    let bars: usize = audit.systems.iter().map(|s| s.bars.len()).sum();
    let findings: Vec<String> = (audit.findings.iter())
        .map(|(k, n)| format!("{k}={n}"))
        .collect();
    println!(
        "audited\t{:.1}\t{} systems\t{bars} bars\t{} unread\t{}",
        audit.score,
        audit.systems.len(),
        audit.reading.unread.len(),
        findings.join("; ")
    );
    let mut worst: Vec<&fm_vector::SystemAudit> = audit.systems.iter().collect();
    worst.sort_by(|x, y| y.score.total_cmp(&x.score));
    for s in worst.iter().take(10).filter(|s| s.score > 0.0) {
        let mut why = s.reasons.clone();
        for b in &s.bars {
            why.extend(b.reasons.iter().map(|r| format!("bar {}: {r}", b.bar)));
        }
        println!(
            "system\t{}\tpage {}\t{:.1}\t{}",
            s.system + 1,
            s.page + 1,
            s.score,
            why.join("; ")
        );
    }
}