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
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!("give one or more molecules");
std::process::exit(1);
}
let data = match std::fs::read(DEFAULT_FONT) {
Ok(data) => data,
Err(reason) => {
eprintln!("cannot read the font: {DEFAULT_FONT}: {reason}");
std::process::exit(1);
}
};
let font = lina::load_font(data).expect("cannot load the font");
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() {"no label".to_string()} else {mark};
println!(" atom {order} ({:.3}, {:.3}) {mark}", atom.x, atom.y);
}
for line in &figure.line {
println!(
" line ({:.3}, {:.3}) - ({:.3}, {:.3})",
line.x1, line.y1, line.x2, line.y2
);
}
for wedge in &figure.wedge {
let filled = if wedge.filled {"filled"} else {"hollow"};
println!(
" wedge ({:.3}, {:.3}) width {:.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!(" circle ({:.3}, {:.3}) radius {:.3}", circle.x, circle.y, circle.radius);
}
println!();
}
}