Registry / RepositoryTypeScriptRustPython
Rollpie
ReadmeFiles
Versions
Info
Download
0.2.0528.5 KB2026-10-160.1.1542.8 KB2026-10-150.1.0541.1 KB2026-10-15
Version
0.1.0
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-10-15
Size
541.1 KB
Downloads
9
Checksum
67f9c361d04f05b0299dd8e9ef5e2a0120d67be36205a76945eb5f7ef90443be
Dependencies
None

show.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! 図の座標を数で見る
//!
//! 使い方:
//!   cargo run --example show -- 'A?[b,=]-[:60]B-[:-60]C?[b]'
//!
//! 見た目がおかしいときに、原子がどこに置かれ、線がどこからどこへ引かれたかを確かめる。

use lina::{Style, to_figure};


const DEFAULT_FONT: &str = "font/latinmodern-math.otf";


fn main() {
    let argument: Vec<String> = std::env::args().skip(1).collect();

    if argument.is_empty() {
        eprintln!("分子を 1 つ以上わたしてください");
        std::process::exit(1);
    }

    let data = match std::fs::read(DEFAULT_FONT) {
        Ok(data) => data,
        Err(reason) => {
            eprintln!("フォントを読めません: {DEFAULT_FONT}: {reason}");
            std::process::exit(1);
        }
    };
    let font = lina::load_font(data).expect("フォントを読み込めません");
    let style = Style::default();

    for source in &argument {
        println!("{source}");

        let figure = match to_figure(source, &font, &style) {
            Ok(figure) => figure,
            Err(reason) => {
                println!("  {reason}");
                continue;
            }
        };

        for (order, atom) in figure.atom.iter().enumerate() {
            let mark: String = atom.label.placed.iter().map(|placed| placed.character).collect();
            let mark = if mark.is_empty() {"印なし".to_string()} else {mark};
            println!("  原子 {order}  ({:.3}, {:.3})  {mark}", atom.x, atom.y);
        }

        for line in &figure.line {
            println!(
                "  線    ({:.3}, {:.3}) - ({:.3}, {:.3})",
                line.x1, line.y1, line.x2, line.y2
            );
        }

        for wedge in &figure.wedge {
            let filled = if wedge.filled {"塗る"} else {"塗らない"};
            println!(
                "  くさび ({:.3}, {:.3}) から幅 {:.3}  {filled}",
                wedge.tip.0,
                wedge.tip.1,
                ((wedge.base[0].0 - wedge.base[1].0).powi(2)
                    + (wedge.base[0].1 - wedge.base[1].1).powi(2))
                .sqrt()
            );
        }

        for circle in &figure.circle {
            println!("  丸    ({:.3}, {:.3})  半径 {:.3}", circle.x, circle.y, circle.radius);
        }

        println!();
    }
}