diff --git a/Cargo.lock b/Cargo.lock index 00d67d3..71e596b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,7 +329,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "basic" -version = "0.5.3" +version = "0.5.4-beta.0" dependencies = [ "eframe", "egui", @@ -339,7 +339,7 @@ dependencies = [ [[package]] name = "basic_interactive" -version = "0.5.3" +version = "0.5.4-beta.0" dependencies = [ "eframe", "egui", @@ -349,7 +349,7 @@ dependencies = [ [[package]] name = "basic_undirected" -version = "0.5.3" +version = "0.5.4-beta.0" dependencies = [ "eframe", "egui", @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "configurable" -version = "0.5.3" +version = "0.5.4-beta.0" dependencies = [ "eframe", "egui", @@ -802,7 +802,7 @@ dependencies = [ [[package]] name = "egui_graphs" -version = "0.5.3" +version = "0.5.4-beta.0" dependencies = [ "egui", "petgraph", diff --git a/Cargo.toml b/Cargo.toml index 45f32db..db1b33e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui_graphs" -version = "0.5.3" +version = "0.5.4-beta.0" authors = ["Dmitrii Samsonov "] license = "MIT" homepage = "https://github.com/blitzarx1/egui_graphs" diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml index 328a2de..d9323a8 100644 --- a/examples/basic/Cargo.toml +++ b/examples/basic/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basic" -version = "0.5.3" +version = "0.5.4-beta.0" authors = ["Dmitrii Samsonov "] license = "MIT" edition = "2021" diff --git a/examples/basic_interactive/Cargo.toml b/examples/basic_interactive/Cargo.toml index 45ddcbe..02f909b 100644 --- a/examples/basic_interactive/Cargo.toml +++ b/examples/basic_interactive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basic_interactive" -version = "0.5.3" +version = "0.5.4-beta.0" authors = ["Dmitrii Samsonov "] license = "MIT" edition = "2021" diff --git a/examples/basic_undirected/Cargo.toml b/examples/basic_undirected/Cargo.toml index 08cfeae..6fab573 100644 --- a/examples/basic_undirected/Cargo.toml +++ b/examples/basic_undirected/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basic_undirected" -version = "0.5.3" +version = "0.5.4-beta.0" authors = ["Dmitrii Samsonov "] license = "MIT" edition = "2021" diff --git a/examples/configurable/Cargo.toml b/examples/configurable/Cargo.toml index 40c7af9..2242055 100644 --- a/examples/configurable/Cargo.toml +++ b/examples/configurable/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "configurable" -version = "0.5.3" +version = "0.5.4-beta.0" authors = ["Dmitrii Samsonov "] license = "MIT" edition = "2021" diff --git a/examples/configurable/src/main.rs b/examples/configurable/src/main.rs index c856bf6..3178782 100644 --- a/examples/configurable/src/main.rs +++ b/examples/configurable/src/main.rs @@ -142,16 +142,16 @@ impl ConfigurableApp { let g_n = self.g.node_weight_mut(*g_n_idx).unwrap(); let sim_n = self.sim.get_graph_mut().node_weight_mut(*g_n_idx).unwrap(); - if g_n.dragged { - let loc = g_n.location; + if g_n.dragged() { + let loc = g_n.location(); sim_n.location = Vec3::new(loc.x, loc.y, 0.); return; } let loc = sim_n.location; - g_n.location = Vec2::new(loc.x, loc.y); + g_n.set_location(Vec2::new(loc.x, loc.y)); - if g_n.selected { + if g_n.selected() { self.selected_nodes.push(g_n.clone()); } }); @@ -233,8 +233,8 @@ impl ConfigurableApp { // location of new node is in surrounging of random existing node let mut rng = rand::thread_rng(); let location = Vec2::new( - random_n.location.x + 10. + rng.gen_range(0. ..50.), - random_n.location.y + 10. + rng.gen_range(0. ..50.), + random_n.location().x + 10. + rng.gen_range(0. ..50.), + random_n.location().y + 10. + rng.gen_range(0. ..50.), ); let idx = self.g.add_node(Node::new(location, ())); diff --git a/src/drawer.rs b/src/drawer.rs index f60c483..ee214fc 100644 --- a/src/drawer.rs +++ b/src/drawer.rs @@ -1,6 +1,6 @@ use std::{ collections::HashMap, - f32::{MAX, MIN}, + f32::{consts::PI, MAX, MIN}, }; use egui::{ @@ -70,27 +70,27 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { // we shall account for the node radius // so that the node is fully visible - let x_minus_rad = n.location.x - comp_node.radius(self.meta); + let x_minus_rad = n.location().x - comp_node.radius(self.meta); if x_minus_rad < min_x { min_x = x_minus_rad; }; - let y_minus_rad = n.location.y - comp_node.radius(self.meta); + let y_minus_rad = n.location().y - comp_node.radius(self.meta); if y_minus_rad < min_y { min_y = y_minus_rad; }; - let x_plus_rad = n.location.x + comp_node.radius(self.meta); + let x_plus_rad = n.location().x + comp_node.radius(self.meta); if x_plus_rad > max_x { max_x = x_plus_rad; }; - let y_plus_rad = n.location.y + comp_node.radius(self.meta); + let y_plus_rad = n.location().y + comp_node.radius(self.meta); if y_plus_rad > max_y { max_y = y_plus_rad; }; - if n.dragged { + if n.dragged() { new_dragged = Some(idx); } @@ -221,27 +221,33 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { return vec![]; } - let pos_start_and_end = n.location.to_pos2(); - let loop_size = comp_node.radius(self.meta) * (4. + 1. + order as f32); + let center_horizont_angle = PI / 4.; + let center = n.location(); + let y_intersect = center.y - comp_node.radius(self.meta) * center_horizont_angle.sin(); - let control_point1 = Pos2::new( - pos_start_and_end.x + loop_size, - pos_start_and_end.y - loop_size, + let left_intersect = Pos2::new( + center.x - comp_node.radius(self.meta) * center_horizont_angle.cos(), + y_intersect, ); - let control_point2 = Pos2::new( - pos_start_and_end.x - loop_size, - pos_start_and_end.y - loop_size, + let right_intersect = Pos2::new( + center.x + comp_node.radius(self.meta) * center_horizont_angle.cos(), + y_intersect, ); - let stroke = Stroke::new(e.width, self.settings_style.color_edge(self.p.ctx(), e)); + let loop_size = comp_node.radius(self.meta) * (4. + 1. + order as f32); + + let control_point1 = Pos2::new(center.x + loop_size, center.y - loop_size); + let control_point2 = Pos2::new(center.x - loop_size, center.y - loop_size); + + let stroke = Stroke::new(e.width(), self.settings_style.color_edge(self.p.ctx(), e)); let shape_basic = CubicBezierShape::from_points_stroke( [ - pos_start_and_end, + right_intersect, control_point1, control_point2, - pos_start_and_end, + left_intersect, ], - true, + false, Color32::TRANSPARENT, stroke, ); @@ -254,17 +260,17 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { let mut shapes = vec![shape_basic]; let highlighted_stroke = Stroke::new( - e.width * 2., + e.width() * 2., self.settings_style.color_edge_highlight(comp_edge).unwrap(), ); shapes.push(CubicBezierShape::from_points_stroke( [ - pos_start_and_end, + right_intersect, control_point1, control_point2, - pos_start_and_end, + left_intersect, ], - true, + false, Color32::TRANSPARENT, highlighted_stroke, )); @@ -286,7 +292,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { let mut end_node = self.g.node(*end_idx).unwrap(); let mut transparent = false; - if (start_node.folded || comp_start.subfolded()) && comp_end.subfolded() { + if (start_node.folded() || comp_start.subfolded()) && comp_end.subfolded() { return (vec![], vec![]); } @@ -320,8 +326,8 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { transparent = true; } - let pos_start = start_node.screen_transform(self.meta).location.to_pos2(); - let pos_end = end_node.screen_transform(self.meta).location.to_pos2(); + let pos_start = start_node.screen_transform(self.meta).location().to_pos2(); + let pos_end = end_node.screen_transform(self.meta).location().to_pos2(); let vec = pos_end - pos_start; let l = vec.length(); @@ -339,13 +345,13 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { if transparent { color = color.gamma_multiply(0.15); } - let stroke = Stroke::new(e.width, color); + let stroke = Stroke::new(e.width(), color); // draw straight edge if order == 0 { let mut shapes = vec![]; - let head_point_1 = tip_point - e.tip_size * rotate_vector(dir, e.tip_angle); - let head_point_2 = tip_point - e.tip_size * rotate_vector(dir, -e.tip_angle); + let head_point_1 = tip_point - e.tip_size() * rotate_vector(dir, e.tip_angle()); + let head_point_2 = tip_point - e.tip_size() * rotate_vector(dir, -e.tip_angle()); shapes.push(Shape::line_segment([start_point, tip_point], stroke)); @@ -364,7 +370,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { } let highlighted_stroke = Stroke::new( - e.width * 2., + e.width() * 2., self.settings_style.color_edge_highlight(comp_edge).unwrap(), ); shapes.push(Shape::line_segment( @@ -391,14 +397,14 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { let dir_perpendicular = Vec2::new(-dir.y, dir.x); let center_point = (start_point + tip_point.to_vec2()).to_vec2() / 2.0; let control_point = - (center_point + dir_perpendicular * e.curve_size * order as f32).to_pos2(); + (center_point + dir_perpendicular * e.curve_size() * order as f32).to_pos2(); let tip_vec = control_point - tip_point; let tip_dir = tip_vec / tip_vec.length(); - let tip_size = e.tip_size; + let tip_size = e.tip_size(); - let arrow_tip_dir_1 = rotate_vector(tip_dir, e.tip_angle) * tip_size; - let arrow_tip_dir_2 = rotate_vector(tip_dir, -e.tip_angle) * tip_size; + let arrow_tip_dir_1 = rotate_vector(tip_dir, e.tip_angle()) * tip_size; + let arrow_tip_dir_2 = rotate_vector(tip_dir, -e.tip_angle()) * tip_size; let head_point_1 = tip_point + arrow_tip_dir_1; let head_point_2 = tip_point + arrow_tip_dir_2; @@ -424,7 +430,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { } let highlighted_stroke = Stroke::new( - e.width * 2., + e.width() * 2., self.settings_style.color_edge_highlight(comp_edge).unwrap(), ); quadratic_shapes.push(QuadraticBezierShape::from_points_stroke( @@ -451,7 +457,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { comp_node: &StateComputedNode, ) -> (Vec, Vec) { let node = &n.screen_transform(self.meta); - let loc = node.location.to_pos2(); + let loc = node.location().to_pos2(); let (mut circles, mut texts) = self.draw_node_basic(loc, node, comp_node); let (circles_interacted, texts_interacted) = @@ -463,10 +469,10 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { fn shape_label(&self, node_radius: f32, n: &Node) -> Option { let color_label = self.settings_style.color_label(self.p.ctx()); - let label_pos = Pos2::new(n.location.x, n.location.y - node_radius * 2.); + let label_pos = Pos2::new(n.location().x, n.location().y - node_radius * 2.); let label_size = node_radius; let galley = self.p.layout_no_wrap( - n.label.as_ref()?.clone(), + n.label()?.clone(), FontId::new(label_size, FontFamily::Monospace), color_label, ); @@ -482,10 +488,10 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { ) -> (Vec, Vec) { let color = self.settings_style.color_node(self.p.ctx(), node); let mut nodes = vec![]; - if !(node.selected + if !(node.selected() || comp_node.subselected() - || node.dragged - || node.folded + || node.dragged() + || node.folded() || comp_node.subfolded()) { // draw not interacted nodes in place @@ -507,7 +513,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { return (nodes, vec![]); } - if node.folded || comp_node.subfolded() { + if node.folded() || comp_node.subfolded() { return (nodes, vec![]); } @@ -530,10 +536,10 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { node: &Node, comp_node: &StateComputedNode, ) -> (Vec, Vec) { - if !(node.selected + if !(node.selected() || comp_node.subselected() - || node.dragged - || node.folded + || node.dragged() + || node.folded() || comp_node.subfolded()) { return (vec![], vec![]); @@ -553,7 +559,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> Drawer<'a, N, E, Ty> { texts.push(label_shape); }; - if node.folded { + if node.folded() { shape = CircleShape::stroke( loc, node_radius, diff --git a/src/elements.rs b/src/elements.rs index f2e3884..c094693 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -6,18 +6,18 @@ use crate::metadata::Metadata; #[derive(Clone, Debug, PartialEq)] pub struct Node { /// Client data - pub data: Option, + data: Option, - pub location: Vec2, + location: Vec2, - pub label: Option, + label: Option, /// If `color` is None default color is used. - pub color: Option, + color: Option, - pub folded: bool, - pub selected: bool, - pub dragged: bool, + folded: bool, + selected: bool, + dragged: bool, } impl Default for Node { @@ -44,12 +44,62 @@ impl Node { } } + pub fn data(&self) -> Option<&N> { + self.data.as_ref() + } + + pub fn location(&self) -> Vec2 { + self.location + } + + pub fn set_location(&mut self, loc: Vec2) { + self.location = loc + } + + pub fn folded(&self) -> bool { + self.folded + } + + pub fn set_folded(&mut self, folded: bool) { + self.folded = folded; + } + + pub fn selected(&self) -> bool { + self.selected + } + + pub fn set_selected(&mut self, selected: bool) { + self.selected = selected; + } + + pub fn dragged(&self) -> bool { + self.dragged + } + + pub fn set_dragged(&mut self, dragged: bool) { + self.dragged = dragged; + } + + pub fn label(&self) -> Option<&String> { + self.label.as_ref() + } + pub fn with_label(&mut self, label: String) -> Self { let mut res = self.clone(); res.label = Some(label); res } + pub fn color(&self) -> Option { + self.color + } + + pub fn with_color(&mut self, color: Color32) -> Self { + let mut res = self.clone(); + res.color = Some(color); + res + } + pub fn screen_transform(&self, meta: &Metadata) -> Self { Self { location: self.location * meta.zoom + meta.pan, @@ -69,15 +119,15 @@ impl Node { #[derive(Clone, Debug, Copy, PartialEq)] pub struct Edge { /// Client data - pub data: Option, + data: Option, - pub width: f32, - pub tip_size: f32, - pub tip_angle: f32, - pub curve_size: f32, + width: f32, + tip_size: f32, + tip_angle: f32, + curve_size: f32, /// If `color` is None default color is used. - pub color: Option, + color: Option, } impl Default for Edge { @@ -103,6 +153,36 @@ impl Edge { } } + pub fn width(&self) -> f32 { + self.width + } + + pub fn tip_size(&self) -> f32 { + self.tip_size + } + + pub fn tip_angle(&self) -> f32 { + self.tip_angle + } + + pub fn curve_size(&self) -> f32 { + self.curve_size + } + + pub fn data(&self) -> Option<&E> { + self.data.as_ref() + } + + pub fn color(&self) -> Option { + self.color + } + + pub fn with_color(&mut self, color: Color32) -> Self { + let mut res = self.clone(); + res.color = Some(color); + res + } + pub(crate) fn screen_transform(&self, meta: &Metadata) -> Self { Self { width: self.width * meta.zoom, diff --git a/src/graph_view.rs b/src/graph_view.rs index 34252b6..01f1d8d 100644 --- a/src/graph_view.rs +++ b/src/graph_view.rs @@ -113,22 +113,22 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> GraphView<'a, N, E, Ty> { let (mut min_x, mut min_y, mut max_x, mut max_y) = (MAX, MAX, MIN, MIN); self.g.nodes_with_context(state).for_each(|(_, n, comp)| { - let x_minus_rad = n.location.x - comp.radius(meta); + let x_minus_rad = n.location().x - comp.radius(meta); if x_minus_rad < min_x { min_x = x_minus_rad; }; - let y_minus_rad = n.location.y - comp.radius(meta); + let y_minus_rad = n.location().y - comp.radius(meta); if y_minus_rad < min_y { min_y = y_minus_rad; }; - let x_plus_rad = n.location.x + comp.radius(meta); + let x_plus_rad = n.location().x + comp.radius(meta); if x_plus_rad > max_x { max_x = x_plus_rad; }; - let y_plus_rad = n.location.y + comp.radius(meta); + let y_plus_rad = n.location().y + comp.radius(meta); if y_plus_rad > max_y { max_y = y_plus_rad; }; @@ -226,7 +226,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> GraphView<'a, N, E, Ty> { } let n = self.g.node(idx).unwrap(); - if n.selected { + if n.selected() { self.set_node_selected(idx, false); return; } @@ -346,15 +346,15 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> GraphView<'a, N, E, Ty> { fn set_node_selected(&mut self, idx: NodeIndex, val: bool) { let n = self.g.node_mut(idx).unwrap(); - let change = ChangeNode::change_selected(idx, n.selected, val); - n.selected = val; + let change = ChangeNode::change_selected(idx, n.selected(), val); + n.set_selected(val); self.send_changes(Change::node(change)); } fn set_node_folded(&mut self, idx: NodeIndex, val: bool) { let n = self.g.node_mut(idx).unwrap(); - let change = ChangeNode::change_folded(idx, n.folded, val); - n.folded = val; + let change = ChangeNode::change_folded(idx, n.folded(), val); + n.set_folded(val); self.send_changes(Change::node(change)); } @@ -384,16 +384,16 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> GraphView<'a, N, E, Ty> { fn set_dragged(&mut self, idx: NodeIndex, val: bool) { let n = self.g.node_mut(idx).unwrap(); - let change = ChangeNode::change_dragged(idx, n.dragged, val); - n.dragged = val; + let change = ChangeNode::change_dragged(idx, n.dragged(), val); + n.set_dragged(val); self.send_changes(Change::node(change)); } fn move_node(&mut self, idx: NodeIndex, delta: Vec2) { let n = self.g.node_mut(idx).unwrap(); - let new_loc = n.location + delta; - let change = ChangeNode::change_location(idx, n.location, new_loc); - n.location = new_loc; + let new_loc = n.location() + delta; + let change = ChangeNode::change_location(idx, n.location(), new_loc); + n.set_location(new_loc); self.send_changes(Change::node(change)); } diff --git a/src/graph_wrapper.rs b/src/graph_wrapper.rs index 8b0e747..f50e47e 100644 --- a/src/graph_wrapper.rs +++ b/src/graph_wrapper.rs @@ -31,7 +31,7 @@ impl<'a, N: Clone, E: Clone, Ty: EdgeType> GraphWrapper<'a, N, E, Ty> { // transform pos to graph coordinates let pos_in_graph = (pos - meta.pan).to_vec2() / meta.zoom; self.nodes_with_context(comp) - .find(|(_, n, comp)| (n.location - pos_in_graph).length() <= comp.radius(meta)) + .find(|(_, n, comp)| (n.location() - pos_in_graph).length() <= comp.radius(meta)) } pub fn nodes_with_context( diff --git a/src/settings.rs b/src/settings.rs index ceb912b..d97dbd3 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -121,8 +121,8 @@ impl Default for SettingsStyle { impl SettingsStyle { pub(crate) fn color_node(&self, ctx: &egui::Context, n: &Node) -> Color32 { - if n.color.is_some() { - return n.color.unwrap(); + if n.color().is_some() { + return n.color().unwrap(); } if ctx.style().visuals.dark_mode { @@ -144,11 +144,11 @@ impl SettingsStyle { n: &Node, comp: &StateComputedNode, ) -> Option { - if n.dragged { + if n.dragged() { return Some(self.color_drag); } - if n.selected { + if n.selected() { return Some(self.color_selection); } @@ -164,8 +164,8 @@ impl SettingsStyle { } pub(crate) fn color_edge(&self, ctx: &egui::Context, e: &Edge) -> Color32 { - if e.color.is_some() { - return e.color.unwrap(); + if e.color().is_some() { + return e.color().unwrap(); } if ctx.style().visuals.dark_mode { diff --git a/src/state_computed.rs b/src/state_computed.rs index dcaefd3..e67ca16 100644 --- a/src/state_computed.rs +++ b/src/state_computed.rs @@ -90,7 +90,7 @@ impl StateComputed { child_mode: bool, depth: i32, ) { - if !root.selected { + if !root.selected() { return; } @@ -134,7 +134,7 @@ impl StateComputed { root: &Node, depth: usize, ) { - if !root.folded { + if !root.folded() { return; } diff --git a/src/transform.rs b/src/transform.rs index 1655f28..380e4cb 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -43,16 +43,16 @@ pub const DEFAULT_SPAWN_SIZE: f32 = 250.; /// let mut input_indices = input_graph.node_indices(); /// let input_node_1 = input_indices.next().unwrap(); /// let input_node_2 = input_indices.next().unwrap(); -/// assert_eq!(input_graph.node_weight(input_node_1).unwrap().data, Some("A")); -/// assert_eq!(input_graph.node_weight(input_node_2).unwrap().data, Some("B")); +/// assert_eq!(*input_graph.node_weight(input_node_1).unwrap().data().clone().unwrap(), "A"); +/// assert_eq!(*input_graph.node_weight(input_node_2).unwrap().data().clone().unwrap(), "B"); /// -/// assert_eq!(input_graph.edge_weight(input_graph.edge_indices().next().unwrap()).unwrap().data, Some("edge1")); +/// assert_eq!(*input_graph.edge_weight(input_graph.edge_indices().next().unwrap()).unwrap().data().clone().unwrap(), "edge1"); /// -/// assert_eq!(input_graph.node_weight(input_node_1).unwrap().label.clone().unwrap(), input_node_1.index().to_string()); -/// assert_eq!(input_graph.node_weight(input_node_2).unwrap().label.clone().unwrap(), input_node_2.index().to_string()); +/// assert_eq!(*input_graph.node_weight(input_node_1).unwrap().label().clone().unwrap(), input_node_1.index().to_string()); +/// assert_eq!(*input_graph.node_weight(input_node_2).unwrap().label().clone().unwrap(), input_node_2.index().to_string()); /// -/// let loc_1 = input_graph.node_weight(input_node_1).unwrap().location; -/// let loc_2 = input_graph.node_weight(input_node_2).unwrap().location; +/// let loc_1 = input_graph.node_weight(input_node_1).unwrap().location(); +/// let loc_2 = input_graph.node_weight(input_node_2).unwrap().location(); /// assert!(loc_1 != Vec2::ZERO); /// assert!(loc_2 != Vec2::ZERO); /// ``` @@ -147,16 +147,19 @@ mod tests { let user_n = user_g.node_weight(user_idx).unwrap(); let input_n = input_g.node_weight(input_idx).unwrap(); - assert_eq!(input_n.data, Some(*user_n)); + assert_eq!(*input_n.data().clone().unwrap(), *user_n); - assert!(input_n.location.x >= 0.0 && input_n.location.x <= DEFAULT_SPAWN_SIZE); - assert!(input_n.location.y >= 0.0 && input_n.location.y <= DEFAULT_SPAWN_SIZE); + assert!(input_n.location().x >= 0.0 && input_n.location().x <= DEFAULT_SPAWN_SIZE); + assert!(input_n.location().y >= 0.0 && input_n.location().y <= DEFAULT_SPAWN_SIZE); - assert_eq!(input_n.label.clone().unwrap(), user_idx.index().to_string()); + assert_eq!( + *input_n.label().clone().unwrap(), + user_idx.index().to_string() + ); - assert_eq!(input_n.color, None); - assert!(!input_n.selected); - assert!(!input_n.dragged); + assert_eq!(input_n.color(), None); + assert!(!input_n.selected()); + assert!(!input_n.dragged()); } } @@ -177,16 +180,19 @@ mod tests { let user_n = user_g.node_weight(user_idx).unwrap(); let input_n = input_g.node_weight(input_idx).unwrap(); - assert_eq!(input_n.data, Some(*user_n)); + assert_eq!(*input_n.data().clone().unwrap(), *user_n); - assert!(input_n.location.x >= 0.0 && input_n.location.x <= DEFAULT_SPAWN_SIZE); - assert!(input_n.location.y >= 0.0 && input_n.location.y <= DEFAULT_SPAWN_SIZE); + assert!(input_n.location().x >= 0.0 && input_n.location().x <= DEFAULT_SPAWN_SIZE); + assert!(input_n.location().y >= 0.0 && input_n.location().y <= DEFAULT_SPAWN_SIZE); - assert_eq!(input_n.label.clone().unwrap(), user_idx.index().to_string()); + assert_eq!( + *input_n.label().clone().unwrap(), + user_idx.index().to_string() + ); - assert_eq!(input_n.color, None); - assert!(!input_n.selected); - assert!(!input_n.dragged); + assert_eq!(input_n.color(), None); + assert!(!input_n.selected()); + assert!(!input_n.dragged()); } } }