Add persisted per-view port anchors and connection-aware border placement

This commit is contained in:
2026-09-06 01:20:28 +03:00
parent 93fd32c684
commit 35133de650
13 changed files with 1435 additions and 149 deletions
+15 -8
View File
@@ -1,6 +1,6 @@
//! Deterministic, bounded diagram geometry. Only authored pins belong in the model;
//! callers share this derived geometry for drawing, picking, fitting and export.
use crate::projection::{self, PortAnchorSide, ProjectedEdge, ProjectedNode, ProjectedView};
use crate::projection::{self, ProjectedEdge, ProjectedNode, ProjectedView};
use crate::{Diagram, Id, Position, Project, RelationKind, Size};
use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap};
@@ -264,11 +264,7 @@ fn endpoints(node: &ProjectedNode, port: Option<Id>, view: &ProjectedView) -> Ve
.iter()
.find(|p| p.element == id && p.owner == node.id)
}) {
let normal = match port.side {
PortAnchorSide::Left => pos(-1.0, 0.0),
PortAnchorSide::Right => pos(1.0, 0.0),
PortAnchorSide::Bottom => pos(0.0, 1.0),
};
let normal = port.side.normal();
return vec![Endpoint {
point: port.position,
stub: pos(
@@ -1190,11 +1186,22 @@ impl BoundsBuilder {
}
fn finish(self) -> RoutingBounds {
let (left, top, right, bottom) = self.extents.unwrap_or((0.0, 0.0, 0.0, 0.0));
// Subtraction and subsequent addition can round in opposite directions
// when an authored label extends far left/up. Bounds must still enclose
// every original point, including the far right and bottom edges.
let span = |start: f32, end: f32| {
let extent = end - start;
if start + extent < end {
extent.next_up()
} else {
extent
}
};
RoutingBounds {
position: pos(left, top),
size: Size {
width: right - left,
height: bottom - top,
width: span(left, right),
height: span(top, bottom),
},
}
}