Skip to content

Commit

Permalink
[NEW] implemented a contsructor for Mapline that gets two arrays with…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
rafaga committed Mar 29, 2024
1 parent 5ca4152 commit 5254894
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egui-map"
version = "0.0.12"
version = "0.0.13"
edition = "2021"
authors = ["Rafael Amador <[email protected]"]
description = "Visual component to draw a map on screen."
Expand Down Expand Up @@ -40,7 +40,7 @@ default = []
puffin = ["dep:puffin"]

[dependencies]
egui = { version = "0.26.2", features = ["bytemuck", "log"]}
egui = { version = "0.27.0", features = ["bytemuck", "log"]}
kdtree = { version = "0.7.0" }
puffin = { version = "0.19.0", optional=true, default-features = false}

Expand Down
9 changes: 5 additions & 4 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,17 @@ impl Map {
if self.zoom > 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,
Expand All @@ -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(_) => (),
}
}
Expand Down
36 changes: 20 additions & 16 deletions src/map/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64>) -> 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;
}
}

Expand Down

0 comments on commit 5254894

Please sign in to comment.