by adom
Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.
← Commit history
0.2.83 (unreleased): turned bodies as {cx, cy, w, h, rotation} for exact height_check (engine 0.20.0, EDA Bridge Standard #26)
9 files changed
+139−27
CHANGELOG.md+5bridge-rs/Cargo.lock+1−1bridge-rs/src/bodies.rs+32−4bridge-rs/vendor/README.md+1−1bridge-rs/vendor/adom-eda-checks/Cargo.toml+1−1bridge-rs/vendor/adom-eda-checks/README.md+2−2bridge-rs/vendor/adom-eda-checks/src/bodies.rs+84−11bridge-rs/vendor/adom-eda-checks/src/placement.rs+2−1src/agent/AdomAgent.pas.tmpl+11−6CHANGELOG.md+5@@ -2,6 +2,11 @@ ## 0.2.83 (unreleased) +- **Turned parts' 3D bodies are compared by their own rectangles** (EDA Bridge Standard #26, engine 0.20.0 / standard+ 0.23.0, vendored as published). `altium_bodies` sends `{cx, cy, w, h, rotation}` for a part turned off the 90-degree+ grid, measured from the body's outline in the part's frame, so `height_check`'s collisions and gaps are exact where the+ axis-aligned box was far bigger. Measured on a Sentinel copy with C20 turned to 30 degrees: the body is 1.05 x 0.95 mm+ and its end caps 0.35 x 0.95 (the old box was 1.38 x 1.35), and height_check finds its corner 0.08 mm from C23. - **`altium_simulate`: Monte Carlo and noise.** `monteCarlo {runs, distribution?, seed?, tolerances?}` runs the analysis again with every part drawn within its tolerance, each run its own signal (`v(out)_m1` ...) with the drawn values in `step`; rerunning run 1's values in ngspice gives Altium's 9.27674 dB at 10 MHz exactly. `{type: "noise", source,
bridge-rs/Cargo.lock+1−1@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "adom-eda-checks"-version = "0.19.1"+version = "0.20.0" dependencies = [ "roxmltree", "serde_json",
bridge-rs/src/bodies.rs+32−4@@ -10,10 +10,29 @@ fn r3(v: f64) -> f64 { (v * 1000.0).round() / 1000.0 } /// ({ref, side, x0, y0, x1, y1, z0, z1}, mm). Rows with no part ("-") are left out. Pure. pub fn rows(raw: &[Value]) -> Vec<Value> { let n = |r: &Value, i: usize| r3(r[i].as_f64().unwrap_or(0.0) / PER_MM);- raw.iter().filter(|r| r[0].as_str().map(|s| s != "-").unwrap_or(false)).map(|r| json!({- "ref": r[0], "side": if r[1].as_i64() == Some(32) { "bottom" } else { "top" },- "x0": n(r, 4), "y0": n(r, 5), "x1": n(r, 6), "y1": n(r, 7), "z0": n(r, 3), "z1": n(r, 2),- })).collect()+ raw.iter().filter(|r| r[0].as_str().map(|s| s != "-").unwrap_or(false)).map(|r| {+ let mut o = json!({"ref": r[0], "side": if r[1].as_i64() == Some(32) { "bottom" } else { "top" },+ "x0": n(r, 4), "y0": n(r, 5), "x1": n(r, 6), "y1": n(r, 7), "z0": n(r, 3), "z1": n(r, 2)});+ // a part turned off the 90-degree grid: its body's own rectangle, from the outline in the part's frame+ let rot = r.get(8).and_then(|v| v.as_f64()).unwrap_or(0.0) / 1000.0;+ let pts: Vec<(f64, f64)> = r.get(9).and_then(|v| v.as_array()).map(|a| a.iter().map(|p| (p[0].as_f64().unwrap_or(0.0) / PER_MM, p[1].as_f64().unwrap_or(0.0) / PER_MM)).collect()).unwrap_or_default();+ if let Some((cx, cy, w, h)) = turned_rect(&pts, rot) {+ o["cx"] = json!(r3(cx)); o["cy"] = json!(r3(cy)); o["w"] = json!(r3(w)); o["h"] = json!(r3(h)); o["rotation"] = json!(r3(rot));+ }+ o+ }).collect()+}++/// The rectangle of an outline turned by `rot` degrees: its extent in the turned frame, the centre back on the board.+/// None for a part on the 90-degree grid (its box is exact) or an outline of fewer than three points. Pure.+pub fn turned_rect(pts: &[(f64, f64)], rot: f64) -> Option<(f64, f64, f64, f64)> {+ if pts.len() < 3 || (rot.rem_euclid(90.0)).min(90.0 - rot.rem_euclid(90.0)) < 1e-6 { return None; }+ let (c, s) = (rot.to_radians().cos(), rot.to_radians().sin());+ let local: Vec<(f64, f64)> = pts.iter().map(|(x, y)| (x * c + y * s, -x * s + y * c)).collect();+ let (u0, u1) = local.iter().fold((f64::MAX, f64::MIN), |a, p| (a.0.min(p.0), a.1.max(p.0)));+ let (v0, v1) = local.iter().fold((f64::MAX, f64::MIN), |a, p| (a.0.min(p.1), a.1.max(p.1)));+ let (uc, vc) = ((u0 + u1) / 2.0, (v0 + v1) / 2.0);+ Some((uc * c - vc * s, uc * s + vc * c, u1 - u0, v1 - v0)) } /// The bodies companion model of the EDA Bridge Standard: one box per body, in mm, z from the surface the part sits@@ -60,4 +79,13 @@ mod tests { assert_eq!(h["overLimit"][0]["ref"], "J1"); assert_eq!(h["tallest"]["bottom"]["heightMm"], json!(4.1)); }+ #[test]+ fn a_turned_body_keeps_its_own_rectangle() {+ // a 4 x 2 mm body at (10, 5) turned 30 degrees+ let (c, s) = (30f64.to_radians().cos(), 30f64.to_radians().sin());+ let pts: Vec<(f64, f64)> = [(-2.0, -1.0), (2.0, -1.0), (2.0, 1.0), (-2.0, 1.0)].iter().map(|(u, v)| (10.0 + u * c - v * s, 5.0 + u * s + v * c)).collect();+ let (cx, cy, w, h) = turned_rect(&pts, 30.0).unwrap();+ assert!((cx - 10.0).abs() < 1e-9 && (cy - 5.0).abs() < 1e-9 && (w - 4.0).abs() < 1e-9 && (h - 2.0).abs() < 1e-9, "{cx} {cy} {w} {h}");+ assert!(turned_rect(&pts, 90.0).is_none() && turned_rect(&pts, 0.0).is_none(), "on the grid the box is exact");+ } }
bridge-rs/vendor/README.md+1−1@@ -2,7 +2,7 @@ | Folder | From | Version | |---|---|---|-| `adom-eda-checks/` | adom/eda-bridge-standard `engine/` (the shared checks engine) | standard 0.22.2, engine 0.19.1 |+| `adom-eda-checks/` | adom/eda-bridge-standard `engine/` (the shared checks engine) | standard 0.23.0, engine 0.20.0 | | `pcb-design-rules/records/` | adom/pcb-design-rules `rules/records/` (each fab's published limits, with sources and dates) | head of 2026-10-27 | The wiki has no git protocol, so these are copied at a version: refresh both from their pages, then run the tests.
bridge-rs/vendor/adom-eda-checks/Cargo.toml+1−1@@ -1,6 +1,6 @@ [package] name = "adom-eda-checks"-version = "0.19.1"+version = "0.20.0" edition = "2021" description = "The EDA Bridge Standard's checks and board-file writers, computed from the board model JSON: no bridge calls, no tool." license = "MIT"
bridge-rs/vendor/adom-eda-checks/README.md+2−2@@ -75,7 +75,7 @@ Every check takes one JSON object: | `board` | the board model, `<prefix>_routing_state` (`schema/board.schema.json`) | | `stack` | the stack-up companion, `<prefix>_layer_stack` | | `pours` | poured copper, `<prefix>_pour_state` (its `zones`) |-| `bodies` | the 3D bodies companion, `<prefix>_bodies`: `bodies[{ref, side, x0, y0, x1, y1, z0, z1}]` (one box per body or per part) and `noBody` |+| `bodies` | the 3D bodies companion, `<prefix>_bodies`: `bodies[{ref, side, x0, y0, x1, y1, z0, z1}]` (one box per body or per part) and `noBody`. A turned body may give its footprint as `{cx, cy, w, h, rotation}` or four `corners`; bodies are then compared by their rectangles (separating axes), not their boxes | | `rules` | the board's rules, `<prefix>_read_rules`: a clearance rule as `{kind: "clearance", clearanceMm}` (a `value` with its unit, `"0.1mm"`, works too). Only copper-to-copper clearance counts: a rule whose kind or name names the board edge, mask, silk, paste, holes, a keepout or restrict area, the courtyard or the same net is skipped | | `silk` | `<prefix>_silk_state` | | `fab` | one record from adom/pcb-design-rules `rules/records/<vendor>.json`, with `vendor` |@@ -115,7 +115,7 @@ adom-eda-checks import_svg --svg logo.svg --args '{"at": [10, 10], "widthMm": 20 Replies keep the standard envelope (`success`, `errorCode`, `error`, `_hint`) and name verbs without a prefix (`apply_pours`, `add_rule`, `place_vias`): a bridge adds its own. Every reply also carries `engine`-(`"adom-eda-checks 0.19.1"`), so a bridge reports the engine it runs without writing the version by hand.+(`"adom-eda-checks 0.20.0"`), so a bridge reports the engine it runs without writing the version by hand. ## Tests
bridge-rs/vendor/adom-eda-checks/src/bodies.rs+84−11@@ -9,19 +9,74 @@ use std::collections::BTreeMap; fn r3(v: f64) -> f64 { (v * 1000.0).round() / 1000.0 } fn f(v: &Value) -> f64 { v.as_f64().unwrap_or(0.0) } -/// One body as a box in mm: its part, side (top/bottom), x and y extent, and z from the board surface it sits on.+/// One body as a box in mm: its part, side (top/bottom), x and y extent, and z from the board surface it sits on; a+/// turned body also has its footprint as a rectangle's four corners (`turned`), and x/y extent is their bounding box. #[derive(Debug, Clone)]-pub struct BodyBox { pub part: String, pub top: bool, pub x0: f64, pub y0: f64, pub x1: f64, pub y1: f64, pub z0: f64, pub z1: f64 }+pub struct BodyBox { pub part: String, pub top: bool, pub x0: f64, pub y0: f64, pub x1: f64, pub y1: f64, pub z0: f64, pub z1: f64, pub turned: Option<Vec<(f64, f64)>> } -/// The bodies companion (`bodies[{ref, side, x0, y0, x1, y1, z0, z1}]`, mm) as boxes. Pure.+/// A body row's turned rectangle: `{cx, cy, w, h, rotation}` (degrees counterclockwise) or `corners` (four [x, y]).+fn turned(r: &Value) -> Option<Vec<(f64, f64)>> {+ if let Some(cs) = r["corners"].as_array().filter(|a| a.len() == 4) { return Some(cs.iter().map(|c| (f(&c[0]), f(&c[1]))).collect()); }+ if r["cx"].is_number() && r["w"].is_number() && r["h"].is_number() {+ let (cx, cy, hw, hh, a) = (f(&r["cx"]), f(&r["cy"]), f(&r["w"]) / 2.0, f(&r["h"]) / 2.0, f(&r["rotation"]).to_radians());+ let (c, s) = (a.cos(), a.sin());+ return Some([(-hw, -hh), (hw, -hh), (hw, hh), (-hw, hh)].iter().map(|(u, v)| (cx + u * c - v * s, cy + u * s + v * c)).collect());+ }+ None+}++/// The bodies companion (`bodies[{ref, side, x0, y0, x1, y1, z0, z1}]`, mm, and for a turned body `{cx, cy, w, h,+/// rotation}` or `corners`) as boxes. Pure. pub fn boxes(rows: &[Value]) -> Vec<BodyBox> {- rows.iter().filter(|r| r["ref"].as_str().map(|s| !s.is_empty()).unwrap_or(false)).map(|r| BodyBox {- part: r["ref"].as_str().unwrap_or("").to_string(), top: r["side"].as_str() != Some("bottom"),- x0: f(&r["x0"]).min(f(&r["x1"])), y0: f(&r["y0"]).min(f(&r["y1"])), x1: f(&r["x0"]).max(f(&r["x1"])), y1: f(&r["y0"]).max(f(&r["y1"])),- z0: f(&r["z0"]), z1: f(&r["z1"]),+ rows.iter().filter(|r| r["ref"].as_str().map(|s| !s.is_empty()).unwrap_or(false)).map(|r| {+ let t = turned(r);+ let (x0, y0, x1, y1) = match &t {+ Some(cs) => cs.iter().fold((f64::MAX, f64::MAX, f64::MIN, f64::MIN), |b, p| (b.0.min(p.0), b.1.min(p.1), b.2.max(p.0), b.3.max(p.1))),+ None => (f(&r["x0"]).min(f(&r["x1"])), f(&r["y0"]).min(f(&r["y1"])), f(&r["x0"]).max(f(&r["x1"])), f(&r["y0"]).max(f(&r["y1"]))),+ };+ BodyBox { part: r["ref"].as_str().unwrap_or("").to_string(), top: r["side"].as_str() != Some("bottom"), x0, y0, x1, y1, z0: f(&r["z0"]), z1: f(&r["z1"]), turned: t } }).collect() } +/// How two bodies' footprints meet in x and y: (true, how deep) when they overlap, else (false, the gap between them).+/// Axis boxes compare as boxes; when either is turned, both are compared as rectangles by separating axes, so a part at+/// 45 degrees no longer counts its box's empty corners (kicad-lane #26: 70 false collisions round a turned QFN). Pure.+pub fn xy_meet(a: &BodyBox, b: &BodyBox) -> (bool, f64) {+ if a.turned.is_none() && b.turned.is_none() {+ let dx = (b.x0 - a.x1).max(a.x0 - b.x1);+ let dy = (b.y0 - a.y1).max(a.y0 - b.y1);+ return if dx < 0.0 && dy < 0.0 { (true, -(dx.max(dy))) } else { (false, (dx.max(0.0).powi(2) + dy.max(0.0).powi(2)).sqrt()) };+ }+ let poly = |x: &BodyBox| x.turned.clone().unwrap_or_else(|| vec![(x.x0, x.y0), (x.x1, x.y0), (x.x1, x.y1), (x.x0, x.y1)]);+ let (pa, pb) = (poly(a), poly(b));+ // separating axes: each edge's normal of either rectangle+ let mut sep = f64::MIN;+ for p in [&pa, &pb] {+ for i in 0..p.len() {+ let (e0, e1) = (p[i], p[(i + 1) % p.len()]);+ let (nx, ny) = (e0.1 - e1.1, e1.0 - e0.0);+ let l = (nx * nx + ny * ny).sqrt();+ if l < 1e-12 { continue; }+ let proj = |q: &Vec<(f64, f64)>| q.iter().map(|v| (v.0 * nx + v.1 * ny) / l).fold((f64::MAX, f64::MIN), |m, d| (m.0.min(d), m.1.max(d)));+ let ((a0, a1), (b0, b1)) = (proj(&pa), proj(&pb));+ sep = sep.max((b0 - a1).max(a0 - b1));+ }+ }+ if sep < 0.0 { return (true, -sep); }+ // apart: the shortest distance between their edges+ let seg = |p: (f64, f64), a: (f64, f64), b: (f64, f64)| {+ let (dx, dy) = (b.0 - a.0, b.1 - a.1);+ let l2 = dx * dx + dy * dy;+ let t = if l2 == 0.0 { 0.0 } else { (((p.0 - a.0) * dx + (p.1 - a.1) * dy) / l2).clamp(0.0, 1.0) };+ ((p.0 - a.0 - t * dx).powi(2) + (p.1 - a.1 - t * dy).powi(2)).sqrt()+ };+ let mut d = f64::MAX;+ for (p, q) in [(&pa, &pb), (&pb, &pa)] {+ for v in p.iter() { for i in 0..q.len() { d = d.min(seg(*v, q[i], q[(i + 1) % q.len()])); } }+ }+ (false, d)+}+ /// The input's bodies: the companion's `bodies`, or the companion given as a bare list. pub fn input_boxes(input: &Value) -> Option<Vec<BodyBox>> { let b = crate::input::part(input, "bodies")?;@@ -69,9 +124,7 @@ pub fn clashes(bs: &[BodyBox], gap: f64) -> (Vec<Value>, Vec<Value>) { if a.part == b.part || a.top != b.top { continue; } let dz = a.z1.min(b.z1) - a.z0.max(b.z0); if dz <= 0.0 { continue; } // one sits above the other (a part under a connector's overhang)- let dx = (b.x0 - a.x1).max(a.x0 - b.x1);- let dy = (b.y0 - a.y1).max(a.y0 - b.y1);- let (hit, d) = if dx < 0.0 && dy < 0.0 { (true, -(dx.max(dy))) } else { (false, (dx.max(0.0).powi(2) + dy.max(0.0).powi(2)).sqrt()) };+ let (hit, d) = xy_meet(a, b); if !hit && d >= gap { continue; } let key = if a.part < b.part { (a.part.clone(), b.part.clone()) } else { (b.part.clone(), a.part.clone()) }; let at = json!([r3((a.x0.max(b.x0) + a.x1.min(b.x1)) / 2.0), r3((a.y0.max(b.y0) + a.y1.min(b.y1)) / 2.0)]);@@ -135,7 +188,7 @@ mod tests { use super::*; fn bx(p: &str, top: bool, x0: f64, y0: f64, x1: f64, y1: f64, z0: f64, z1: f64) -> BodyBox {- BodyBox { part: p.into(), top, x0, y0, x1, y1, z0, z1 }+ BodyBox { part: p.into(), top, x0, y0, x1, y1, z0, z1, turned: None } } #[test]@@ -184,4 +237,24 @@ mod tests { assert_eq!(r["complete"], json!(false)); assert_eq!(height_check(&json!({"args": {}}))["errorCode"], "no_bodies"); }++ #[test]+ fn turned_bodies_meet_by_their_rectangles_not_their_boxes() {+ // a 4 mm QFN at 45 degrees and a cap in its box's empty corner: apart, not a collision (kicad-lane #26)+ let rows = vec![json!({"ref": "U1", "side": "top", "cx": 0.0, "cy": 0.0, "w": 4.0, "h": 4.0, "rotation": 45.0, "z0": 0.0, "z1": 0.9}),+ json!({"ref": "C1", "side": "top", "x0": 2.0, "y0": 2.0, "x1": 2.6, "y1": 2.3, "z0": 0.0, "z1": 0.5})];+ let bs = boxes(&rows);+ assert!((bs[0].x1 - 2.0 * 2f64.sqrt()).abs() < 1e-9, "the box still covers the turned body");+ let (hit, d) = xy_meet(&bs[0], &bs[1]);+ assert!(!hit && d > 0.5, "{hit} {d}");+ let (col, _) = clashes(&bs, 0.2);+ assert!(col.is_empty());+ // the same cap moved onto the QFN's edge collides+ let near = boxes(&[rows[0].clone(), json!({"ref": "C1", "side": "top", "x0": 1.2, "y0": 1.2, "x1": 1.8, "y1": 1.5, "z0": 0.0, "z1": 0.5})]);+ assert!(xy_meet(&near[0], &near[1]).0);+ // corners work too+ let c = boxes(&[json!({"ref": "U2", "corners": [[0, 0], [2, 0], [2, 1], [0, 1]], "z0": 0, "z1": 1})]);+ assert_eq!((c[0].x1, c[0].y1), (2.0, 1.0));+ } }+
bridge-rs/vendor/adom-eda-checks/src/placement.rs+2−1@@ -111,7 +111,8 @@ pub fn is_stacked(pads: &[Value], bs: &[crate::bodies::BodyBox], a: &str, b: &st if pa.is_empty() || pb.is_empty() || pa.iter().any(|x| pb.iter().any(|y| hit(grow(*x, margin), grow(*y, margin)))) { return false; } let (ba, bb): (Vec<_>, Vec<_>) = (bs.iter().filter(|x| x.part == a).collect(), bs.iter().filter(|x| x.part == b).collect()); if ba.is_empty() || bb.is_empty() { return false; }- !ba.iter().any(|p| bb.iter().any(|q| hit(grow((p.x0, p.y0, p.x1, p.y1), margin), grow((q.x0, q.y0, q.x1, q.y1), margin)) && p.z0.max(q.z0) < p.z1.min(q.z1)))+ // bodies meet when their footprints come within twice the margin (turned ones by their rectangles) and their heights overlap+ !ba.iter().any(|p| bb.iter().any(|q| { let (h, d) = crate::bodies::xy_meet(p, q); (h || d < 2.0 * margin) && p.z0.max(q.z0) < p.z1.min(q.z1) })) } /// placement_check: input {board, bodies?, args: {marginMm?, edgeMm?}}. Without bodies the parts' boxes are their pads
src/agent/AdomAgent.pas.tmpl+11−6@@ -7902,7 +7902,7 @@ Begin End; { bodies: every 3D body on the board as [component, componentLayer, overallHeight, standoffHeight, left, bottom, right,- top] in internal units. OverallHeight is the body's top above the board surface its part sits on and StandoffHeight+ top, rotation*1000, outline] in internal units (the outline only for a part turned off the 90-degree grid). OverallHeight is the body's top above the board surface its part sits on and StandoffHeight its bottom (measured on the Bluetooth Sentinel example, Develop 2026-10-23); a part with several bodies has several rows. A body with no component (a free 3D body) is named '-'. } Function CmdBodies(Lines : TStringList) : String;@@ -7911,8 +7911,8 @@ Var BIt : IPCB_BoardIterator; Body : IPCB_ComponentBody; R : TCoordRect;- S, Nm : String;- Lyr, N : Integer;+ S, Nm, Outl : String;+ Lyr, N, Rot : Integer; Begin Board := PCBServer.GetCurrentPCBBoard; If Board = Nil Then Begin Result := '{' + JRaw('ok','false') + ',' + JStr('errorCode','no_current_board') + ',' + JStr('error','no current PCB board (open a .PcbDoc first)') + '}'; Exit; End;@@ -7924,12 +7924,17 @@ Begin Body := BIt.FirstPCBObject; While (Body <> Nil) And (N < 20000) Do Begin- Nm := '-'; Lyr := 0;- If Body.Component <> Nil Then Begin Nm := Body.Component.Name.Text; Lyr := Body.Component.Layer; End;+ Nm := '-'; Lyr := 0; Rot := 0;+ If Body.Component <> Nil Then Begin Nm := Body.Component.Name.Text; Lyr := Body.Component.Layer; Rot := Round(Body.Component.Rotation * 1000); End; R := Body.BoundingRectangle;+ { the body's outline and its part's rotation: a part turned off the grid has a box far bigger than its body, and+ the standard compares turned bodies by their own rectangles (EDA Bridge Standard #26) }+ Outl := '[]';+ If (Rot Mod 90000) <> 0 Then+ Try Outl := ContourPts(Body.MainContour); Except Outl := '[]'; End; If N > 0 Then S := S + ','; S := S + '["' + JsonEsc(Nm) + '",' + IntToStr(Lyr) + ',' + IntToStr(Body.OverallHeight) + ',' + IntToStr(Body.StandoffHeight) + ',' +- IntToStr(R.Left) + ',' + IntToStr(R.Bottom) + ',' + IntToStr(R.Right) + ',' + IntToStr(R.Top) + ']';+ IntToStr(R.Left) + ',' + IntToStr(R.Bottom) + ',' + IntToStr(R.Right) + ',' + IntToStr(R.Top) + ',' + IntToStr(Rot) + ',' + Outl + ']'; N := N + 1; Body := BIt.NextPCBObject; End;