This repository was archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
Fix/incompatible port snap #62
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,31 +178,62 @@ where | |
let start_pos = port_locations[locator]; | ||
|
||
// Find a port to connect to | ||
fn snap_to_ports<Key: slotmap::Key + Into<AnyParameterId>, Value>( | ||
fn snap_to_ports< | ||
NodeData, | ||
UserState, | ||
DataType: DataTypeTrait<UserState>, | ||
ValueType, | ||
Key: slotmap::Key + Into<AnyParameterId>, | ||
Value, | ||
>( | ||
graph: &Graph<NodeData, DataType, ValueType>, | ||
port_type: &DataType, | ||
ports: &SlotMap<Key, Value>, | ||
port_locations: &PortLocations, | ||
cursor_pos: Pos2, | ||
) -> Pos2 { | ||
ports | ||
.iter() | ||
.find_map(|(port_id, _)| { | ||
port_locations.get(&port_id.into()).and_then(|port_pos| { | ||
if port_pos.distance(cursor_pos) < DISTANCE_TO_CONNECT { | ||
Some(*port_pos) | ||
} else { | ||
None | ||
} | ||
}) | ||
let compatible_ports = graph | ||
.any_param_type(port_id.into()) | ||
.map(|other| other == port_type) | ||
.unwrap_or(false); | ||
|
||
if compatible_ports { | ||
port_locations.get(&port_id.into()).and_then(|port_pos| { | ||
if port_pos.distance(cursor_pos) < DISTANCE_TO_CONNECT { | ||
Some(*port_pos) | ||
} else { | ||
None | ||
} | ||
}) | ||
} else { | ||
None | ||
} | ||
}) | ||
.unwrap_or(cursor_pos) | ||
} | ||
|
||
let (src_pos, dst_pos) = match locator { | ||
AnyParameterId::Output(_) => ( | ||
start_pos, | ||
snap_to_ports(&self.graph.inputs, &port_locations, cursor_pos), | ||
snap_to_ports( | ||
&self.graph, | ||
port_type, | ||
&self.graph.inputs, | ||
&port_locations, | ||
cursor_pos, | ||
), | ||
), | ||
AnyParameterId::Input(_) => ( | ||
snap_to_ports(&self.graph.outputs, &port_locations, cursor_pos), | ||
snap_to_ports( | ||
&self.graph, | ||
port_type, | ||
&self.graph.outputs, | ||
&port_locations, | ||
cursor_pos, | ||
), | ||
start_pos, | ||
), | ||
}; | ||
|
@@ -261,7 +292,7 @@ where | |
self.node_order.retain(|id| *id != *node_id); | ||
} | ||
NodeResponse::DisconnectEvent { input, output } => { | ||
let other_node = self.graph.get_input(*input).node(); | ||
let other_node = self.graph.get_output(*output).node; | ||
Comment on lines
-264
to
+295
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a bug: When a disconnection event occurs, the node that still remains is the one attached to the output side, not the input. |
||
self.graph.remove_connection(*input); | ||
self.connection_in_progress = | ||
Some((other_node, AnyParameterId::Output(*output))); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there's no type inference, even local private functions in Rust, so we need to carry over the ugly generics from the parent calling fn 😬
This cannot be made into a closure (which would support the generics) because it needs to be called with different types, and there's no monomorphization for closures.