← Commit history
Merge PR #694: analyze current: a Fields barrel finding at a pin hole the insertMm2 screen checked is not an open finding (#295)
1 file changed
+43−2
crates/aiflow-analyze/src/lib.rs+43−2@@ -386,6 +386,10 @@ pub fn field_screen(fields: &Value, spec: &Value, board_bytes: &[u8], spec_bytes pub fn field_screen_with_acks(fields: &Value, spec: &Value, board_bytes: &[u8], spec_bytes: &[u8], kind: &str, acks: &[Value]) -> Result<Vec<Value>, String> { use sha2::{Digest, Sha256}; let mut covered: Vec<Value> = Vec::new();+ // (net, x, y) of every pin hole whose plated connections the insert screen below checked: a declared+ // spec.contacts.<REF>.insertMm2 or a machine contact. Fields' own current-barrel finding at such a hole+ // judges the plating alone, which that screen has already replaced with plating plus the conductor.+ let mut screened_holes: Vec<(String, f64, f64)> = Vec::new(); for (key,bytes) in [("board",board_bytes),("spec",spec_bytes)] { let expected=format!("{:x}",Sha256::digest(bytes)); if fields["inputIdentity"][key].as_str()!=Some(expected.as_str()) {@@ -510,6 +514,11 @@ pub fn field_screen_with_acks(fields: &Value, spec: &Value, board_bytes: &[u8], if (actual-density.unwrap()).abs()>1e-8*actual.max(1.0) { return Err(format!("Fields {name} barrel density is inconsistent (|amps|/area differs from meanBarrelJ)")); }+ if let (Some(r), Some(x), Some(y)) = (hole_ref(c), c["at"][0].as_f64(), c["at"][1].as_f64()) {+ if machine(&r) || spec["contacts"][r.as_str()]["insertMm2"].as_f64().is_some_and(|v| v.is_finite() && v > 0.0) {+ screened_holes.push((name.clone(), x, y));+ }+ } if actual>barrel_limit { let r = hole_ref(c); let insert = r.as_deref().and_then(|r| spec["contacts"][r]["insertMm2"].as_f64()).filter(|v| v.is_finite() && *v > 0.0);@@ -567,10 +576,22 @@ pub fn field_screen_with_acks(fields: &Value, spec: &Value, board_bytes: &[u8], } } let issues=fields["issues"].as_array().ok_or("Fields report has no issues array")?;- // a neck finding at an acknowledged point is the same reviewed peak; barrel findings never are+ // a neck finding at an acknowledged point is the same reviewed peak; an ack never covers a barrel finding let acked_neck = |i: &Value| i["kind"]=="current-neck" && covered.iter().any(|c| c["net"]==i["net"] && i["at"][0].as_f64().zip(i["at"][1].as_f64()).is_some_and(|(x,y)| (x-c["at"][0].as_f64().unwrap_or(f64::NAN)).hypot(y-c["at"][1].as_f64().unwrap_or(f64::NAN)) <= current_acks::TOLERANCE_MM));- let relevant: Vec<_>=issues.iter().filter(|i| if kind=="current" { (i["kind"]=="current-neck" && !acked_neck(i)) || i["kind"]=="current-barrel" } else { i["kind"]=="tab-rise" || i["kind"]=="thermal-vias" || (i["kind"]=="solid-uncoupled" && i["severity"]=="high") }).collect();+ // a barrel finding (one connection, or Fields' per-net group of them in action.items) is the insert+ // screen's when every connection it names sits in a pin hole that screen checked on that net+ let screened_barrel = |i: &Value| {+ let points: Vec<&Value> = match i["action"]["items"].as_array() { Some(items) if i["action"]["type"]=="group" => items.iter().collect(), _ => vec![i] };+ !points.is_empty() && points.iter().all(|p| {+ let net = p["net"].as_str().or(i["net"].as_str());+ match (net, p["at"][0].as_f64(), p["at"][1].as_f64()) {+ (Some(n), Some(x), Some(y)) => screened_holes.iter().any(|(sn, hx, hy)| sn==n && (hx-x).abs()<0.01 && (hy-y).abs()<0.01),+ _ => false,+ }+ })+ };+ let relevant: Vec<_>=issues.iter().filter(|i| if kind=="current" { (i["kind"]=="current-neck" && !acked_neck(i)) || (i["kind"]=="current-barrel" && !screened_barrel(i)) } else { i["kind"]=="tab-rise" || i["kind"]=="thermal-vias" || (i["kind"]=="solid-uncoupled" && i["severity"]=="high") }).collect(); if !relevant.is_empty() { return Err(relevant.iter().map(|i|i["what"].as_str().unwrap_or("unresolved field finding")).collect::<Vec<_>>().join("; ")); } Ok(covered) }@@ -609,6 +630,26 @@ mod field_screen_tests { // with the 14 AWG lead declared (2.08 mm2) it is screened on plating plus the lead: 16 / 2.29 = 7 A/mm2 let declared=json!({"loads":{"VCC":{"amps":16}},"contacts":{"MC13":{"insertMm2":2.08}}}); assert!(field_screen_with_acks(&f,&declared,board,b"spec","current",&[]).unwrap().iter().any(|c|c["why"].as_str().unwrap().contains("2.08")));+ // Fields' own barrel finding for that hole (single, or grouped per net in action.items) is the+ // insert screen's, so it no longer fails it; one for an undeclared hole, another net or an+ // unknown spot still does, and a neck ack never covers a barrel+ let single=json!({"kind":"current-barrel","net":"VCC","at":[10.0,10.0],"what":"VCC: plated connection F.Cu→B.Cu at (10.00, 10.00) over"});+ let grouped=json!({"kind":"current-barrel","net":"VCC","at":[10.0,10.0],"what":"VCC: 2 plated connections carry more than the density threshold",+ "action":{"type":"group","of":"review","items":[{"net":"VCC","at":[10.0,10.0]},{"net":"VCC","at":[10.0,10.0]}]}});+ for finding in [single.clone(), grouped.clone()] {+ let mut g=f.clone(); g["issues"]=json!([finding]);+ field_screen(&g,&declared,board,b"spec","current").unwrap();+ field_screen(&g,&spec,board,b"spec","current").unwrap();+ }+ let mut both=f.clone(); both["nets"][0]["platedPads"]=json!(2); both["nets"][0]["platedConnections"]=json!([conn(10.0),{"at":[20.0,10.0],"from":"F.Cu","to":"B.Cu","amps":1.0,"barrelAreaMm2":area,"meanBarrelJ":1.0/area,"resolvedPerimeterFraction":1.0}]);+ let mut mixed=grouped.clone(); mixed["action"]["items"][1]["at"]=json!([20.0,10.0]);+ both["issues"]=json!([mixed]);+ assert!(field_screen(&both,&declared,board,b"spec","current").unwrap_err().contains("2 plated connections"));+ for bad in [json!({"kind":"current-barrel","net":"GND","at":[10.0,10.0],"what":"GND barrel"}), json!({"kind":"current-barrel","net":"VCC","what":"no position"}),+ json!({"kind":"current-barrel","net":"VCC","at":[10.0,10.0],"what":"empty group","action":{"type":"group","items":[]}})] {+ let mut g=f.clone(); g["issues"]=json!([bad]);+ assert!(field_screen(&g,&declared,board,b"spec","current").is_err());+ } // the same hole on an ordinary part (J1) still fails the screen f["nets"][0]["platedConnections"]=json!([conn(20.0)]); assert!(field_screen(&f,&spec,board,b"spec","current").unwrap_err().contains("J1"));