-
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
Conversation
Web viewer built successfully. If applicable, you should also test it:
Note: This comment is updated whenever you push a commit. |
e194dc2
to
c550b56
Compare
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.
Very nice!
/// Represents a cubic bezier curve. | ||
/// | ||
/// In the future we could probably support more complex splines. | ||
CubicBezier { |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. kurbo could provide the actual tangent here
target: anchor + Vec2::RIGHT * 4., | ||
// TODO(grtlr): The actual length of that spline should follow the `distance` parameter of the link force. | ||
control: [ | ||
anchor + Vec2::new(-30. * offset, -40. * offset), |
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.
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.
Yeah, sorry I should have mentioned. I didn't want to get into edge routing just yet. I've created an issue here to track this: #8291
points: [source, control[0], control[1], target], | ||
closed: false, | ||
fill: Color32::TRANSPARENT, | ||
stroke: stroke.into(), |
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.
oh nice, that was easy enough :)
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.
Yeah, we will run into limitations though when we want to draw more complex edges (such as in GraphViz layouts), because that's currently not supported by egui
.
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.
This is where kurbo can help. It can convert various things to cubic bezier, and can also linearise everything to polylines.
} | ||
|
||
// We can add interactions in the future, for now we simply allocate the | ||
// rect, so that bounding boxes are computed correctly. | ||
ui.allocate_rect(rect, NON_SENSE) | ||
ui.allocate_rect(geometry.bounding_rect(), NON_SENSE) |
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.
idiomatically, NON_SENSE
is egui::Sense::hover()
. Also, nonsense sounds... weird :)
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.
That was a pun that somehow made it through the previous review process, I've removed the code 😇.
Related
What
This PR brings self-edges in the form of Bezier-curves.
It also tries to make multiple edges between the same node more legible by applying a small arc on such edges to prevent overlap.