From 52548949ece1990ca9c3dfc5625c1ce1b0532520 Mon Sep 17 00:00:00 2001 From: Rafael Amador Date: Thu, 28 Mar 2024 19:18:59 -0600 Subject: [PATCH] [NEW] implemented a contsructor for Mapline that gets two arrays with 2 elements of f32 [NEW] removed the dimension value in MapPoint struct, because it will use a three coordinate system with a conversion to Pos2 based upon a projection algorithm [FIX] id and name properties in mappoint now are private [ENHANCEMENT] using 0.27 version of egui --- Cargo.toml | 4 ++-- src/map.rs | 9 +++++---- src/map/objects.rs | 36 ++++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3936ef3..3defe47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui-map" -version = "0.0.12" +version = "0.0.13" edition = "2021" authors = ["Rafael Amador self.settings.label_visible_zoom && (self.settings.node_text_visibility == VisibilitySetting::Allways || (self.settings.node_text_visibility == VisibilitySetting::Hover - && nearest_id.unwrap_or(&0usize) == &system.id)) + && nearest_id.unwrap_or(&0usize) == &system.get_id())) { let mut viewport_text = viewport_point; viewport_text.x += 3.0 * self.zoom; viewport_text.y -= 3.0 * self.zoom; text_settings.position = viewport_text; - text_settings.text = system.name.to_string(); + text_settings.text = system.get_name(); self.paint_label(paint, &text_settings); } - if let Some(init_time) = self.entities.get(&system.id) { + let system_id = system.get_id(); + if let Some(init_time) = self.entities.get(&system_id) { match Animation::pulse( paint, viewport_point, @@ -512,7 +513,7 @@ impl Map { Ok(true) => { ui_obj.ctx().request_repaint(); } - Ok(false) => nodes_to_remove.push(system.id), + Ok(false) => nodes_to_remove.push(system_id), Err(_) => (), } } diff --git a/src/map/objects.rs b/src/map/objects.rs index 9eedabc..2151d08 100644 --- a/src/map/objects.rs +++ b/src/map/objects.rs @@ -168,43 +168,47 @@ impl MapLine { } } +impl From<([f32; 2], [f32; 2])> for MapLine { + fn from(value: ([f32; 2], [f32; 2])) -> Self { + MapLine::new(value.0[0], value.0[1], value.1[0], value.1[1]) + } +} + // This can by any object or point with its associated metadata /// Struct that contains coordinates to help calculate nearest point in space #[derive(Clone)] pub struct MapPoint { - dimension: usize, /// coordinates of the Solar System pub coords: [f64; 3], /// coordinates for lines connecting this point pub lines: Vec<[f64; 3]>, /// Object Identifier for search propurses - pub id: usize, + id: usize, /// SolarSystem Name - pub name: String, + name: String, } impl MapPoint { /// Creates a new Spatial point with an Id (solarSystemId) and the system's 3D coordinates - pub fn new(id: usize, coords: Vec) -> MapPoint { - let mut point = [0.0f64; 3]; - let size = coords.len(); - point[0] = coords[0]; - point[1] = coords[1]; - if size == 3 { - point[2] = coords[2]; - } + pub fn new(id: usize, coords: [f64; 3]) -> MapPoint { MapPoint { - coords: point, - dimension: size, + coords, id, lines: Vec::new(), name: String::new(), } } - /// Get the number of dimensions used in this object - pub fn get_dimension(self) -> usize { - self.dimension + pub fn get_id(&self) -> usize { + self.id + } + + pub fn get_name(&self) -> String { + self.name.clone() + } + + pub fn set_name(&mut self, value: String) { + self.name = value; } }