draftwright 0.2.15

Automated technical drawings from STEP B-rep: a Rust port of draftwright.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
//! Surface finish, threads, knurls and notes authored in the Spec (draftwright-rust #43 item 1,
//! the second part; stream K1b), the way [`crate::spec_gdt`] authors datums and controls. Python
//! draftwright's `Sheet.finish(ra, ref)`, `_Hole.thread(spec, depth=)`, `_Dim.thread(spec)`,
//! `_Dim.knurl(pitch, pattern)`, `Sheet.note(text, ref)` and `Sheet.default_surface_finish(ra)`
//! are the reference for what may be said:
//!
//! - `features/<id>/finish` and `faces/<face>/finish`: an ISO 1302 surface texture,
//!   `{ra, removal?}` (Ra in µm; `removal` is `required`, `prohibited` or `any`, the default),
//!   drawn as a face's AP242 surface texture is (the symbol on a leader from the face's edge);
//!   `sheet/default_finish`, the same, is the part's default finish beside the title block.
//! - `features/<id>/thread`: an ISO metric thread `{designation, length?}` (`M6`, `M10x1.25-6g`,
//!   `M5 LH`) on a hole the callouts state on its own, a hole pattern or a turned step, printed
//!   after its callout's size as an AP242 thread is (`⌀6 THRU M6`, `ø10 M10; 15 MIN FULL THREAD`).
//! - `features/<id>/knurl`: `{pattern, pitch}` (`straight` or `diamond`, mm) on a turned step,
//!   printed after its diameter as an AP242 knurl is (`ø24 STRAIGHT KNURL P0.8`).
//! - `features/<id>/note` and `faces/<face>/note`: free text on a leader to the feature or face,
//!   drawn as an AP242 surface label is. A note on the sheet is a general note (`notes`), and the
//!   general tolerance is the title block's (`sheet/title/tolerance`): both were authored before.
//!
//! Each is lowered into the record an AP242 requirement of its kind is read into
//! ([`crate::pmi::Record`], its source `spec:<path>`), merged into the Analysis's PMI reading with
//! the datums and controls ([`crate::spec_gdt::effective`]). Where the file states the same (a
//! finish on any of the same faces, the part's default finish, a thread or knurl on any of the
//! same faces) the Spec's wins with `spec_overrides_pmi`. What cannot be read (a roughness not
//! positive, an unknown removal, a designation that is not ISO metric, an empty note) is refused;
//! a thread or knurl its feature cannot carry (a knurl on a hole, a tap larger than its hole, a
//! length past its feature's) is reported as an AP242 one no feature owns is
//! (`pmi_not_lowered`, [`crate::pmi_lowering::manufacturing`]).

use serde::{Deserialize, Serialize};

use crate::model::{Analysis, Invalid, Spec};
use crate::pmi::{Category, Field, Record};
use crate::spec_gdt::SOURCE_PREFIX;

/// An ISO 1302 surface texture the Spec authors (draftwright's `finish(ra)`).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FinishSpec {
    /// The arithmetic mean roughness, µm.
    pub ra: f64,
    /// The material removal condition: `required` (the symbol's bar), `prohibited` (its circle)
    /// or `any` (the basic symbol, the default).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub removal: Option<String>,
}

/// An ISO metric thread the Spec authors on a hole, hole pattern or turned step (draftwright's
/// `thread(spec, depth=)`).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ThreadSpec {
    /// `M<size>[x<pitch>][-<class>][ LH|RH]`, printed as written.
    pub designation: String,
    /// The minimum full-thread length, mm; absent for the feature's full length.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub length: Option<f64>,
}

/// A knurl the Spec authors on a turned step (draftwright's `knurl(pitch, pattern)`).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct KnurlSpec {
    /// `straight` or `diamond`.
    pub pattern: String,
    /// Its pitch, mm.
    pub pitch: f64,
}

/// The removal conditions a finish may state, each with the term an AP242 surface texture states
/// it by (ISO 10303-1110), as [`crate::pmi_lowering`] draws it.
const REMOVALS: [(&str, &str); 3] = [
    ("any", "any process allowed"),
    ("required", "material removal required"),
    ("prohibited", "no material removal"),
];

/// The knurl patterns (draftwright's `KnurlRequirement.pattern`).
const PATTERNS: [&str; 2] = ["straight", "diamond"];

/// ISO 261's coarse pitches by nominal size, for a designation that states none.
pub(crate) const COARSE: [(f64, f64); 40] = [
    (1.0, 0.25),
    (1.1, 0.25),
    (1.2, 0.25),
    (1.4, 0.3),
    (1.6, 0.35),
    (1.8, 0.35),
    (2.0, 0.4),
    (2.2, 0.45),
    (2.5, 0.45),
    (3.0, 0.5),
    (3.5, 0.6),
    (4.0, 0.7),
    (4.5, 0.75),
    (5.0, 0.8),
    (6.0, 1.0),
    (7.0, 1.0),
    (8.0, 1.25),
    (9.0, 1.25),
    (10.0, 1.5),
    (11.0, 1.5),
    (12.0, 1.75),
    (14.0, 2.0),
    (16.0, 2.0),
    (18.0, 2.5),
    (20.0, 2.5),
    (22.0, 2.5),
    (24.0, 3.0),
    (27.0, 3.0),
    (30.0, 3.5),
    (33.0, 3.5),
    (36.0, 4.0),
    (39.0, 4.0),
    (42.0, 4.5),
    (45.0, 4.5),
    (48.0, 5.0),
    (52.0, 5.0),
    (56.0, 5.5),
    (60.0, 5.5),
    (64.0, 6.0),
    (68.0, 6.0),
];

/// Whether *spec* authors any finish, thread, knurl or note, or a default finish.
pub fn authors(spec: &Spec) -> bool {
    spec.sheet.default_finish.is_some()
        || spec.features.values().any(|f| {
            f.finish.is_some() || f.thread.is_some() || f.knurl.is_some() || f.note.is_some()
        })
        || spec
            .faces
            .values()
            .any(|f| f.finish.is_some() || f.note.is_some())
}

fn invalid(message: String, choices: Vec<String>) -> Invalid {
    Invalid {
        message,
        choices,
        path: None,
        also: Vec::new(),
    }
}

/// A metric designation's nominal size and pitch (the coarse pitch when it states none), or why
/// it is not one: `M<size>`, then optionally `x<pitch>` (spaces allowed around the `x`), `-<class>`
/// and ` LH` or ` RH`.
pub(crate) fn metric(designation: &str) -> Result<(f64, f64), String> {
    let bad = || {
        format!(
            "{designation:?} is not an ISO metric thread designation: M<size>[x<pitch>][-<class>][ LH] (M6, M10x1.25-6g)"
        )
    };
    let s = designation.trim();
    let rest = s.strip_prefix('M').ok_or_else(bad)?;
    let number = |t: &str| -> Option<(f64, usize)> {
        let n = t
            .find(|c: char| !(c.is_ascii_digit() || c == '.'))
            .unwrap_or(t.len());
        let v: f64 = t[..n].parse().ok()?;
        (v.is_finite() && v > 0.0).then_some((v, n))
    };
    let (nominal, n) = number(rest).ok_or_else(bad)?;
    let mut rest = &rest[n..];
    let mut pitch = None;
    let trimmed = rest.trim_start();
    if let Some(after) = trimmed.strip_prefix(['x', 'X', '×']) {
        let (p, n) = number(after.trim_start()).ok_or_else(bad)?;
        pitch = Some(p);
        rest = &after.trim_start()[n..];
    }
    if let Some(after) = rest.strip_prefix('-') {
        let n = after
            .find(|c: char| !c.is_ascii_alphanumeric())
            .unwrap_or(after.len());
        if n == 0 {
            return Err(bad());
        }
        rest = &after[n..];
    }
    let hand = rest.trim();
    if !(hand.is_empty() || (matches!(hand, "LH" | "RH") && rest.starts_with(char::is_whitespace)))
    {
        return Err(bad());
    }
    let pitch = match pitch {
        Some(p) => p,
        None => COARSE
            .iter()
            .find(|(d, _)| (d - nominal).abs() < 1e-9)
            .map(|(_, p)| *p)
            .ok_or_else(|| {
                format!(
                    "{designation:?} states no pitch and M{} has no ISO 261 coarse pitch; write it (M{}x<pitch>)",
                    crate::pmi::fmt_g3(nominal),
                    crate::pmi::fmt_g3(nominal)
                )
            })?,
    };
    Ok((nominal, pitch))
}

/// A finish at *at* reads as one: a positive roughness and a known removal condition.
fn finish(at: &str, f: &FinishSpec) -> Result<(), Invalid> {
    if !(f.ra.is_finite() && f.ra > 0.0) {
        return Err(invalid(
            format!(
                "The roughness at {at}/ra is {}; Ra is a positive value in µm.",
                f.ra
            ),
            vec![],
        ));
    }
    if let Some(r) = &f.removal
        && !REMOVALS.iter().any(|(n, _)| n == r)
    {
        return Err(invalid(
            format!(
                "{r:?} at {at}/removal is not a material removal condition; they are required, prohibited and any."
            ),
            REMOVALS.iter().map(|(n, _)| n.to_string()).collect(),
        ));
    }
    Ok(())
}

/// A note at *at* reads as one: text on one line.
fn note(at: &str, text: &str) -> Result<(), Invalid> {
    if text.trim().is_empty() || text.contains('\n') {
        return Err(invalid(
            format!("The note at {at} is empty or more than one line; a note is one line of text."),
            vec![],
        ));
    }
    Ok(())
}

/// Checks every finish, thread, knurl and note the spec authors reads as one: the form, never the
/// part (that is [`records`]' and [`crate::pmi_lowering::manufacturing`]'s). A refusal names the
/// entry's path.
pub(crate) fn check(spec: &Spec) -> Result<(), Invalid> {
    if let Some(f) = &spec.sheet.default_finish {
        finish("sheet/default_finish", f)?;
    }
    for (id, f) in &spec.features {
        let base = format!("features/{}", crate::items::key(id));
        if let Some(x) = &f.finish {
            finish(&format!("{base}/finish"), x)?;
        }
        if let Some(t) = &f.modelled_thread
            && let Some(designation) = &t.designation
        {
            note(&format!("{base}/modelled_thread/designation"), designation)?;
        }
        if let Some(t) = &f.thread {
            let at = format!("{base}/thread");
            metric(&t.designation).map_err(|why| invalid(format!("{why}, at {at}."), vec![]))?;
            if t.length.is_some_and(|l| !(l.is_finite() && l > 0.0)) {
                return Err(invalid(
                    format!("The thread length at {at}/length is not a positive length in mm."),
                    vec![],
                ));
            }
        }
        if let Some(k) = &f.knurl {
            let at = format!("{base}/knurl");
            if !PATTERNS.contains(&k.pattern.as_str()) {
                return Err(invalid(
                    format!(
                        "{:?} at {at}/pattern is not a knurl pattern; they are straight and diamond.",
                        k.pattern
                    ),
                    PATTERNS.map(String::from).to_vec(),
                ));
            }
            if !(k.pitch.is_finite() && k.pitch > 0.0) {
                return Err(invalid(
                    format!("The knurl pitch at {at}/pitch is not a positive length in mm."),
                    vec![],
                ));
            }
        }
        if !f.note_satisfies.is_empty() && f.note.is_none() {
            return Err(invalid(
                format!("{base}/note_satisfies needs a feature note."),
                vec![],
            ));
        }
        if let Some(n) = &f.note {
            note(&format!("{base}/note"), n)?;
        }
    }
    for (key, f) in &spec.faces {
        let base = format!("faces/{}", crate::items::key(key));
        if let Some(x) = &f.finish {
            finish(&format!("{base}/finish"), x)?;
        }
        if let Some(n) = &f.note {
            note(&format!("{base}/note"), n)?;
        }
    }
    Ok(())
}

/// A finish's record fields: its removal condition's term, then Ra in mm, as an AP242 surface
/// texture's are read.
fn texture_fields(f: &FinishSpec) -> Vec<(String, Field)> {
    let removal = f.removal.as_deref().unwrap_or("any");
    let term = REMOVALS
        .iter()
        .find(|(n, _)| *n == removal)
        .map_or("any process allowed", |(_, t)| t);
    vec![
        ("material removal".into(), Field::Text(term.into())),
        ("Ra".into(), Field::Length(f.ra / 1000.0)),
    ]
}

/// The finish, thread, knurl and note records *spec* authors, features first, then faces, then the
/// default finish, each as the AP242 reading would hold one: `surface_finish` (on faces,
/// attached as a datum is), `internal_thread` (a hole's or pattern's) or `external_thread`,
/// `knurl`, a surface label of kind `note` (its leader from its first face's proven site), and
/// the part's `surface_texture`. Refused: an unknown feature or face ([`crate::spec_gdt`]'s
/// refusals), a thread or knurl on a feature of no kind that takes one.
pub(crate) fn records(
    analysis: &Analysis,
    spec: &Spec,
    part: usize,
) -> Result<Vec<Record>, Invalid> {
    use crate::spec_gdt::{attachments, feature_faces, named_faces, record};
    let patterns = analysis
        .recognition
        .as_ref()
        .map_or(&[][..], |r| r.patterns.as_slice());
    let mut out = Vec::new();
    let finish_record = |base: &str, faces: &[usize], f: &FinishSpec| {
        let mut r = record(
            analysis,
            part,
            format!("{SOURCE_PREFIX}{base}/finish"),
            Category::ManufacturingRequirement,
            faces,
        );
        r.kind = "surface_finish".into();
        r.label = format!("Ra {} µm", crate::pmi::fmt_g3(f.ra));
        r.fields = texture_fields(f);
        r.geometry = Some(crate::pmi::finish_geometry_of(
            &r,
            &attachments(analysis, &r),
        ));
        r
    };
    let note_record = |base: &str, faces: &[usize], text: &str| {
        let mut r = record(
            analysis,
            part,
            format!("{SOURCE_PREFIX}{base}/note"),
            Category::SurfaceLabel,
            faces,
        );
        r.kind = "note".into();
        r.label = text.trim().to_string();
        // Its leader hangs from each face's first proven site (a label's `sites`); its view
        // follows its faces' longest extent, as a common label's does.
        let mut g = crate::pmi::Geometry {
            reasons: crate::pmi::placements_reason(&r).into_iter().collect(),
            ..Default::default()
        };
        g.sites = r
            .faces
            .iter()
            .filter_map(|&f| analysis.face_attachments[f].sites.first().copied())
            .collect();
        if g.sites.is_empty() {
            g.reasons
                .push("the note's faces give no proven site for its leader".into());
        }
        r.geometry = Some(g);
        r
    };
    for (id, f) in &spec.features {
        if f.finish.is_none() && f.thread.is_none() && f.knurl.is_none() && f.note.is_none() {
            continue;
        }
        let base = format!("features/{}", crate::items::key(id));
        let faces = feature_faces(analysis, id)?;
        if let Some(x) = &f.finish {
            out.push(finish_record(&base, &faces, x));
        }
        // The kind of feature a thread or knurl is on: a hole or hole pattern takes an internal
        // thread; a turned step or boss an external thread or a knurl.
        let kind = analysis
            .features
            .iter()
            .find(|g| g.id == *id)
            .map(|g| g.kind.as_str())
            .or_else(|| {
                patterns
                    .iter()
                    .any(|p| p.id == *id)
                    .then_some("hole_pattern")
            })
            .unwrap_or("");
        let internal = matches!(kind, "hole" | "hole_pattern");
        let external = matches!(kind, "turned_step" | "boss");
        if let Some(t) = &f.thread {
            if !(internal || external) {
                return Err(invalid(
                    format!(
                        "{id} is a {kind}, which takes no thread ({base}/thread): a thread is on a hole, a hole pattern or a turned step."
                    ),
                    vec![],
                ));
            }
            let (nominal, pitch) = metric(&t.designation).map_err(|why| invalid(why, vec![]))?;
            let mut r = record(
                analysis,
                part,
                format!("{SOURCE_PREFIX}{base}/thread"),
                Category::ManufacturingRequirement,
                &faces,
            );
            r.kind = if internal {
                "internal_thread"
            } else {
                "external_thread"
            }
            .into();
            r.label = t.designation.trim().to_string();
            r.fields = vec![
                ("feature".into(), Field::Text(id.clone())),
                ("designation".into(), Field::Text(r.label.clone())),
                ("nominal".into(), Field::Length(nominal)),
                ("pitch".into(), Field::Length(pitch)),
            ];
            if let Some(l) = t.length {
                r.fields.push(("length".into(), Field::Length(l)));
            }
            out.push(r);
        }
        if let Some(k) = &f.knurl {
            if !external {
                return Err(invalid(
                    format!(
                        "{id} is a {kind}, which takes no knurl ({base}/knurl): a knurl is on a turned step."
                    ),
                    vec![],
                ));
            }
            let mut r = record(
                analysis,
                part,
                format!("{SOURCE_PREFIX}{base}/knurl"),
                Category::ManufacturingRequirement,
                &faces,
            );
            r.kind = "knurl".into();
            r.label = format!(
                "{} knurl, {} mm pitch",
                k.pattern,
                crate::pmi::fmt_g3(k.pitch)
            );
            r.fields = vec![
                ("feature".into(), Field::Text(id.clone())),
                ("pattern".into(), Field::Text(k.pattern.clone())),
                ("pitch".into(), Field::Length(k.pitch)),
            ];
            out.push(r);
        }
        if let Some(n) = &f.note {
            out.push(note_record(&base, &faces, n));
        }
    }
    for (key, f) in &spec.faces {
        if f.finish.is_none() && f.note.is_none() {
            continue;
        }
        let base = format!("faces/{}", crate::items::key(key));
        let faces = named_faces(analysis, key)?;
        if let Some(x) = &f.finish {
            out.push(finish_record(&base, &faces, x));
        }
        if let Some(n) = &f.note {
            out.push(note_record(&base, &faces, n));
        }
    }
    if let Some(f) = &spec.sheet.default_finish {
        let mut r = record(
            analysis,
            part,
            format!("{SOURCE_PREFIX}sheet/default_finish"),
            Category::ManufacturingRequirement,
            &[],
        );
        r.kind = "surface_texture".into();
        // As the reading labels a part's own surface texture, which the sheet reads its Ra from.
        r.label = format!(
            "Ra {} µm unless otherwise specified",
            crate::pmi::fmt_g3(f.ra)
        );
        r.fields = texture_fields(f);
        out.push(r);
    }
    Ok(out)
}

/// Whether the Spec's record *s* states what the file's *pmi* states, so the file's is not drawn:
/// a finish on any of the same faces, the part's default finish, a thread (of either kind) or a
/// knurl on any of the same faces.
pub(crate) fn overrides(s: &Record, pmi: &Record) -> bool {
    let thread = |k: &str| k == "internal_thread" || k == "external_thread";
    let shares = || s.faces.iter().any(|f| pmi.faces.contains(f));
    s.category == Category::ManufacturingRequirement
        && pmi.category == Category::ManufacturingRequirement
        && match s.kind.as_str() {
            "surface_texture" => pmi.kind == "surface_texture",
            "surface_finish" | "knurl" => pmi.kind == s.kind && shares(),
            k if thread(k) => thread(&pmi.kind) && shares(),
            _ => false,
        }
}

/// Refuse unknown roles rather than allowing a typo to suppress unrelated coverage.
pub(crate) fn check_claims(analysis: &Analysis, spec: &Spec) -> Result<(), Invalid> {
    for (id, f) in &spec.features {
        if let Some(view) = &f.gusset_view {
            let valid = crate::lint::gussets::groups(analysis).into_iter().any(|g| {
                g.owner.id == *id
                    && g.read.is_ok_and(|(ribs, _)| {
                        ribs[0]
                            .supports
                            .iter()
                            .any(|(k, _)| crate::dims::end_on(*k) == view)
                    })
            });
            if !valid {
                return Err(invalid(
                    format!(
                        "features/{id}/gusset_view must look along a leg of a readable gusset group (front, side or plan)."
                    ),
                    vec![],
                ));
            }
        }
        if f.modelled_thread.is_some()
            && !analysis
                .features
                .iter()
                .any(|f| f.id == *id && f.kind == "modelled_thread")
        {
            return Err(invalid(
                format!("features/{id}/modelled_thread requires a recognised modelled thread."),
                vec![],
            ));
        }
    }
    if spec.features.values().all(|f| f.note_satisfies.is_empty()) {
        return Ok(());
    }
    let mut ids = crate::dims::measurement_ids(analysis);
    // The vocabulary includes locations already conveyed by datums or symmetry;
    // absence from the missing-requirement findings does not erase a measurable role.
    ids.extend(
        crate::lint::pockets::placed(analysis)
            .into_iter()
            .flat_map(|(f, p)| {
                p.ok().into_iter().flat_map(move |p| {
                    crate::lint::pockets::locations(&p, analysis.envelope[0])
                        .into_iter()
                        .map(move |(role, _)| format!("d:{}/{role}", f.id))
                })
            }),
    );
    // Inclined holes also have entry-point locations in the legacy hole-coverage
    // vocabulary, even where an infinite axis has no unique Cartesian station.
    ids.extend(
        crate::lint::coverage::sites(analysis, &[])
            .into_iter()
            .flat_map(|s| {
                let (subject, axis) = (s.subject, s.axis);
                (0..3)
                    .filter(move |&k| k != axis)
                    .map(move |k| format!("d:{subject}/location.length.{}", ["x", "y", "z"][k]))
            }),
    );
    ids.extend(
        crate::lint::location::targets(analysis)
            .into_iter()
            .map(|(f, k, _)| format!("d:{f}/location.length.{}", ["x", "y", "z"][k])),
    );
    // A concentric pattern's location is still a measurable role when its
    // numeric tangent dimensions are correctly suppressed (#311, #312).
    let holes: Vec<_> = crate::bridge::holes::read(analysis)
        .into_iter()
        .filter_map(|(_, h)| h.ok())
        .collect();
    let refs: Vec<_> = holes.iter().collect();
    let bosses = crate::bridge::holes::bosses(analysis);
    for p in analysis.recognition.iter().flat_map(|r| &r.patterns) {
        let Ok(members) = crate::bridge::holes::established_with(p, &refs, &bosses) else {
            continue;
        };
        if let Some((axis, _)) = holes[members[0]].principal {
            for k in (0..3).filter(|&k| k != axis) {
                ids.insert(format!("d:{}/location.length.{}", p.id, ["x", "y", "z"][k]));
            }
        }
    }
    for (id, f) in &spec.features {
        for role in &f.note_satisfies {
            if !ids.contains(&format!("d:{id}/{role}")) {
                return Err(invalid(
                    format!("{role:?} is not a measurement role of {id}."),
                    vec![],
                ));
            }
        }
    }
    Ok(())
}

pub(crate) fn satisfaction(spec: &Spec, source: &str) -> Vec<crate::output::Claim> {
    let Some(id) = source
        .strip_prefix("spec:features/")
        .and_then(|s| s.strip_suffix("/note"))
    else {
        return vec![];
    };
    spec.features
        .get(id)
        .into_iter()
        .flat_map(|f| &f.note_satisfies)
        .map(|p| crate::output::Claim {
            feature: id.into(),
            parameter: p.clone(),
        })
        .collect()
}