Compare commits

...
Author SHA1 Message Date
shaneandshinyobjectz 1b20fff4d0 A part never stands on what it holds: a mug isn't sunk into its coffee (#365)
Co-authored-by: shinyobjectz <[email protected]>
2026-12-06 07:23:27 -08:00
2 changed files with 25 additions and 1 deletions

No files matched your search

+9 -1
View File
@@ -132,6 +132,12 @@ fn insets(parts: &[Part]) -> Vec<Option<usize>> {
.collect()
}
/// Whether `inner` lies wholly in `outer`'s box (within a millimetre): what `outer` holds, never what it stands on.
fn holds(outer: &Part, inner: &Part) -> bool {
let e = Vec3::splat(0.001);
inner.lo.cmpge(outer.lo - e).all() && inner.hi.cmple(outer.hi + e).all()
}
fn rest_of(parts: &[Part], grid: &Grid, insets: &[Option<usize>], i: usize) -> Rest {
let p = &parts[i];
let height = p.hi.y - p.lo.y;
@@ -147,7 +153,9 @@ fn rest_of(parts: &[Part], grid: &Grid, insets: &[Option<usize>], i: usize) -> R
let mut col = grid.column(parts, f.x, f.z, i);
// a part and the wall it's set into don't stand on each other, nor do a wall's pieces (a corner, the wall over
// a window)
col.retain(|&(y, j, _)| y <= f.y + up && insets[i] != Some(j) && insets[j] != Some(i) && !(wall(p) && wall(&parts[j])));
// nor does a part stand on what it holds: coffee in its mug, soil in its pot, a box's contents (12-06, the 3D
// proof: "mug is sunk 12.0 mm into coffee", the coffee's top a floor's thickness above the mug's foot)
col.retain(|&(y, j, _)| y <= f.y + up && insets[i] != Some(j) && insets[j] != Some(i) && !(wall(p) && wall(&parts[j])) && !holds(p, &parts[j]));
let Some(&(y, j, k)) = col.iter().max_by(|a, b| a.0.total_cmp(&b.0)) else { continue };
let gap = f.y - y;
tested += 1;
+16
View File
@@ -170,3 +170,19 @@ fn a_thing_left_in_the_air_is_an_error_unless_it_glows_or_is_floating() {
let (_, level, _, errors) = air(json!({}), json!({"emissive": {"red": 2200.0, "green": 120.0, "blue": 80.0, "alpha": 1.0}}));
assert_eq!((level.as_str(), errors), ("note", 0));
}
#[test]
fn a_mug_stands_on_the_table_not_on_its_coffee() {
let floor = part("floor", Vec3::new(0.0, -0.05, 0.0), Vec3::new(4.0, 0.1, 4.0));
let mug = part("mug", Vec3::new(0.3, 0.05, 0.2), Vec3::new(0.08, 0.1, 0.08));
// the coffee in it: its top 12 mm above the mug's foot, wholly inside the mug's box
let coffee = part("coffee", Vec3::new(0.3, 0.007, 0.2), Vec3::new(0.06, 0.01, 0.06));
let parts = [floor, mug, coffee];
match rest(&parts, 1) {
Rest::On { under, gap, .. } => {
assert_eq!(parts[under].label, "floor");
assert!(gap.abs() <= TOUCH, "{gap}");
}
r => panic!("the mug should rest on the floor: {r:?}"),
}
}