use egui::{Pos2, Rect, Vec2};
#[derive(Clone, Debug)]
pub enum PathGeometry {
Line { source: Pos2, target: Pos2 },
CubicBezier {
source: Pos2,
target: Pos2,
control: [Pos2; 2],
},
}
#[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),
PathGeometry::CubicBezier {
source,
target,
ref control,
} => Rect::from_points(&[&[source, target], control.as_slice()].concat()),
}
}
pub fn source_pos(&self) -> Pos2 {
match self.path {
PathGeometry::Line { source, .. } | PathGeometry::CubicBezier { source, .. } => source,
}
}
pub fn target_pos(&self) -> Pos2 {
match self.path {
PathGeometry::Line { target, .. } | PathGeometry::CubicBezier { target, .. } => target,
}
}
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(),
}
}
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(),
}
}
}