diff --git a/Cargo.lock b/Cargo.lock index ac595f9..235cd07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,14 +541,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" -[[package]] -name = "hwocr" -version = "0.1.0" -dependencies = [ - "relm4", - "rten-tensor", -] - [[package]] name = "indexmap" version = "2.2.3" @@ -1107,6 +1099,14 @@ version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +[[package]] +name = "waywrite" +version = "0.1.0" +dependencies = [ + "relm4", + "rten-tensor", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 69fae56..7a99ab1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hwocr" +name = "waywrite" version = "0.1.0" edition = "2021" diff --git a/src/main.rs b/src/main.rs index 80e86e1..4548b74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt, WidgetExt, Ge use gtk::cairo::{Context, Operator}; use relm4::drawing::DrawHandler; -use hwocr::process_point::to_matrix; -use hwocr::Point; +use waywrite::process_point::to_matrix; +use waywrite::Point; #[derive(Debug)] enum AppInput { @@ -33,9 +33,9 @@ impl SimpleComponent for AppModel { view! { gtk::Window { - set_title: Some("Simple"), - set_default_width: 400, - set_default_height: 100, + set_title: Some("Waywrite"), + set_default_width: 600, + set_default_height: 200, gtk::Box{ set_orientation: gtk::Orientation::Horizontal, @@ -49,10 +49,6 @@ impl SimpleComponent for AppModel { set_margin_all: 5, set_vexpand: true, - gtk::Label { - set_label: "Draw something", - }, - #[local_ref] area -> gtk::DrawingArea { set_vexpand: true, @@ -77,24 +73,18 @@ impl SimpleComponent for AppModel { set_halign: gtk::Align::End, gtk::Button { - set_label: "Increment", + set_label: "Enter", connect_clicked[sender] => move |_| { sender.input(AppInput::Input); } }, gtk::Button { - set_label: "Decrement", + set_label: "Erase", connect_clicked[sender] => move |_| { sender.input(AppInput::Reset); } }, - - gtk::Label { - #[watch] - set_label: &format!("Counter: {}", model.counter), - set_margin_all: 5, - }, } } } @@ -123,6 +113,7 @@ impl SimpleComponent for AppModel { match message { AppInput::Input => { + println!("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); let mat = to_matrix(&self.points); for line in mat.iter() { line.iter().for_each(|x| print!("{}", x)); @@ -163,6 +154,6 @@ fn draw(cx: &Context, points: &[Point]) { } fn main() { - let app = RelmApp::new("relm4.test.simple"); + let app = RelmApp::new("simmer505.waywrite"); app.run::(0); } diff --git a/src/process_point.rs b/src/process_point.rs index 1b07ddc..4731772 100644 --- a/src/process_point.rs +++ b/src/process_point.rs @@ -8,7 +8,9 @@ fn process(points: Vec) -> NdTensor { NdTensor::zeros([1, 1, 1]) } -pub fn to_matrix(points: &Vec) -> Vec>{ +pub fn to_matrix(points: &Vec) -> Vec>{ + + const MATRIX_SIZE: f64 = 200.0; let min_x = points.iter().min_by_key(|p| p.x as i32).unwrap().x; let min_y = points.iter().min_by_key(|p| p.y as i32).unwrap().y; @@ -18,27 +20,28 @@ pub fn to_matrix(points: &Vec) -> Vec>{ let x_len = max_x - min_x; let y_len = max_y - min_y; - let x_scale = 800.0 / x_len; - let y_scale = (y_len / x_len) * x_scale; + let y_ratio = y_len / x_len; + let x_scale = (0.8 * MATRIX_SIZE) / x_len; + let y_scale = ((0.8 * MATRIX_SIZE) * y_ratio) / y_len; let scaled_points = points.iter().map(|point| { - let x_scaled = ((point.x - min_x) * x_scale) + 100.0; - let y_scaled = ((point.y - min_y) * x_scale) + (100.0 * y_scale); + let x_scaled = ((point.x - min_x) * x_scale) + (0.1 * MATRIX_SIZE); + let y_scaled = ((point.y - min_y) * y_scale) + ((0.1 * MATRIX_SIZE) * y_ratio); ((x_scaled, y_scaled), point.new_line) }); - let mut matrix: Vec> = vec![Box::new([-0.0; 1000]); (y_len * y_scale) as u32 as usize]; + let mut matrix: Vec> = vec![Box::new([0.0; MATRIX_SIZE as u32 as usize]); (MATRIX_SIZE * y_ratio) as u64 as usize]; for ((x, y), newline) in scaled_points { - let start_x = x - 1.5; - let end_x = x + 1.5; - let start_y = y - 1.5; - let end_y = y + 1.5; + let start_x = x - (MATRIX_SIZE / 100.0); + let end_x = x + (MATRIX_SIZE / 100.0); + let start_y = y - ((MATRIX_SIZE / 100.0) * y_ratio); + let end_y = y + ((MATRIX_SIZE / 100.0) * y_ratio); - matrix.iter_mut().enumerate().for_each(|(y, line)| line.iter_mut().for_each(|x| { - if (start_x < *x && *x < end_x) && (start_y < (y as f64) && (y as f64) < end_y) { - *x = 1.0; + matrix.iter_mut().enumerate().for_each(|(mat_y, line)| line.iter_mut().enumerate().for_each(|(mat_x, val)| { + if (start_x < (mat_x as f64) && (mat_x as f64) < end_x) && (start_y < (mat_y as f64) && (mat_y as f64) < end_y) { + *val = 1.0; } })); }