Major vessels are sited tissues among the shells: carotids at the side of the neck, femoral at the inner thigh
Reach gates a sited tissue by the shells listed before it (stack order is depth order); an unsited core keeps the total, and the validator refuses a shell only after an unsited core. Every shipped sited core follows all its shells, so its reach is unchanged (831,060-case sweep: only the Femoral differs). Content: VesselV 3.5, CarotidLeft/Right on the head, Femoral on each thigh; LarynxV 1.0 -> 0.7 and the airway's cough 2.0 -> 0.3 so the front of the throat drowns him before it bleeds him out. Pins: the vessel and throat bands on a real Actor at severity 20 and gain 10, the cough bound re-derived, and LowestHysteresis pinned by its own margin (1 mm and 10 mm fail). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
15c955bda7
commit
5a43458689
8 changed files with 245 additions and 22 deletions
|
|
@ -35,7 +35,7 @@ namespace Lodur
|
|||
/// One tissue layer of a part. <paramref name="Consciousness"/>, <paramref name="BloodPumping"/> and <paramref name="Motor"/> are
|
||||
/// function weights, a closed set with one reader each (<paramref name="Breathing"/> is the lungs' share of ventilation): a capacity is the weighted mean integrity of the tissues that carry its weight.
|
||||
/// A Vital tissue at integrity 0 kills. A stack is shells (<see cref="Thickness"/> above 0, in m) outside-in, then cores (Thickness 0:
|
||||
/// bone, organs, a muscle with no sheet); a core with a <see cref="Site"/> occupies that sphere of the part, one with none fills what the shells leave of the part's shape. <see cref="Sheet"/> is the
|
||||
/// bone, organs, a muscle with no sheet); a core with a <see cref="Site"/> occupies that sphere of the part, one with none fills what the shells leave of the part's shape. Stack order is depth order: a sited tissue may sit among the shells (a vessel between fat and a muscle sheet), at the depth the shells listed before it give; an unsited core fills past all the shells and may not precede one. <see cref="Sheet"/> is the
|
||||
/// material of a shell simulated as a particle sheet; null means it is not.
|
||||
/// </summary>
|
||||
public readonly record struct TissueDef(
|
||||
|
|
@ -44,7 +44,7 @@ namespace Lodur
|
|||
public double Thickness { get; init; }
|
||||
public SheetDef? Sheet { get; init; }
|
||||
|
||||
/// <summary>Where a core sits in the part's frame; null fills the part past its shells. A shell takes none.</summary>
|
||||
/// <summary>Where a core sits in the part's frame; null fills the part past its shells. A shell takes none. A sited tissue's depth is the summed thickness of the shells listed before it.</summary>
|
||||
public TissueSite? Site { get; init; }
|
||||
|
||||
/// <summary>The fraction, 0..1, of a wound's bleed in this tissue that enters the airway instead of leaving through the part's surface (the larynx, trachea and lungs' mucosa); 0 for every other tissue.</summary>
|
||||
|
|
@ -56,8 +56,8 @@ namespace Lodur
|
|||
{
|
||||
/// <summary>
|
||||
/// The layers a wound of <paramref name="depth"/> (m, finite and above 0) at <paramref name="point"/> (the part's frame) reaches, written into <paramref name="layers"/> as stack indices in stack order; returns the count.
|
||||
/// Shells (Thickness above 0) outside-in: shell i is reached iff depth exceeds the summed Thickness of the shells before it. With S the shells' total, a core is reached iff depth exceeds S and
|
||||
/// (it has no Site, or depth exceeds the distance from point to the Site's centre less its radius). Strict: a depth equal to a boundary does not reach past it. Allocates nothing.
|
||||
/// Shells (Thickness above 0) outside-in: shell i is reached iff depth exceeds the summed Thickness of the shells before it. With S the shells' total and B the summed Thickness of the shells listed before a core:
|
||||
/// an unsited core is reached iff depth exceeds S; a sited one iff depth exceeds B and depth exceeds the distance from point to the Site's centre less its radius (B is S for a site listed after every shell). Strict: a depth equal to a boundary does not reach past it. Allocates nothing.
|
||||
/// </summary>
|
||||
public int Reach((float X, float Y, float Z) point, double depth, Span<int> layers)
|
||||
{
|
||||
|
|
@ -76,10 +76,13 @@ namespace Lodur
|
|||
if (depth > before) layers[n++] = i;
|
||||
before += t.Thickness;
|
||||
}
|
||||
else if (depth > shells)
|
||||
else
|
||||
{
|
||||
if (t.Site is not TissueSite site) layers[n++] = i;
|
||||
else
|
||||
if (t.Site is not TissueSite site)
|
||||
{
|
||||
if (depth > shells) layers[n++] = i;
|
||||
}
|
||||
else if (depth > before)
|
||||
{
|
||||
double dx = point.X - site.Centre.X, dy = point.Y - site.Centre.Y, dz = point.Z - site.Centre.Z;
|
||||
if (depth > Math.Sqrt(dx * dx + dy * dy + dz * dz) - site.Radius) layers[n++] = i;
|
||||
|
|
@ -299,8 +302,8 @@ namespace Lodur
|
|||
if (!(float.IsFinite(site.Radius) && site.Radius > 0f)) throw new ArgumentException($"{where}: the site radius is not finite and above 0.");
|
||||
}
|
||||
|
||||
if (t.Thickness == 0.0) core = true;
|
||||
else if (core) throw new ArgumentException($"{where}: a shell follows a core.");
|
||||
if (t.Thickness == 0.0 && t.Site is null) core = true;
|
||||
else if (t.Thickness > 0.0 && core) throw new ArgumentException($"{where}: a shell follows a core.");
|
||||
if (t.Sheet is SheetDef sh)
|
||||
{
|
||||
if (!(t.Thickness > 0.0)) throw new ArgumentException($"{where}: a sheet needs a thickness above 0.");
|
||||
|
|
|
|||
|
|
@ -12,7 +12,12 @@ namespace Lodur
|
|||
private const double SkinV = 0.2, MuscleV = 1.0, BoneV = 0.3, BrainV = 1.0, HeartV = 4.0, LungV = 2.0, LiverV = 3.0, KidneyV = 2.0, GutV = 1.0;
|
||||
|
||||
// Airway tissues: mucosa as perfused as muscle (placeholders). AirwayShare is the fraction of a wound's bleed that enters the airway: all of the larynx's and trachea's, half a lung's (half coughed up, half stays in the chest).
|
||||
private const double LarynxV = 1.0, TracheaV = 1.0, MucosaShare = 1.0, LungShare = 0.5;
|
||||
private const double LarynxV = 0.7, TracheaV = 1.0, MucosaShare = 1.0, LungShare = 0.5;
|
||||
|
||||
// Major vessels: a sited tissue placed among the shells at its depth (ruling bds-bleed-by-vessels), so a knife at the side of the neck or the inner thigh reaches one and the front of the throat does not.
|
||||
// VesselV is play-tuned (probe: at the BDS knife's severity 20 and blood gain 10 either dies of blood loss at about 30 s; 3.0 gave 33.9 s, 4.0 gave 26.5 s). A vessel is no airway tissue (AirwayShare 0).
|
||||
// LarynxV 1.0 -> 0.7: at 1.0 the front of the throat bled him out before it drowned him (grid in the cut report); 0.7 with the cough at 0.3 drowns him first (ruling bds-drown-in-own-blood-first).
|
||||
private const double VesselV = 3.5;
|
||||
|
||||
// Fat is thickness in the stack, not particles; its vascularity is a placeholder.
|
||||
private const double FatV = 0.1;
|
||||
|
|
@ -55,14 +60,20 @@ namespace Lodur
|
|||
new TissueDef("Trachea", 10, TracheaV) { AirwayShare = MucosaShare, Site = new TissueSite((0f, 0.2f, 0.06f), 0.015f) });
|
||||
// The neck's muscle carries the Neck joint's motor weight: the head has to be a joint child with a muscle (spec discrepancy, report deviation).
|
||||
// Head sites are placeholders in the part's frame (+z face, -y chin), probed against PartTissuesDef.Reach: the neck muscle low at the chin, skull and brain about the crown, the larynx at the throat.
|
||||
Stack("Head", Side.Center, Skin(5), Fat(5), Muscle(25) with { Site = new TissueSite((0f, -0.085f, -0.01f), 0.06f) }, Bone("Skull", 25) with { Site = new TissueSite((0f, 0.02f, -0.005f), 0.09f) },
|
||||
// The carotids lie at the side of the neck, 0.055 m either side of the midline (placeholders), after the fat and before the muscle: a depth-2 cm wound at the side reaches one, the front of the throat does not.
|
||||
Stack("Head", Side.Center, Skin(5), Fat(5),
|
||||
new TissueDef("CarotidLeft", 10, VesselV) { Site = new TissueSite((0.055f, -0.07f, 0.01f), 0.012f) },
|
||||
new TissueDef("CarotidRight", 10, VesselV) { Site = new TissueSite((-0.055f, -0.07f, 0.01f), 0.012f) },
|
||||
Muscle(25) with { Site = new TissueSite((0f, -0.085f, -0.01f), 0.06f) }, Bone("Skull", 25) with { Site = new TissueSite((0f, 0.02f, -0.005f), 0.09f) },
|
||||
new TissueDef("Brain", 10, BrainV, Vital: true, Consciousness: 1.0) { Site = new TissueSite((0f, 0.02f, -0.005f), 0.07f) },
|
||||
new TissueDef("Larynx", 10, LarynxV) { AirwayShare = MucosaShare, Site = new TissueSite((0f, -0.075f, 0.06f), 0.015f) });
|
||||
foreach (var side in new[] { Side.Left, Side.Right })
|
||||
{
|
||||
Stack("UpperArm", side, Skin(8), Fat(8), MuscleSheet(30), Bone("Humerus", 25));
|
||||
Stack("LowerArm", side, Skin(8), Fat(8), MuscleSheet(25), Bone("Radius", 20));
|
||||
Stack("Thigh", side, Skin(10), Fat(10), MuscleSheet(30), Bone("Femur", 25));
|
||||
// The femoral vessel runs at the inner thigh (sx +1 Left, -1 Right: the inner side is toward the midline), between the fat and the muscle sheet (placeholder site in the part's frame).
|
||||
var sx = side == Side.Left ? 1f : -1f;
|
||||
Stack("Thigh", side, Skin(10), Fat(10), new TissueDef("Femoral", 10, VesselV) { Site = new TissueSite((-sx * 0.032f, 0.12f, 0.032f), 0.012f) }, MuscleSheet(30), Bone("Femur", 25));
|
||||
Stack("Shin", side, Skin(8), Fat(8), MuscleSheet(25), Bone("Tibia", 25));
|
||||
Stack("Foot", side, Skin(5), Muscle(20), Bone("Bones", 25));
|
||||
Stack("Palm", side, Skin(5), Muscle(20), Bone("Metacarpals", 15));
|
||||
|
|
@ -103,9 +114,9 @@ namespace Lodur
|
|||
// a breath tried and not got is felt at once (Banzett, Lansing and Schwartzstein, Air hunger, Respir Physiol Neurobiol 2008).
|
||||
new[] { (0.5, 0.0), (1.3, 1.0) }, new[] { (0.5, 0.0), (1.0, 0.6) }),
|
||||
// The airway (placeholders). Capacity 150 mL is 2 mL/kg at 75 kg (an upper-airway and bronchial volume, the lung's own is far larger: the airway fills before the lung); it holds the breath from 15.6 mL
|
||||
// of liquid at the openings (a mouthful, a tenth of the capacity). A free breath draws the liquid at the airway in at 1 per second, an awake cough clears 2 per second of what is there and fails below 0.3
|
||||
// of liquid at the openings (a mouthful, a tenth of the capacity). A free breath draws the liquid at the airway in at 1 per second, an awake cough clears 0.3 per second of what is there (a continuous airway bleed at the knife's severity must beat the cough, or the front of the throat bleeds him out instead of drowning him) and fails below 0.3
|
||||
// consciousness, and the airway drains at 0.1 per second once the lowest rim of an opening lies 5 cm below the deepest sump (a true side pose, drop 0.025 m the mouth's half-width, halves it; side-lying falls measure a median 0.043 m, upright -0.047 m, so he drains nothing standing). Liquid and pooled liquid count alike.
|
||||
new AirwayDef(150e-6, 1.0, 1.0, 1.0, 15.6e-6, 2.0, new[] { (0.3, 0.0), (0.6, 1.0) }, 0.1, 0.05), 64);
|
||||
new AirwayDef(150e-6, 1.0, 1.0, 1.0, 15.6e-6, 0.3, new[] { (0.3, 0.0), (0.6, 1.0) }, 0.1, 0.05), 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,20 +274,22 @@ public sealed class AirwayPhysiologyTests
|
|||
[Fact]
|
||||
public void An_awake_Fella_coughs_his_airway_clear()
|
||||
{
|
||||
// Placeholders deciding this: Cough (2.2 s to clear half, and every bound below); Draw only fills the half airway first and decides no outcome; Drain is 0 face up and decides nothing.
|
||||
// Half the airway, awake, face up, nothing at the openings: gone (below 1e-6, a 75-fold fall) in 10 s; shipped it takes 2.2 s. Without the cough (or with one gated by something else) it never falls.
|
||||
// Placeholders deciding this: Cough (0.3 per second, a continuous airway bleed must beat it: ruling bds-drown-in-own-blood-first) and every bound below; Draw only fills the half airway first and decides no outcome; Drain is 0 face up and decides nothing.
|
||||
// Half the airway, awake, face up, nothing at the openings, 20 s. Readings (deterministic): shipped liquid 1.9e-7 m^3 (half the airway down to 0.25%, quarter at 2.4 s), a cough at half the rate 3.86e-6 (quarter at 4.9 s), no cough 7.8e-5.
|
||||
// Liquid bound 8.6e-7 = sqrt(1.9e-7 x 3.86e-6), separation 20 (ruling deterministic-bound-margin); the half-rate cough is claimed. Coughed total (fraction of capacity): shipped 0.515, no cough 0 (one unit 0.01,
|
||||
// midpoint 0.07): the bound stays at 0.4, tighter than that midpoint, 1.29 under the shipped reading; a half-rate cough (0.493) is not claimed by this metric, the liquid bound claims it.
|
||||
var p = Breather(20.0);
|
||||
var flood = new PhysiologyInput(0.0, 0.0, false, new AirwaySample(100.0 * HoldAt, 0.0, 0.0));
|
||||
while (p.AirwayLiquid < 0.5 * Capacity) p.Step(Dt, flood);
|
||||
var clear = new PhysiologyInput(0.0, 0.0, false, new AirwaySample(0.0, 0.0, 0.0));
|
||||
double coughed = 0.0;
|
||||
for (long i = 0; i < (long)(10.0 / Dt); i++)
|
||||
for (long i = 0; i < (long)(20.0 / Dt); i++)
|
||||
{
|
||||
p.Step(Dt, clear);
|
||||
coughed += p.Coughed;
|
||||
}
|
||||
|
||||
Assert.True(p.AirwayLiquid < 1e-6, $"airway liquid {p.AirwayLiquid}");
|
||||
Assert.True(p.AirwayLiquid < 8.6e-7, $"airway liquid {p.AirwayLiquid}");
|
||||
Assert.True(coughed > 0.4 * Capacity, $"coughed {coughed}");
|
||||
Assert.Equal(0.0, p.Drained);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,6 +116,9 @@ public sealed class PhysiologyPlanTests
|
|||
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 vessel = t with { Label = "vessel", Site = new TissueSite((0f, 0f, 0f), 0.01f) };
|
||||
Plan(new[] { vessel, shell }); // a sited tissue may precede a shell: stack order is depth order
|
||||
Refuses(() => Plan(new[] { t, vessel, shell })); // a shell after an unsited core, a sited tissue between or not
|
||||
|
||||
var a = new AfflictionDef("a", PhysiologyClock.Acute, 0, true, Array.Empty<Effect>());
|
||||
Refuses(() => Plan(afflictions: new[] { a, a })); // duplicate affliction label
|
||||
|
|
|
|||
|
|
@ -100,7 +100,9 @@ public sealed class PhysiologyPlansTests
|
|||
|
||||
var muscleSheet = tissues.Any(t => t.Label == "Muscle" && t.Sheet != null);
|
||||
var shells = 1 + (fat ? 1 : 0) + (muscleSheet ? 1 : 0);
|
||||
for (var l = shells; l < tissues.Count; l++) Assert.Equal(0.0, tissues[l].Thickness); // cores only after the shells
|
||||
Assert.Equal(shells, tissues.Count(t => t.Thickness > 0.0));
|
||||
var lastShell = tissues.ToList().FindLastIndex(t => t.Thickness > 0.0);
|
||||
for (var l = 0; l < lastShell; l++) Assert.True(tissues[l].Thickness > 0.0 || tissues[l].Site != null, $"{label}: an unsited core precedes a shell"); // only a sited tissue (a vessel) sits among the shells
|
||||
|
||||
Assert.Equal(Array.IndexOf(sheetKinds, label) >= 0, muscleSheet);
|
||||
if (muscleSheet) muscleSheets++;
|
||||
|
|
|
|||
111
tests/Lodur.Core.Tests/VesselTests.cs
Normal file
111
tests/Lodur.Core.Tests/VesselTests.cs
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
using Lodur;
|
||||
|
||||
namespace Lodur.Core.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// The humanoid's vessel bands on a real Actor: a knife cut at the BDS knife's severity and the BDS blood gain (ruling bds-blood-gain-simulated; both fixtures here, named, as
|
||||
/// the BDS client maps them) kills in about 30 s of blood loss when it opens a carotid or the femoral, and drowns him first when it opens the front of the throat
|
||||
/// (rulings bds-bleed-by-vessels, bds-drown-in-own-blood-first). The Actor's brain clutches on air hunger, as a body that struggles for breath does.
|
||||
/// </summary>
|
||||
public sealed class VesselTests
|
||||
{
|
||||
private const double Dt = 0.01;
|
||||
private const double KnifeSeverity = 20.0;
|
||||
private const double BloodGain = 10.0;
|
||||
|
||||
private static readonly BodyPlan Body = BodyPlans.Humanoid();
|
||||
private static readonly PhysiologyPlan Plan = PhysiologyPlans.Humanoid();
|
||||
private static readonly float[] NoPoint = { 0f };
|
||||
|
||||
private readonly record struct Band(DeathCause Cause, double DeadAt, double OutAt, double BrainOxygenOut, double BloodLossOut, double MaxOcclusion, double OcclusionFullAt, string[] Layers);
|
||||
|
||||
/// <summary>The identity pose of every joint of the humanoid, the pose the clutch goal holds.</summary>
|
||||
private static Quat[] Identity() => Enumerable.Repeat(Quat.Identity, Body.Joints.Count).ToArray();
|
||||
|
||||
private static Brain Clutch() => new()
|
||||
{
|
||||
Goals = new[]
|
||||
{
|
||||
new GoalSpec
|
||||
{
|
||||
Id = "rest", Priority = 0.0,
|
||||
Behaviour = new PoseBehaviour { Keys = new[] { Identity() }, FlinchPose = Identity(), Hold = new HoldParameters { HoldStrength = 0.7f } },
|
||||
},
|
||||
new GoalSpec
|
||||
{
|
||||
Id = "clutch", Priority = 1.0, InvoluntarySeconds = double.PositiveInfinity,
|
||||
When = new[] { new Condition(DriveQuantity.AirHunger, ConditionOp.AtLeast, 0.3) },
|
||||
Behaviour = new PoseBehaviour { Keys = new[] { Identity() }, FlinchPose = Identity(), Hold = new HoldParameters { HoldStrength = 1f, FlinchGain = 0.0, StrainShake = 0.0 } },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/// <summary>One knife wound of the fixture's severity at <paramref name="point"/> (the part's frame) and <paramref name="depth"/>, then the real Actor ticked until it dies.</summary>
|
||||
private static Band Cut(string part, Side side, (float X, float Y, float Z) point, double depth)
|
||||
{
|
||||
var p = new Physiology(Body, Plan, 20.0, BloodGain);
|
||||
var a = new Actor(Dt, 1, new NerveParameters(), new WithdrawalParameters(), new DriveParameters(), Clutch(), physiology: p);
|
||||
var pi = Body.PartIndex(part, side);
|
||||
var stack = Plan.Parts.First(s => s.PartLabel == part && s.Side == side);
|
||||
Span<int> layers = stackalloc int[stack.Tissues.Count];
|
||||
var n = stack.Reach(point, depth, layers);
|
||||
Assert.True(p.Afflict(Plan.AfflictionIndex("Cut"), pi, layers[..n], KnifeSeverity));
|
||||
var names = layers[..n].ToArray().Select(i => stack.Tissues[i].Label).ToArray();
|
||||
|
||||
var s = new float[p.JointCount];
|
||||
var q = new Quat[p.JointCount];
|
||||
double deadAt = -1, outAt = -1, oxygen = -1, loss = -1, maxOcc = 0, fullAt = -1;
|
||||
for (long i = 0; i < (long)(600.0 / Dt) && !p.Dead; i++)
|
||||
{
|
||||
a.Tick(NoPoint, NoPoint, NoPoint, default, s, q);
|
||||
var t = (i + 1) * Dt;
|
||||
if (p.Dead) deadAt = t;
|
||||
maxOcc = Math.Max(maxOcc, p.Occlusion);
|
||||
if (fullAt < 0 && p.Occlusion >= 0.99) fullAt = t;
|
||||
if (outAt < 0 && p.Consciousness <= 0.1)
|
||||
{
|
||||
outAt = t;
|
||||
oxygen = p.BrainOxygen;
|
||||
loss = p.BloodLoss;
|
||||
}
|
||||
}
|
||||
|
||||
return new Band(p.Cause, deadAt, outAt, oxygen, loss, maxOcc, fullAt, names);
|
||||
}
|
||||
|
||||
// Shipped readings (deterministic, Release): either carotid and either femoral die of BloodLoss at 29.73 s, out at 16.82 s with brain oxygen 0.995 and no occlusion; the front of the throat
|
||||
// fills the airway at 1.29 s, is out at 83.46 s with brain oxygen 0.371 and blood loss 0.450 and dies of Consciousness at 167.3 s. Mutants measured the same way: VesselV 1.0 dies at 79.35 s;
|
||||
// a carotid with no site (reached at the front of the throat too) at 16.15 s; cough 2.0 fills the airway at 129.95 s, is out at 127.7 s with brain oxygen 0.994 and blood loss 0.6000 and dies of BloodLoss at 380.9 s;
|
||||
// larynx V 1.0 is out at 86.61 s with blood loss 0.6001 (brain oxygen 0.376: the hypoxia bound does not claim it).
|
||||
|
||||
[Theory]
|
||||
[InlineData("Head", Side.Center, 0.0778f, -0.0778f, 0f, "CarotidLeft")]
|
||||
[InlineData("Head", Side.Center, -0.0778f, -0.0778f, 0f, "CarotidRight")]
|
||||
[InlineData("Thigh", Side.Left, -0.0495f, 0.12f, 0.0495f, "Femoral")]
|
||||
[InlineData("Thigh", Side.Right, 0.0495f, 0.12f, 0.0495f, "Femoral")]
|
||||
public void A_vessel_kills_in_about_30_seconds_of_blood_loss_and_does_not_drown(string part, Side side, float x, float y, float z, string vessel)
|
||||
{
|
||||
// Death in [20, 40] s: shipped 29.73 (ruled about 30). VesselV 1.0 reads 79.35 (2.0 x the upper bound), an unsited carotid 16.15 (1.24 x under the lower bound); the shipped reading is 1.35 and 1.49 inside them.
|
||||
// The geometric midpoints (48.6 and 21.9 s) are looser; the ruled band is kept.
|
||||
var r = Cut(part, side, (x, y, z), 0.02);
|
||||
Assert.Contains(vessel, r.Layers);
|
||||
Assert.Equal(DeathCause.BloodLoss, r.Cause);
|
||||
Assert.InRange(r.DeadAt, 20.0, 40.0);
|
||||
Assert.Equal(0.0, r.MaxOcclusion); // no airway tissue reached: exactly zero
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_front_of_the_throat_drowns_him_before_it_bleeds_him_out()
|
||||
{
|
||||
var r = Cut("Head", Side.Center, (0f, -0.0778f, 0.0778f), 0.02);
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Larynx" }, r.Layers); // no carotid at the front
|
||||
// Occlusion full within 5 s: shipped 1.29 s (3.9 x inside), cough 2.0 reads 129.95 s (26 x outside).
|
||||
Assert.InRange(r.OcclusionFullAt, 0.0, 5.0);
|
||||
Assert.True(r.OutAt > 0.0, "he never loses consciousness");
|
||||
// Brain oxygen at consciousness 0.1: shipped 0.371, cough 2.0 0.994; bound sqrt(0.371 x 0.994) = 0.607 (separation 2.7).
|
||||
Assert.True(r.BrainOxygenOut < 0.607, $"brain oxygen {r.BrainOxygenOut}");
|
||||
// Blood loss then: shipped 0.4501, cough 2.0 and larynx V 1.0 0.6000; bound sqrt(0.4501 x 0.6000) = 0.5197 (separation 1.33, ruling deterministic-bound-margin).
|
||||
Assert.True(r.BloodLossOut < 0.5197, $"blood loss {r.BloodLossOut}");
|
||||
Assert.Equal(DeathCause.Consciousness, r.Cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -51,6 +51,80 @@ public sealed class WoundReachTests
|
|||
Assert.Equal(new[] { 0, 1, 2 }, Reach(stack, near, 0.0071));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_sited_tissue_between_shells_is_gated_by_the_shells_before_it_only()
|
||||
{
|
||||
// Skin 2 mm, Fat 5 mm, a vessel sited on the point, Muscle sheet 15 mm, an unsited core: the vessel sits at 7 mm (the shells before it), the core at 22 mm (all of them).
|
||||
var stack = Stack(Shell("Skin", 0.002), Shell("Fat", 0.005), Core("Vessel", new TissueSite((0f, 0f, 0f), 0.01f)), Shell("Muscle", 0.015), Core("Fill"));
|
||||
var p = (0f, 0f, 0f);
|
||||
Assert.Equal(new[] { 0, 1 }, Reach(stack, p, 0.0069)); // kills: gate by nothing
|
||||
Assert.Equal(new[] { 0, 1, 2, 3 }, Reach(stack, p, 0.0071));
|
||||
Assert.Equal(new[] { 0, 1, 2, 3 }, Reach(stack, p, 0.021)); // kills: gate by the total (22 mm)
|
||||
Assert.Equal(new[] { 0, 1, 2, 3, 4 }, Reach(stack, p, 0.0221)); // the unsited core keeps the total
|
||||
// The distance still gates it: the site's surface is 0.04 m from this point.
|
||||
Assert.Equal(new[] { 0, 1, 3 }, Reach(stack, (0f, 0f, 0.05f), 0.021));
|
||||
}
|
||||
|
||||
/// <summary>The rule before vessel sites: every core, sited or not, is gated by the shells' total.</summary>
|
||||
private static int[] ShippedReach(PartTissuesDef stack, (float X, float Y, float Z) point, double depth)
|
||||
{
|
||||
var shells = 0.0;
|
||||
foreach (var t in stack.Tissues) shells += t.Thickness;
|
||||
var hit = new List<int>();
|
||||
var before = 0.0;
|
||||
for (var i = 0; i < stack.Tissues.Count; i++)
|
||||
{
|
||||
var t = stack.Tissues[i];
|
||||
if (t.Thickness > 0.0)
|
||||
{
|
||||
if (depth > before) hit.Add(i);
|
||||
before += t.Thickness;
|
||||
}
|
||||
else if (depth > shells)
|
||||
{
|
||||
if (t.Site is not TissueSite site) hit.Add(i);
|
||||
else
|
||||
{
|
||||
double dx = point.X - site.Centre.X, dy = point.Y - site.Centre.Y, dz = point.Z - site.Centre.Z;
|
||||
if (depth > Math.Sqrt(dx * dx + dy * dy + dz * dz) - site.Radius) hit.Add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hit.ToArray();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Over_the_humanoid_only_the_femoral_sites_differ_from_the_rule_before_vessel_sites()
|
||||
{
|
||||
// Every part, a 9 x 9 x 9 grid of points 4 cm apart about the part's origin, depths 1 to 60 mm: the carotids sit after every shell of the head, so they gate as before; only a Femoral,
|
||||
// listed before the thigh's muscle sheet, may be reached where the total would not.
|
||||
var cases = 0;
|
||||
var femoralGained = 0;
|
||||
foreach (var stack in Humanoid.Parts)
|
||||
{
|
||||
var femoral = stack.PartLabel == "Thigh" ? stack.Tissues.ToList().FindIndex(t => t.Label == "Femoral") : -1;
|
||||
for (var ix = -4; ix <= 4; ix++)
|
||||
for (var iy = -4; iy <= 4; iy++)
|
||||
for (var iz = -4; iz <= 4; iz++)
|
||||
for (var mm = 1; mm <= 60; mm++)
|
||||
{
|
||||
var point = (0.04f * ix, 0.04f * iy, 0.04f * iz);
|
||||
var now = Reach(stack, point, mm / 1000.0);
|
||||
var before = ShippedReach(stack, point, mm / 1000.0);
|
||||
cases++;
|
||||
if (femoral < 0) { Assert.Equal(before, now); continue; }
|
||||
var nowSansFemoral = now.Where(i => i != femoral).ToArray();
|
||||
Assert.Equal(before.Where(i => i != femoral), nowSansFemoral);
|
||||
if (now.Contains(femoral) && !before.Contains(femoral)) femoralGained++;
|
||||
Assert.True(!before.Contains(femoral) || now.Contains(femoral), "a Femoral the old rule reached is lost");
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(cases > 800000, $"{cases} cases");
|
||||
Assert.True(femoralGained > 0, "no Femoral is reached where the shells' total would have gated it");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_depth_exactly_at_a_sites_surface_does_not_reach_it()
|
||||
{
|
||||
|
|
@ -102,8 +176,11 @@ public sealed class WoundReachTests
|
|||
Assert.DoesNotContain("Brain", scalp);
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Skull" }, scalp);
|
||||
Assert.Contains("Brain", Labels("Head", (0f, 0.11f, 0f), 0.04));
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Muscle" }, Labels("Head", (0.0778f, -0.0778f, 0f), 0.02));
|
||||
// The side of the neck reaches a carotid (mirrored left to right), the front of the throat none, the back of the neck neither.
|
||||
Assert.Equal(new[] { "Skin", "Fat", "CarotidLeft", "Muscle" }, Labels("Head", (0.0778f, -0.0778f, 0f), 0.02));
|
||||
Assert.Equal(new[] { "Skin", "Fat", "CarotidRight", "Muscle" }, Labels("Head", (-0.0778f, -0.0778f, 0f), 0.02));
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Muscle" }, Labels("Head", (0f, -0.0778f, -0.0778f), 0.02));
|
||||
Assert.DoesNotContain("CarotidLeft", Labels("Head", (0f, -0.0778f, 0.0778f), 0.04));
|
||||
|
||||
var chest = Labels("Torso", (0.02f, 0.05f, 0.09f), 0.04);
|
||||
Assert.Contains("Heart", chest);
|
||||
|
|
@ -118,6 +195,18 @@ public sealed class WoundReachTests
|
|||
string[] Thigh(double depth) => Reach(thigh, (0.07f, 0f, 0f), depth).Select(i => thigh.Tissues[i].Label).ToArray();
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Muscle" }, Thigh(0.02));
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Muscle", "Femur" }, Thigh(0.03));
|
||||
|
||||
// The femoral vessel is at the inner thigh: -x on the left thigh, +x on the right.
|
||||
string[] ThighOf(Side side, float x, double depth)
|
||||
{
|
||||
var stack = Humanoid.Parts.First(p => p.PartLabel == "Thigh" && p.Side == side);
|
||||
return Reach(stack, (x, 0.12f, 0.0495f), depth).Select(i => stack.Tissues[i].Label).ToArray();
|
||||
}
|
||||
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Femoral", "Muscle" }, ThighOf(Side.Left, -0.0495f, 0.02));
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Femoral", "Muscle" }, ThighOf(Side.Right, 0.0495f, 0.02));
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Muscle" }, ThighOf(Side.Left, 0.0495f, 0.02));
|
||||
Assert.Equal(new[] { "Skin", "Fat", "Muscle" }, ThighOf(Side.Right, -0.0495f, 0.02));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -419,8 +419,10 @@ public sealed class AirwayTests
|
|||
// and pitching back it holds Nose past face down (measured: to -26.3), and each still lands the change inside 40 degrees.
|
||||
var flipUp = Sweep(up, -40f, 40f, 0.05f, Mouth);
|
||||
var flipDown = Sweep(down, 40f, -40f, -0.05f, Nose);
|
||||
Assert.True(flipUp > 0f && flipUp < 40f, $"held Mouth to {flipUp} degrees");
|
||||
Assert.True(flipDown < 0f && flipDown > -40f, $"held Nose to {flipDown} degrees");
|
||||
// The hold is the margin itself (ruling deterministic-bound-margin, readings at 0.05 degree steps): margin 5 mm (shipped) holds Mouth to +10.40 and Nose to -26.35 degrees; 1 mm holds +5.95 and -21.90, 10 mm holds +15.99 and -31.95.
|
||||
// Mouth bound (7.87, 12.9) = sqrt(10.40 x 5.95) and sqrt(10.40 x 15.99), separation 1.75 and 1.54; Nose bound (-29.0, -24.0) = sqrt(26.35 x 31.95) and sqrt(26.35 x 21.90), separation 1.21 and 1.20.
|
||||
Assert.True(flipUp > 7.87f && flipUp < 12.9f, $"held Mouth to {flipUp} degrees");
|
||||
Assert.True(flipDown < -24.0f && flipDown > -29.0f, $"held Nose to {flipDown} degrees");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in a new issue