Make InterpolationConfig configurable from command line
This commit is contained in:
parent
77e02aa620
commit
d63396b78e
65
src/main.rs
65
src/main.rs
@ -99,7 +99,11 @@ impl Lerp for Point {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn optimize_line(default_weight: u32, line: &str) -> Result<Vec<InputArrayEntry>> {
|
fn optimize_line(
|
||||||
|
default_weight: u32,
|
||||||
|
line: &str,
|
||||||
|
config: &InterpolationConfig,
|
||||||
|
) -> Result<Vec<InputArrayEntry>> {
|
||||||
let frame: Vec<InputArrayEntry> = serde_json::from_str(line)?;
|
let frame: Vec<InputArrayEntry> = serde_json::from_str(line)?;
|
||||||
|
|
||||||
let input_points: Vec<Point> = frame
|
let input_points: Vec<Point> = frame
|
||||||
@ -116,13 +120,8 @@ fn optimize_line(default_weight: u32, line: &str) -> Result<Vec<InputArrayEntry>
|
|||||||
let pg = segments_to_point_graph(&input_points, segs);
|
let pg = segments_to_point_graph(&input_points, segs);
|
||||||
let eg = point_graph_to_euler_graph(&pg);
|
let eg = point_graph_to_euler_graph(&pg);
|
||||||
let ec = euler_graph_to_euler_circuit(&input_points, &eg);
|
let ec = euler_graph_to_euler_circuit(&input_points, &eg);
|
||||||
let output_points: Vec<Point> = interpolate_euler_circuit(
|
let output_points: Vec<Point> =
|
||||||
&input_points,
|
interpolate_euler_circuit(&input_points, &ec, &eg, input_points.len() as u32, config);
|
||||||
&ec,
|
|
||||||
&eg,
|
|
||||||
input_points.len() as u32,
|
|
||||||
&InterpolationConfig::default(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let output_frame: Vec<_> = output_points.iter().map(|p| (p.x, p.y, p.color)).collect();
|
let output_frame: Vec<_> = output_points.iter().map(|p| (p.x, p.y, p.color)).collect();
|
||||||
|
|
||||||
@ -131,20 +130,56 @@ fn optimize_line(default_weight: u32, line: &str) -> Result<Vec<InputArrayEntry>
|
|||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let matches = app_from_crate!()
|
let matches = app_from_crate!()
|
||||||
.args(&[Arg::with_name("default-weight")
|
.args(&[
|
||||||
.short("w")
|
Arg::with_name("default-weight")
|
||||||
.takes_value(true)
|
.short("w")
|
||||||
.multiple(false)
|
.takes_value(true)
|
||||||
.default_value("0")])
|
.multiple(false)
|
||||||
|
.default_value("0"),
|
||||||
|
Arg::with_name("distance-per-point")
|
||||||
|
.short("d")
|
||||||
|
.takes_value(true)
|
||||||
|
.multiple(false),
|
||||||
|
Arg::with_name("blank-delay-points")
|
||||||
|
.short("b")
|
||||||
|
.takes_value(true)
|
||||||
|
.multiple(false),
|
||||||
|
Arg::with_name("radians-per-point")
|
||||||
|
.short("r")
|
||||||
|
.takes_value(true)
|
||||||
|
.multiple(false),
|
||||||
|
])
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let default_weight = matches.value_of("default-weight").unwrap().parse().unwrap();
|
let default_weight = matches.value_of("default-weight").unwrap().parse().unwrap();
|
||||||
|
let mut config = InterpolationConfig::default();
|
||||||
|
|
||||||
|
if let Some(distance_per_point) = matches.value_of("distance-per-point") {
|
||||||
|
config.distance_per_point = distance_per_point
|
||||||
|
.parse()
|
||||||
|
.expect("distance-per-point must be a float")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(blank_delay_points) = matches.value_of("blank-delay-points") {
|
||||||
|
config.blank_delay_points = blank_delay_points
|
||||||
|
.parse()
|
||||||
|
.expect("blank-delay-points must be an unsigned integer")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(radians_per_point) = matches.value_of("radians-per-point") {
|
||||||
|
config.radians_per_point = radians_per_point
|
||||||
|
.parse()
|
||||||
|
.expect("radians-per-point must be a float")
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
io::stdin().read_line(&mut line)?;
|
io::stdin().read_line(&mut line)?;
|
||||||
|
|
||||||
serde_json::to_writer(io::stdout(), &optimize_line(default_weight, &line)?)?;
|
serde_json::to_writer(
|
||||||
|
io::stdout(),
|
||||||
|
&optimize_line(default_weight, &line, &config)?,
|
||||||
|
)?;
|
||||||
io::stdout().write(b"\n")?;
|
io::stdout().write(b"\n")?;
|
||||||
io::stdout().flush()?;
|
io::stdout().flush()?;
|
||||||
}
|
}
|
||||||
@ -152,5 +187,5 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn optimize_line_test() {
|
fn optimize_line_test() {
|
||||||
optimize_line(0, "[[100.0, 100.0, 65280], [100.0, 500.0, 65280], [500.0, 500.0, 65280], [500.0, 100.0, 65280], [100.0, 100.0, 65280]]").unwrap();
|
optimize_line(0, "[[100.0, 100.0, 65280], [100.0, 500.0, 65280], [500.0, 500.0, 65280], [500.0, 100.0, 65280], [100.0, 100.0, 65280]]", &InterpolationConfig::default()).unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user