From efac7e43eb65916850222919b2da65d1f4351e61 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 5 Oct 2023 11:28:40 -0400 Subject: [PATCH] Resolve warnings in the hex-grid app --- hex-grid/src/bin/icon.rs | 4 +--- hex-grid/src/main.rs | 21 +++++++++++---------- hex-grid/src/utilities.rs | 8 ++++---- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/hex-grid/src/bin/icon.rs b/hex-grid/src/bin/icon.rs index 4ff3f93..db2c614 100644 --- a/hex-grid/src/bin/icon.rs +++ b/hex-grid/src/bin/icon.rs @@ -1,7 +1,5 @@ -use gtk::prelude::*; - fn main() { - gtk::init(); + let _ = gtk::init(); for name in gtk::IconTheme::new().icon_names() { println!("{}", name); } diff --git a/hex-grid/src/main.rs b/hex-grid/src/main.rs index 8b9eb03..509c23c 100644 --- a/hex-grid/src/main.rs +++ b/hex-grid/src/main.rs @@ -10,10 +10,9 @@ Luminescent Dreams Tools is distributed in the hope that it will be useful, but You should have received a copy of the GNU General Public License along with Lumeto. If not, see . */ -use cairo::Context; use coordinates::{hex_map::parse_data, AxialAddr}; use gio::resources_lookup_data; -use glib::{subclass::InitializingObject, Object}; +use glib::Object; use gtk::{gio, prelude::*, subclass::prelude::*, Application, DrawingArea}; use image::io::Reader as ImageReader; use std::{cell::RefCell, io::Cursor, rc::Rc}; @@ -23,7 +22,7 @@ mod palette_entry; mod tile; mod utilities; -const APP_ID: &'static str = "com.luminescent-dreams.hex-grid"; +const APP_ID: &str = "com.luminescent-dreams.hex-grid"; const HEX_RADIUS: f64 = 50.; const MAP_RADIUS: usize = 3; const DRAWING_ORIGIN: (f64, f64) = (1024. / 2., 768. / 2.); @@ -178,14 +177,14 @@ impl ObjectImpl for HexGridWindowPrivate { let norm_x = x - DRAWING_ORIGIN.0; let norm_y = y - DRAWING_ORIGIN.1; let q = (2. / 3. * norm_x) / HEX_RADIUS; - let r = (-1. / 3. * norm_x + (3. as f64).sqrt() / 3. * norm_y) / HEX_RADIUS; + let r = (-1. / 3. * norm_x + (3_f64).sqrt() / 3. * norm_y) / HEX_RADIUS; let (q, r) = axial_round(q, r); let coordinate = AxialAddr::new(q, r); canvas_address.set_value(&format!("{:.0} {:.0}", x, y)); if coordinate.distance(&AxialAddr::origin()) > MAP_RADIUS { - hex_address.set_value(&format!("-----")); + hex_address.set_value("-----"); *c.borrow_mut() = None; } else { hex_address.set_value(&format!("{:.0} {:.0}", coordinate.q(), coordinate.r())); @@ -209,10 +208,10 @@ impl ObjectImpl for HexGridWindowPrivate { DRAWING_ORIGIN.0 + HEX_RADIUS * (3. / 2. * (coordinate.q() as f64)); let center_y = DRAWING_ORIGIN.1 + HEX_RADIUS - * ((3. as f64).sqrt() / 2. * (coordinate.q() as f64) - + (3. as f64).sqrt() * (coordinate.r() as f64)); + * ((3_f64).sqrt() / 2. * (coordinate.q() as f64) + + (3_f64).sqrt() * (coordinate.r() as f64)); let translate_x = center_x - HEX_RADIUS; - let translate_y = center_y - (3. as f64).sqrt() * HEX_RADIUS / 2.; + let translate_y = center_y - (3_f64).sqrt() * HEX_RADIUS / 2.; let tile = match hex_map.get(&coordinate).unwrap() { tile::Terrain::Mountain => &mountain, @@ -249,10 +248,11 @@ impl HexGridWindow { } } +/* fn draw_hexagon(context: &Context, center_x: f64, center_y: f64, radius: f64) { let ul_x = center_x - radius; - let ul_y = center_y - (3. as f64).sqrt() * radius / 2.; - let points: Vec<(f64, f64)> = utilities::hexagon(radius * 2., (3. as f64).sqrt() * radius); + let ul_y = center_y - (3_f64).sqrt() * radius / 2.; + let points: Vec<(f64, f64)> = utilities::hexagon(radius * 2., (3_f64).sqrt() * radius); context.new_path(); context.move_to(ul_x + points[0].0, ul_y + points[0].1); context.line_to(ul_x + points[1].0, ul_y + points[1].1); @@ -262,6 +262,7 @@ fn draw_hexagon(context: &Context, center_x: f64, center_y: f64, radius: f64) { context.line_to(ul_x + points[5].0, ul_y + points[5].1); context.close_path(); } +*/ fn axial_round(q_f64: f64, r_f64: f64) -> (i32, i32) { let s_f64 = -q_f64 - r_f64; diff --git a/hex-grid/src/utilities.rs b/hex-grid/src/utilities.rs index 613dce6..5c83f24 100644 --- a/hex-grid/src/utilities.rs +++ b/hex-grid/src/utilities.rs @@ -27,20 +27,20 @@ pub fn hexagon(width: f64, height: f64) -> Vec<(f64, f64)> { (center_x + radius, center_y), ( center_x + radius / 2., - center_y + (3. as f64).sqrt() * radius / 2., + center_y + (3_f64).sqrt() * radius / 2., ), ( center_x - radius / 2., - center_y + (3. as f64).sqrt() * radius / 2., + center_y + (3_f64).sqrt() * radius / 2., ), (center_x - radius, center_y), ( center_x - radius / 2., - center_y - (3. as f64).sqrt() * radius / 2., + center_y - (3_f64).sqrt() * radius / 2., ), ( center_x + radius / 2., - center_y - (3. as f64).sqrt() * radius / 2., + center_y - (3_f64).sqrt() * radius / 2., ), ] }