-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Bezier-curve multi (self-)edges #8256
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bbc6675
Implement bezier edges
grtlr 0eef53a
Almost working multi self-edges
grtlr 2c03394
WIP: Almost woking except bounding_rects.
grtlr e2f3ea1
Include entity rects into layout
grtlr 817eed0
Fix lint
grtlr 70bc926
[skip ci] Most infrastructure in place
grtlr c550b56
[skip c] Basic fan edges working
grtlr d2c4480
Slots working as expected
grtlr b4a4f70
Cleanup
grtlr 0da106a
Fmt
grtlr c2d478f
Address feedback
grtlr c89c6f9
Fix CI
grtlr a57c3c9
Merge branch 'main' into grtlr/graph-better-edges
grtlr 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//! Provides geometric (shape) abstractions for the different elements of a graph layout. | ||
|
||
use egui::{Pos2, Rect, Vec2}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum PathGeometry { | ||
/// A simple straight edge. | ||
Line { source: Pos2, target: Pos2 }, | ||
|
||
/// Represents a cubic bezier curve. | ||
/// | ||
/// In the future we could probably support more complex splines. | ||
CubicBezier { | ||
source: Pos2, | ||
target: Pos2, | ||
control: [Pos2; 2], | ||
}, | ||
// We could add other geometries, such as `Orthogonal` here too. | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct EdgeGeometry { | ||
pub target_arrow: bool, | ||
pub path: PathGeometry, | ||
} | ||
|
||
impl EdgeGeometry { | ||
pub fn bounding_rect(&self) -> Rect { | ||
match self.path { | ||
PathGeometry::Line { source, target } => Rect::from_two_pos(source, target), | ||
// TODO(grtlr): This is just a crude (upper) approximation, as the resulting bounding box can be too large. | ||
// For now this is fine, as there are no interactions on edges yet. | ||
PathGeometry::CubicBezier { | ||
source, | ||
target, | ||
ref control, | ||
} => Rect::from_points(&[&[source, target], control.as_slice()].concat()), | ||
} | ||
} | ||
|
||
/// The starting position of an edge. | ||
pub fn source_pos(&self) -> Pos2 { | ||
match self.path { | ||
PathGeometry::Line { source, .. } | PathGeometry::CubicBezier { source, .. } => source, | ||
} | ||
} | ||
|
||
/// The end position of an edge. | ||
pub fn target_pos(&self) -> Pos2 { | ||
match self.path { | ||
PathGeometry::Line { target, .. } | PathGeometry::CubicBezier { target, .. } => target, | ||
} | ||
} | ||
|
||
/// The direction of the edge at the source node (normalized). | ||
pub fn source_arrow_direction(&self) -> Vec2 { | ||
use PathGeometry::{CubicBezier, Line}; | ||
match self.path { | ||
Line { source, target } => (source.to_vec2() - target.to_vec2()).normalized(), | ||
CubicBezier { | ||
source, control, .. | ||
} => (control[0].to_vec2() - source.to_vec2()).normalized(), | ||
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. e.g. kurbo could provide the actual tangent here |
||
} | ||
} | ||
|
||
/// The direction of the edge at the target node (normalized). | ||
pub fn target_arrow_direction(&self) -> Vec2 { | ||
use PathGeometry::{CubicBezier, Line}; | ||
match self.path { | ||
Line { source, target } => (target.to_vec2() - source.to_vec2()).normalized(), | ||
CubicBezier { | ||
target, control, .. | ||
} => (target.to_vec2() - control[1].to_vec2()).normalized(), | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
mod geometry; | ||
mod provider; | ||
mod request; | ||
mod result; | ||
mod slots; | ||
|
||
pub use geometry::{EdgeGeometry, PathGeometry}; | ||
pub use provider::ForceLayoutProvider; | ||
pub use request::LayoutRequest; | ||
pub use request::{EdgeTemplate, LayoutRequest}; | ||
pub use result::Layout; |
Oops, something went wrong.
Oops, something went wrong.
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.
Note: we already depends on
kurbo
. I have a good experience using this crate for geometric primitives. Might be worth using it for some computations (e.g. bbox, linear approximation, etc.) if the need increases.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.
Awesome, I heard good things about
kurbo
too!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.
I've been using it lots in my personal projects.