helixiser/export.rs
1//! # Functions for exporting and loading helixiser models
2use crate::helix::Helix;
3
4/// Generate a URL to helix model in the Helxiser web application
5///
6/// # Examples
7/// ```
8/// use open::that;
9/// # use helixiser::helix::{ Helix, Handedness };
10/// # use helixiser::export::helixiser_web_link;
11///
12/// let helix_1 = Helix {
13/// radius: 0.5,
14/// rise: 0.05,
15/// frequency: 10.,
16/// unit_size: 0.18,
17/// offset: 0.,
18/// rotation: 0.,
19/// handedness: Handedness::Right,
20/// };
21///
22/// let link = helixiser_web_link("Rust", vec![helix_1]);
23/// println!("Helixiser Web-link: {}", link);
24/// // uncomment line below to open the model in browser
25/// // open::that(link);
26/// ```
27pub fn helixiser_web_link(name: &str, helix_family: Vec<Helix>) -> String {
28 let mut web_link: String = String::new();
29 // Add the base URL
30 web_link.push_str("https://nemoandrea.github.io/helixiser/#");
31 // Add the meta fields (name)
32 web_link.push_str(&format!("name={}###", name));
33 // specify the helices
34 for helix in helix_family {
35 web_link.push_str(&format!("&radius={}", helix.radius));
36 web_link.push_str(&format!("&rise={}", helix.rise));
37 web_link.push_str(&format!("&frequency={}", helix.frequency));
38 web_link.push_str(&format!("&unit_size={}", helix.unit_size));
39 web_link.push_str(&format!("&rotation={}", helix.rotation));
40 web_link.push_str(&format!("&offset={}", helix.offset));
41 }
42 return web_link
43}