craft-drawingml: elbow connector handles take the spec's whole adjust range (#1892)

This commit is contained in:
Hamza Naveed
2026-11-16 21:30:24 -05:00
committed by GitHub
parent ff5a8af742
commit 746d6e33df
2 changed files with 22 additions and 6 deletions
+11 -6
View File
@@ -1115,6 +1115,9 @@ fn flowchart_and_star_shapes(c: &Ctx) -> Option<Geometry> {
Some(g)
}
/// The range presetShapeDefinitions gives the elbows' handles (`minX` / `maxX`, `minY` / `maxY`).
const ADJ_LIMIT: f64 = 2_147_483_647.0;
fn callout_wave_and_connector_shapes(c: &Ctx) -> Option<Geometry> {
let name = c.name;
let w = c.w;
@@ -1197,28 +1200,30 @@ fn callout_wave_and_connector_shapes(c: &Ctx) -> Option<Geometry> {
}
// The elbows of ECMA-376's presetShapeDefinitions: 3 has one middle leg, 4 adds a
// horizontal one at `adj2`, 5 a third vertical one at `adj3`. 4 and 5 were drawn as 3.
// Their handles take the spec's whole range (its `ahXY` min and max), so dragging one
// never clamps a value an imported route uses.
"bentConnector3" => {
let x1 = w * a(0) / 1e5;
let l = Pb::new().m(0.0, 0.0).l(x1, 0.0).l(x1, h).l(w, h).take();
let mut g = Geometry { paths: vec![stroke_only(l)], text_rect: full, handles: vec![], sites: vec![Point::ZERO, Point::new(w, h)] };
g.handles.push(Handle::new(0, Point::new(0.0, h / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -1e6, 1e6));
g.handles.push(Handle::new(0, Point::new(0.0, h / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -ADJ_LIMIT, ADJ_LIMIT));
g
}
"bentConnector4" => {
let (x1, y2) = (w * a(0) / 1e5, h * a(1) / 1e5);
let l = Pb::new().m(0.0, 0.0).l(x1, 0.0).l(x1, y2).l(w, y2).l(w, h).take();
let mut g = Geometry { paths: vec![stroke_only(l)], text_rect: full, handles: vec![], sites: vec![Point::ZERO, Point::new(w, h)] };
g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -1e6, 1e6));
g.handles.push(Handle::new(1, Point::new((x1 + w) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -1e6, 1e6));
g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -ADJ_LIMIT, ADJ_LIMIT));
g.handles.push(Handle::new(1, Point::new((x1 + w) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -ADJ_LIMIT, ADJ_LIMIT));
g
}
"bentConnector5" => {
let (x1, y2, x3) = (w * a(0) / 1e5, h * a(1) / 1e5, w * a(2) / 1e5);
let l = Pb::new().m(0.0, 0.0).l(x1, 0.0).l(x1, y2).l(x3, y2).l(x3, h).l(w, h).take();
let mut g = Geometry { paths: vec![stroke_only(l)], text_rect: full, handles: vec![], sites: vec![Point::ZERO, Point::new(w, h)] };
g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -1e6, 1e6));
g.handles.push(Handle::new(1, Point::new((x1 + x3) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -1e6, 1e6));
g.handles.push(Handle::new(2, Point::new(0.0, (y2 + h) / 2.0), Vec2::new(w / 1e5, 0.0), a(2), -1e6, 1e6));
g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -ADJ_LIMIT, ADJ_LIMIT));
g.handles.push(Handle::new(1, Point::new((x1 + x3) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -ADJ_LIMIT, ADJ_LIMIT));
g.handles.push(Handle::new(2, Point::new(0.0, (y2 + h) / 2.0), Vec2::new(w / 1e5, 0.0), a(2), -ADJ_LIMIT, ADJ_LIMIT));
g
}
// The curved connectors follow the same legs with cubic Béziers.
+11
View File
@@ -452,6 +452,17 @@ fn the_three_and_four_bend_elbows_follow_their_adjust_values() {
let g = build("bentConnector5", 200.0, 100.0, &[25000.0, 75000.0, 60000.0]).unwrap();
let pos: Vec<(f64, f64)> = g.handles.iter().map(|h| (h.pos.x, h.pos.y)).collect();
assert_eq!(pos, [(50.0, 37.5), (85.0, 75.0), (120.0, 87.5)]);
// A handle dragged far out keeps the value: the spec's range is ±2147483647, and PowerPoint's
// routing gives a thin connector box values well beyond ±1000000 (a leg 50 pt beside a 1 pt
// wide box is 5000000).
for name in ["bentConnector3", "bentConnector4", "bentConnector5"] {
let g = build(name, 200.0, 100.0, &[]).unwrap();
for h in &g.handles {
for v in [5_000_000.0, -5_000_000.0] {
assert_eq!(h.value_at(h.origin + h.dir * v), v, "{name} handle {}", h.index);
}
}
}
}
// curvedConnector2 is one cubic (l,t)…(r,b) through (wd2,t) and (r,hd2); 4 and 5 bend at the same