Skip to content

Commit

Permalink
Small optimization (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
blitzarx1 authored Apr 27, 2023
1 parent 32c769c commit 3b83f10
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egui_graphs"
version = "0.0.21"
version = "0.0.22"
authors = ["Dmitrii Samsonov <[email protected]>"]
license = "MIT"
homepage = "https://github.com/blitzarx1/egui_graphs"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "basic"
version = "0.0.21"
version = "0.0.22"
authors = ["Dmitrii Samsonov <[email protected]>"]
license = "MIT"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion examples/interactive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "interactive"
version = "0.0.21"
version = "0.0.22"
authors = ["Dmitrii Samsonov <[email protected]>"]
license = "MIT"
edition = "2021"
Expand Down
17 changes: 7 additions & 10 deletions src/graph_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,14 @@ impl<'a> GraphView<'a> {
m.first_frame = false;
}

// TODO: optimize this full scan run with quadtree or similar. Quadtree can be constructed
// on draw_and_sync run and used for operations like node_by_pos and similar.
// need to modify `crate::elements::Elements` to store nodes in a quadtree
// Is it really necessary? Check with benchmarks.
fn node_by_pos(&self, metadata: &Metadata, pos: Pos2) -> Option<(&usize, &'a Node)> {
let node_props = self.elements.get_nodes().iter().find(|(_, n)| {
// TODO: dont make screen transform for every node,
// just make once transform to the graph coordinates for the pos
let node = n.screen_transform(metadata.zoom, metadata.pan);
(node.location - pos.to_vec2()).length() <= node.radius
});
// transform pos to graph coordinates
let pos_in_graph = (pos - metadata.pan).to_vec2() / metadata.zoom;
let node_props = self
.elements
.get_nodes()
.iter()
.find(|(_, n)| (n.location - pos_in_graph).length() <= n.radius);

node_props
}
Expand Down

0 comments on commit 3b83f10

Please sign in to comment.