Compare commits

...

2 Commits
v0.2 ... master

1 changed files with 50 additions and 9 deletions

View File

@ -4,9 +4,9 @@ use anyhow::Result;
use clap::{app_from_crate, crate_authors, crate_description, crate_name, crate_version, Arg};
use io::Write;
use lasy::{
euler_graph_to_euler_circuit, interpolate_euler_circuit, point_graph_to_euler_graph,
points_to_segments, segments_to_point_graph, Blanked, InterpolationConfig, IsBlank, Lerp,
Position, Weight,
blank_segment_points, euler_graph_to_euler_circuit, interpolate_euler_circuit,
point_graph_to_euler_graph, points_to_segments, segments_to_point_graph, Blanked,
InterpolationConfig, IsBlank, Lerp, Position, Weight,
};
type InputArrayEntry = (f32, f32, u32);
@ -50,14 +50,14 @@ impl Position for Point {
impl IsBlank for Point {
fn is_blank(&self) -> bool {
self.color == 0xffffff
self.color == 0
}
}
impl Blanked for Point {
fn blanked(&self) -> Self {
Self {
color: 0xffffff,
color: 0,
..*self
}
}
@ -172,14 +172,55 @@ fn main() -> Result<()> {
.expect("radians-per-point must be a float")
}
let mut last_frames = vec![];
loop {
let mut line = String::new();
io::stdin().read_line(&mut line)?;
serde_json::to_writer(
io::stdout(),
&optimize_line(default_weight, &line, &config)?,
)?;
last_frames.push(optimize_line(default_weight, &line, &config)?);
if last_frames.len() == 2 {
let a: Vec<Point> = last_frames
.first()
.unwrap()
.iter()
.map(|(x, y, color)| Point {
x: *x,
y: *y,
color: *color,
weight: default_weight,
})
.collect();
let b: Vec<Point> = last_frames
.last()
.unwrap()
.iter()
.map(|(x, y, color)| Point {
x: *x,
y: *y,
color: *color,
weight: default_weight,
})
.collect();
let c: Vec<InputArrayEntry> = a
.into_iter()
.zip(b.into_iter())
.map(|(a, b)| blank_segment_points(a, b, config.blank_delay_points))
.flatten()
.map(|p| (p.x, p.y, p.color))
.collect();
serde_json::to_writer(io::stdout(), &c)?;
io::stdout().write(b"\n")?;
io::stdout().flush()?;
last_frames.remove(0);
}
serde_json::to_writer(io::stdout(), &last_frames.last())?;
io::stdout().write(b"\n")?;
io::stdout().flush()?;
}