From fec539a56909f00a51ac5b8048391dc3282b667d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 25 Nov 2026 22:51:51 +0100 Subject: [PATCH] Pin shell fit across every shell and box axis, capsule and sphere radius, and +Infinity refusal on thickness and sheet fields Co-Authored-By: Claude Sonnet 5.5 --- tests/Lodur.Core.Tests/PhysiologyPlanTests.cs | 5 +++ tests/Lodur.Core.Tests/PhysiologyTests.cs | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tests/Lodur.Core.Tests/PhysiologyPlanTests.cs b/tests/Lodur.Core.Tests/PhysiologyPlanTests.cs index 77c7204..03acc4d 100644 --- a/tests/Lodur.Core.Tests/PhysiologyPlanTests.cs +++ b/tests/Lodur.Core.Tests/PhysiologyPlanTests.cs @@ -63,14 +63,19 @@ public sealed class PhysiologyPlanTests var shell = t with { Label = "shell", Thickness = 0.01, Sheet = sheet }; Refuses(() => Plan(new[] { t with { Thickness = -1 } })); Refuses(() => Plan(new[] { t with { Thickness = double.NaN } })); + Refuses(() => Plan(new[] { t with { Thickness = double.PositiveInfinity } })); Refuses(() => Plan(new[] { t with { Sheet = sheet } })); // a sheet on Thickness 0 Refuses(() => Plan(new[] { shell with { Sheet = sheet with { Spacing = 0 } } })); Refuses(() => Plan(new[] { shell with { Sheet = sheet with { Spacing = double.NaN } } })); + Refuses(() => Plan(new[] { shell with { Sheet = sheet with { Spacing = double.PositiveInfinity } } })); Refuses(() => Plan(new[] { shell with { Sheet = sheet with { EdgeCompliance = -1 } } })); + Refuses(() => Plan(new[] { shell with { Sheet = sheet with { EdgeCompliance = double.PositiveInfinity } } })); Refuses(() => Plan(new[] { shell with { Sheet = sheet with { EdgeCompliance = double.NaN } } })); Refuses(() => Plan(new[] { shell with { Sheet = sheet with { AttachCompliance = -1 } } })); + Refuses(() => Plan(new[] { shell with { Sheet = sheet with { AttachCompliance = double.PositiveInfinity } } })); Refuses(() => Plan(new[] { shell with { Sheet = sheet with { TensileStrength = 0 } } })); Refuses(() => Plan(new[] { shell with { Sheet = sheet with { TensileStrength = double.NaN } } })); + Refuses(() => Plan(new[] { shell with { Sheet = sheet with { TensileStrength = double.PositiveInfinity } } })); Refuses(() => Plan(new[] { t, shell })); // a shell after a core var a = new AfflictionDef("a", PhysiologyClock.Acute, 0, true, Array.Empty()); diff --git a/tests/Lodur.Core.Tests/PhysiologyTests.cs b/tests/Lodur.Core.Tests/PhysiologyTests.cs index f299332..97a007e 100644 --- a/tests/Lodur.Core.Tests/PhysiologyTests.cs +++ b/tests/Lodur.Core.Tests/PhysiologyTests.cs @@ -75,6 +75,48 @@ public sealed class PhysiologyTests Shelled(0.019).Resolve(slab); } + private static BodyPlan RootOf(PartShape shape, (float X, float Y, float Z) size) + { + PartDef P(string label, PartShape sh, (float X, float Y, float Z) sz) => new(label, Side.Center, sh, sz, (0f, 0f, 0f), Quat.Identity, 1000f, 0.8f, 0f); + var joint = new JointDef("J", Side.Center, JointKind.Spherical, 0, 1, (0f, 0f, 0f), (0f, 1f, 0f), 0f, 0f, 0f, new MuscleGains(1f, 1f, 1f, 1f)); + return new BodyPlan(new[] { P("Root", shape, size), P("Kid", PartShape.Box, (0.1f, 0.1f, 0.1f)) }, new[] { joint }, Array.Empty()); + } + + private static PhysiologyPlan Layered(params double[] shells) + { + var tissues = new TissueDef[shells.Length + 1]; + for (var i = 0; i < shells.Length; i++) tissues[i] = new TissueDef("s" + i, 10, 1) with { Thickness = shells[i] }; + tissues[shells.Length] = BrainT; + return Over(Stack("Root", tissues), Stack("Kid", MuscleT)); + } + + [Fact] + public void Every_shell_counts_and_every_box_axis_bounds_the_fit() + { + var cube = RootOf(PartShape.Box, (0.1f, 0.1f, 0.1f)); + Layered(0.04, 0.04).Resolve(cube); + Assert.Throws(() => Layered(0.06, 0.06).Resolve(cube)); // the sum, not the first or the largest + Assert.Throws(() => Layered(0.01, 0.05, 0.05).Resolve(cube)); // the last shell counts + + foreach (var thin in new[] { (0.02f, 0.1f, 0.1f), (0.1f, 0.02f, 0.1f), (0.1f, 0.1f, 0.02f) }) + { + var body = RootOf(PartShape.Box, thin); + Layered(0.019).Resolve(body); + Assert.Throws(() => Layered(0.03).Resolve(body)); + } + } + + [Fact] + public void A_capsule_and_a_sphere_fit_shells_inside_the_radius() + { + foreach (var body in new[] { RootOf(PartShape.Capsule, (0.1f, 0.5f, 0f)), RootOf(PartShape.Sphere, (0.1f, 0f, 0f)) }) + { + Layered(0.0999).Resolve(body); + Assert.Throws(() => Layered(0.1).Resolve(body)); + Assert.Throws(() => Layered(0.06, 0.06).Resolve(body)); + } + } + [Fact] public void A_physiology_refuses_a_body_with_no_consciousness_tissue_or_a_joint_child_with_no_motor_tissue() {