pub enum JSONInput {
PlotOne {
rules: JSONDrawRules,
iteration: usize,
plot_param: PlotParameters,
filename: String,
comment: Option<String>,
},
PlotMany {
rules: JSONDrawRules,
iterations: Vec<usize>,
row_len: usize,
plot_param: PlotParameters,
filename: String,
comment: Option<String>,
},
OutputStrings {
rules: HashMap<char, String>,
start: String,
iteration: usize,
filename: String,
comment: Option<String>,
},
}Expand description
Represents the JSON input for an input file.
This provides the details of the L-system as well as instructions for printing.
The three variants of this enum correspond to the three commands (and are tagged using the
command field in the JSON): PlotOne, PlotMany, and OutputStrings.
Variants§
PlotOne
Produces a single plot, showing the specified iteration of the fractal.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::{
JSONDrawAction, JSONInput, JSONDrawRules
};
use l_system_fractals::paths::PlotParameters;
use l_system_fractals::num_validity::AlmostEq;
let json_string = r#"{
"command": "PlotOne",
"rules": {
"type": "Advanced",
"replacement": { "A": "A+BA-AA-A-AA+B+AA-BA+AA+A+AA-B-AAA", "B": "BBBBBB" },
"draw_step_sizes": { "A": 1.0 },
"move_step_sizes": { "B": 1.0 },
"angle_numerator": 1,
"angle_denominator": 2,
"start": "A-A-A-A-"
},
"iteration": 3,
"plot_param": {
"width": 700.0,
"height": 700.0,
"border": 50.0,
"fill": "none",
"stroke": "magenta",
"stroke_width": 1
},
"filename": "islands.svg",
"comment": "Benoit B. Mandelbrot (1983), _The Fractal Geometry of Nautre (Updated and Agumented)_, New York: W.H. Freeman and Company, p. 121"
}"#;
let json_input1: JSONInput = serde_json::from_str(json_string).unwrap();
let rules = JSONDrawRules::Advanced {
replacement: HashMap::from([
('A', "A+BA-AA-A-AA+B+AA-BA+AA+A+AA-B-AAA".into()),
('B', "BBBBBB".into())
]),
draw_step_sizes: HashMap::from([('A', 1.0)]),
move_step_sizes: HashMap::from([('B', 1.0)]),
angle_numerator: 1,
angle_denominator: 2,
start: "A-A-A-A-".into()
};
let plot_param = PlotParameters {
width: 700.0,
height: 700.0,
border: 50.0,
fill: "none".into(),
stroke: "magenta".into(),
stroke_width: 1.0,
background: None
};
let json_input2 = JSONInput::PlotOne {
rules,
iteration: 3,
plot_param,
filename: "islands.svg".into(),
comment: Some("Benoit B. Mandelbrot (1983), _The Fractal Geometry of Nautre".to_string()
+ " (Updated and Agumented)_, New York: W.H. Freeman and Company, p. 121")
};
assert!(json_input1.almost_eq(&json_input2, 0.001));Fields
§
rules: JSONDrawRulesThe rules for the L-system
§
plot_param: PlotParametersThe parameters for the output SVG file
PlotMany
Produces multiple plots, showing the specified iterations of the fractal.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::{
JSONDrawAction, JSONInput, JSONDrawRules
};
use l_system_fractals::paths::PlotParameters;
use l_system_fractals::num_validity::AlmostEq;
let json_string = r#"{
"command": "PlotMany",
"rules": {
"type": "Advanced",
"replacement": { "A": "A+BA-AA-A-AA+B+AA-BA+AA+A+AA-B-AAA", "B": "BBBBBB" },
"draw_step_sizes": { "A": 1.0 },
"move_step_sizes": { "B": 1.0 },
"angle_numerator": 1,
"angle_denominator": 2,
"start": "A-A-A-A-"
},
"iterations": [0, 1, 2, 3],
"row_len": 2,
"plot_param": {
"width": 700.0,
"height": 700.0,
"border": 50.0,
"fill": "none",
"stroke": "magenta",
"stroke_width": 1
},
"filename": "islands.svg",
"comment": "Benoit B. Mandelbrot (1983), _The Fractal Geometry of Nautre (Updated and Agumented)_, New York: W.H. Freeman and Company, p. 121"
}"#;
let json_input1: JSONInput = serde_json::from_str(json_string).unwrap();
let rules = JSONDrawRules::Advanced {
replacement: HashMap::from([
('A', "A+BA-AA-A-AA+B+AA-BA+AA+A+AA-B-AAA".into()),
('B', "BBBBBB".into())
]),
draw_step_sizes: HashMap::from([('A', 1.0)]),
move_step_sizes: HashMap::from([('B', 1.0)]),
angle_numerator: 1,
angle_denominator: 2,
start: "A-A-A-A-".into()
};
let plot_param = PlotParameters {
width: 700.0,
height: 700.0,
border: 50.0,
fill: "none".into(),
stroke: "magenta".into(),
stroke_width: 1.0,
background: None
};
let json_input2 = JSONInput::PlotMany {
rules,
iterations: vec![0, 1, 2, 3],
row_len: 2,
plot_param,
filename: "islands.svg".into(),
comment: Some("Benoit B. Mandelbrot (1983), _The Fractal Geometry of Nautre".to_string()
+ " (Updated and Agumented)_, New York: W.H. Freeman and Company, p. 121")
};
assert!(json_input1.almost_eq(&json_input2, 0.001));Fields
§
rules: JSONDrawRulesThe rules for the L-system
§
plot_param: PlotParametersThe parameters for the output SVG file
OutputStrings
Does not produce any plots, but rather just performs the string replacement rules.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::JSONInput;
let json_string = r#"{
"command": "OutputStrings",
"rules": { "A": "AB", "B": "BAB" },
"start": "A",
"iteration": 2,
"filename": "text_output.txt"
}"#;
let json_input1: JSONInput = serde_json::from_str(json_string).unwrap();
let json_input2 = JSONInput::OutputStrings {
rules: HashMap::from([('A', "AB".into()), ('B', "BAB".into())]),
start: "A".into(),
iteration: 2,
filename: "text_output.txt".into(),
comment: None
};Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for JSONInput
impl<'de> Deserialize<'de> for JSONInput
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for JSONInput
Auto Trait Implementations§
impl Freeze for JSONInput
impl RefUnwindSafe for JSONInput
impl Send for JSONInput
impl Sync for JSONInput
impl Unpin for JSONInput
impl UnwindSafe for JSONInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more