use crate::resolve::{AttrMap, Markers, NodeKind, ResolvedValue, SheetInputs, Strategy, VarTable};
use crate::span::Span;
pub struct LaidOut {
pub viewbox: ViewBox,
pub nodes: Vec<PlacedNode>,
pub links: Vec<RoutedLink>,
pub link_report: Vec<crate::routing::Violation>,
pub strays: Vec<Stray>,
pub vars: VarTable,
pub sheet: SheetInputs,
pub canvas_fill: Option<ResolvedValue>,
pub gradients: Vec<GradientDef>,
pub hatches: Vec<HatchDef>,
}
#[derive(Clone)]
pub struct HatchDef {
pub angles: Vec<f64>,
pub pitch: f64,
pub color: ResolvedValue,
}
#[derive(Clone)]
pub struct GradientDef {
pub kind: GradientKind,
pub stops: Vec<ResolvedValue>,
}
#[derive(Clone, Copy)]
pub enum GradientKind {
Linear(f64),
Radial,
}
#[derive(Clone)]
pub struct Stray {
pub from: (f64, f64),
pub to: (f64, f64),
pub data_from: String,
pub data_to: String,
}
#[derive(Clone)]
pub struct RoutedLink {
pub path: Vec<(f64, f64)>,
pub strategy: Strategy,
pub markers: Markers,
pub attrs: AttrMap,
pub applied_styles: Vec<String>,
pub texts: Vec<RoutedText>,
pub data_from: String,
pub data_to: String,
pub seg_from: String,
pub seg_to: String,
pub decl_span: Span,
pub fan_from: Option<u32>,
pub fan_to: Option<u32>,
}
#[derive(Clone)]
pub struct RoutedText {
pub content: String,
pub position: (f64, f64),
pub tangent: (f64, f64),
pub attrs: AttrMap,
pub class: &'static str,
}
pub const LINK_LABEL_CLASS: &str = "lini-link-label";
pub const SEQUENCE_MESSAGE_CLASS: &str = "lini-sequence-message";
#[derive(Debug, Clone, Copy)]
pub struct ViewBox {
pub x: f64,
pub y: f64,
pub w: f64,
pub h: f64,
}
pub type Gutter = (f64, f64, f64, f64);
#[derive(Clone)]
pub struct PlacedNode {
pub id: Option<String>,
pub kind: NodeKind,
pub type_chain: Vec<String>,
pub applied_styles: Vec<String>,
pub label: Option<String>,
pub attrs: AttrMap,
pub own_style: AttrMap,
pub markers: Markers,
pub cx: f64,
pub cy: f64,
pub bbox: Bbox,
pub rotation: f64,
pub children: Vec<PlacedNode>,
pub gutters: Vec<Gutter>,
pub links: Vec<RoutedLink>,
pub sketch: Option<std::sync::Arc<super::drawing::SketchGeo>>,
pub span: Span,
}
#[derive(Debug, Clone, Copy)]
pub struct Bbox {
pub min_x: f64,
pub min_y: f64,
pub max_x: f64,
pub max_y: f64,
}
impl Bbox {
pub fn empty() -> Self {
Self {
min_x: 0.0,
min_y: 0.0,
max_x: 0.0,
max_y: 0.0,
}
}
pub fn centered(w: f64, h: f64) -> Self {
Self {
min_x: -w / 2.0,
min_y: -h / 2.0,
max_x: w / 2.0,
max_y: h / 2.0,
}
}
pub fn w(&self) -> f64 {
self.max_x - self.min_x
}
pub fn h(&self) -> f64 {
self.max_y - self.min_y
}
pub fn inflate(self, pad: f64) -> Self {
Self {
min_x: self.min_x - pad,
min_y: self.min_y - pad,
max_x: self.max_x + pad,
max_y: self.max_y + pad,
}
}
pub fn expand(self, top: f64, right: f64, bottom: f64, left: f64) -> Self {
Self {
min_x: self.min_x - left,
min_y: self.min_y - top,
max_x: self.max_x + right,
max_y: self.max_y + bottom,
}
}
pub fn union(self, other: Bbox) -> Self {
Self {
min_x: self.min_x.min(other.min_x),
min_y: self.min_y.min(other.min_y),
max_x: self.max_x.max(other.max_x),
max_y: self.max_y.max(other.max_y),
}
}
pub fn shifted(self, dx: f64, dy: f64) -> Self {
Self {
min_x: self.min_x + dx,
min_y: self.min_y + dy,
max_x: self.max_x + dx,
max_y: self.max_y + dy,
}
}
}