use super::parameters::{self, Wanted, fmt, fmt3};
use super::section_recesses::{BlindSlot, Grammar, grammar, recesses};
use super::{LintIssue, Mark};
use crate::bridge::Feature;
use crate::bridge::holes::{frame, to_part};
use crate::model::Analysis;
fn slots(analysis: &Analysis, round: bool) -> Vec<(&Feature, BlindSlot)> {
recesses(analysis)
.into_iter()
.filter_map(|f| match grammar(f) {
Ok(Grammar::RectangularBlindSlot(s)) if !round => Some((f, s)),
Ok(Grammar::RoundBottomBlindSlot(s)) if round => Some((f, s)),
_ => None,
})
.collect()
}
pub fn wanted(analysis: &Analysis, round: bool) -> Vec<Wanted<'_>> {
let mut out = Vec::new();
for (f, s) in slots(analysis, round) {
let sizes = if round {
[
("round_bottom_blind_slot_length.length", s.length, "long"),
(
"round_bottom_blind_slot_flat_width.length",
s.width - 2.0 * s.depth,
"bottom flat",
),
("round_bottom_blind_slot_radius.radius", s.depth, "R"),
]
} else {
[
("rectangular_blind_slot_width.length", s.width, "wide"),
("rectangular_blind_slot_length.length", s.length, "long"),
("rectangular_blind_slot_depth.length", s.depth, "deep"),
]
};
out.extend(sizes.into_iter().map(|(parameter, v, word)| Wanted {
feature: f,
parameter: parameter.into(),
values: Ok(vec![v]),
callout: if word == "R" {
format!("R{}", fmt(v))
} else {
format!("{} {word}", fmt(v))
},
}));
}
out
}
fn findings(analysis: &Analysis, marks: &[Mark], round: bool) -> Vec<LintIssue> {
let read = slots(analysis, round);
let frame = frame(analysis);
let noun = |f: &Feature| {
let mut s = format!(
"{} blind slot {}",
if round { "round-bottom" } else { "rectangular" },
f.id
);
if let Some((_, b)) = read.iter().find(|(g, _)| g.id == f.id) {
s += &if round {
format!(
" {} bottom flat × R{} × {} long",
fmt(b.width - 2.0 * b.depth),
fmt(b.depth),
fmt(b.length)
)
} else {
format!(
" {} × {} × {} deep",
fmt(b.width),
fmt(b.length),
fmt(b.depth)
)
};
s += &format!(", at {}", fmt3(to_part(&frame, b.origin)));
}
s
};
parameters::coverage(
if round {
"round_bottom_blind_slot"
} else {
"rectangular_blind_slot"
},
&wanted(analysis, round),
marks,
noun,
"the slot's callout, in the view that looks into it",
)
}
pub fn coverage(analysis: &Analysis, marks: &[Mark]) -> Vec<LintIssue> {
let mut issues = findings(analysis, marks, false);
issues.extend(findings(analysis, marks, true));
issues
}
pub fn semicircular_wanted(analysis: &Analysis) -> Vec<Wanted<'_>> {
let mut out = Vec::new();
for f in analysis
.features
.iter()
.filter(|f| f.kind == "semicircular_blind_slot")
{
let radius = parameters::size(f, "radius");
let depth = radius
.clone()
.and_then(|r| Ok(r + parameters::size(f, "straight_height")?));
for (parameter, value, word) in [
(
"semicircular_blind_slot_width.length",
radius.map(|r| 2.0 * r),
"wide",
),
(
"semicircular_blind_slot_length.length",
parameters::size(f, "length"),
"long",
),
("semicircular_blind_slot_depth.length", depth, "deep"),
] {
out.push(Wanted {
feature: f,
parameter: parameter.into(),
callout: value.as_ref().map_or(format!("its {parameter}"), |v| {
format!("{} {word}", fmt(*v))
}),
values: value.map(|v| vec![v]),
});
}
}
out
}
pub fn semicircular_coverage(analysis: &Analysis, marks: &[Mark]) -> Vec<LintIssue> {
let noun = |f: &Feature| format!("semicircular blind slot {}", f.id);
parameters::coverage(
"semicircular_blind_slot",
&semicircular_wanted(analysis),
marks,
noun,
"the slot's callout, in the view that looks into it",
)
}
#[cfg(test)]
mod tests {
use super::super::paired_ramp_steps::tests::part;
use super::super::section_recesses::tests::recess;
use super::*;
use crate::output::Claim;
fn mark(text: &str, parameters: &[&str]) -> Mark {
Mark {
precision: None,
units: Default::default(),
name: "m_slot".into(),
view: Some("v:front".into()),
text: text.into(),
claims: parameters
.iter()
.map(|p| Claim {
feature: "f:section_recess:1".into(),
parameter: p.to_string(),
})
.collect(),
}
}
#[test]
fn a_rectangular_blind_slot_states_width_length_and_depth() {
let frame = [
[0.0, 0.0, 0.0],
[0.0, 0.0, -1.0],
[-1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
];
let u = [
([5.0, 10.0], 0.0),
([5.0, 5.0], 0.0),
([-5.0, 5.0], 0.0),
([-5.0, 10.0], 0.0),
];
let a = part(
"section_recess",
recess(
"edge_open_recess",
"rectangular",
frame,
[-20.0, 0.0],
[false, true],
false,
&u,
),
);
let w = wanted(&a, false);
let got: Vec<(&str, f64)> = w
.iter()
.map(|w| (w.parameter.as_str(), w.values.as_ref().unwrap()[0]))
.collect();
assert_eq!(
got,
[
("rectangular_blind_slot_width.length", 10.0),
("rectangular_blind_slot_length.length", 20.0),
("rectangular_blind_slot_depth.length", 5.0)
]
);
assert!(wanted(&a, true).is_empty());
let all = [
"rectangular_blind_slot_width.length",
"rectangular_blind_slot_length.length",
"rectangular_blind_slot_depth.length",
];
assert!(coverage(&a, &[mark("OPEN SLOT 10 × 20 × 5 DEEP", &all)]).is_empty());
let codes = |marks: &[Mark]| -> Vec<String> {
coverage(&a, marks)
.into_iter()
.map(|i| format!("{} {}", i.code, i.requirements[0].parameter))
.collect()
};
assert_eq!(
codes(&[mark("10", &all[..1])]),
[
"rectangular_blind_slot_requirement_missing rectangular_blind_slot_length.length",
"rectangular_blind_slot_requirement_missing rectangular_blind_slot_depth.length"
]
);
assert_eq!(
codes(&[mark("OPEN SLOT 10 × 20 × 6 DEEP", &all)]),
["rectangular_blind_slot_requirement_unverifiable rectangular_blind_slot_depth.length"]
);
assert_eq!(
coverage(&a, &[])[0].message,
"rectangular blind slot f:section_recess:1 10 × 20 × 5 deep, at (0, 7.5, 10): \
requirement rectangular_blind_slot_width.length (10 wide) is not stated on the sheet"
);
}
#[test]
fn a_round_bottom_blind_slot_states_length_flat_and_radius() {
let q = 0.414213562373;
let x_run = [
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
];
let rb = [
([-5.0, 10.0], q),
([-2.0, 7.0], 0.0),
([2.0, 7.0], q),
([5.0, 10.0], 0.0),
];
let a = part(
"section_recess",
recess(
"edge_open_recess",
"general",
x_run,
[-20.0, 0.0],
[false, true],
false,
&rb,
),
);
let all = [
"round_bottom_blind_slot_length.length",
"round_bottom_blind_slot_flat_width.length",
"round_bottom_blind_slot_radius.radius",
];
let got: Vec<(String, f64)> = wanted(&a, true)
.into_iter()
.map(|w| (w.parameter, w.values.unwrap()[0]))
.collect();
assert_eq!(
got,
[
(all[0].to_string(), 20.0),
(all[1].to_string(), 4.0),
(all[2].to_string(), 3.0)
]
);
assert!(
coverage(
&a,
&[mark(
"ROUND-BOTTOM OPEN SLOT 4 BOTTOM FLAT × R3 × 20 LONG",
&all
)]
)
.is_empty()
);
assert_eq!(
coverage(&a, &[]).len(),
3,
"each requirement is missing without a callout"
);
}
}