From a28318ccbbbc04a4656e912257883c6c836db065 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 24 Nov 2026 21:43:20 +0100 Subject: [PATCH] tests, docs: restore the sheet (5 s, 5%) and attached-end (1e-4 m) bounds, momentum floor comment, islands in soa-world.md h2's loosened bounds are reverted. Momentum stays at 5e-4 with the measured float32 reason. The corner-group sheet is read at 8 s (it still rings at 5 s: 1.10% under at 5 s, within 0.2% from 6 s). Docs describe islands, the parent gate, geodesic bounds, the pair rule and counts, and drop the nearest-only text. Co-Authored-By: Claude Opus 5.5 --- docs/soa-world.md | 38 ++++++++++++------- .../Box3DSoaCouplingTests.cs | 4 +- .../Box3DSoaParticleTests.cs | 8 ++-- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/docs/soa-world.md b/docs/soa-world.md index faf4660..8755a13 100644 --- a/docs/soa-world.md +++ b/docs/soa-world.md @@ -123,15 +123,24 @@ separate native object (`ymir_box3d_soa.c`, ABI 10) so the Aetheria session's co the bends over it with it. Ymir never removes a constraint or releases an attachment on a load: tear, cut, gib and release are the caller's say-so. - Derivation. Every topology command ends in the one `rederive_topology()`, which is the only writer of the tether lanes and - the component lane. It builds the adjacency of the live distances, labels components by their lowest lane, and runs one - multi-source Dijkstra (binary heap, ties by node then edge) over the distances' rest lengths from the particle of every - `TETHER` attachment (Kim 2012): each other particle gets one tether to the attachment it is nearest by the geodesic rest path, - bounded by that path, with the tether of the previous particle on the path and the edge used (parents come before children). - A tie goes to the path through the lower particle lane. So N particles carry about N tethers however many points are - pinned: a 32 x 32 sheet pinned at 20 points had 20650 tethers (3.5 ms per tick) and has about 1000 plus its pairs. Two - `TETHER` attachments on different particles of one component also get a pair tether: the rest path between their particles - bounds the distance between their points (what lets a heavy body be held at 0.1% stretch from a static point: the full excess - moves the body, not only the light end particle). A pair tether sits behind a route of booking lanes (attachment -1, an edge + the component lane. It builds the adjacency of the live distances, labels components by their lowest lane, and then islands + (Kim, Chentanez, Mueller 2012 sec. 3.4): a particle holding a live `TETHER` attachment is a tether particle, and an island is + a maximal set of tether particles joined by live distances, named by its lowest `TETHER` attachment. For each island, in lane + order, one Dijkstra (binary heap, ties by node then edge) over the distances' rest lengths runs from all its tether particles; + another island's tether particle is settled but not expanded. Each particle that is not a tether particle keeps the two + nearest islands by rest path (an equal path keeps the lower island) and gets one tether to the nearest point of each, bounded + by that geodesic path (not the Euclidean rest distance: 0.23% on a flat two-corner sheet, but a coiled rope could never uncoil under + it, and the graph has no surface to say when it holds), with the tether of the previous particle on the path and the edge used (parents come before children). Ranking + attachments instead of islands fails when a corner is held by adjacent pins (two corners of two pins stretch 11.6% at 5 s by + the two nearest attachments, 2.4% by islands); one island per particle (nearest only) stretched 16.4%, and Kim's typical four + islands buy 1.66% against 1.72% on a 20-pin sheet for twice the lanes, so the count is `YMIR_TETHER_ISLANDS` = 2. Float32 + path sums can break the exact-arithmetic closure of the rankings at a tie (a particle keeps an island its parent dropped), so + a tether is written only when its parent particle is a source or holds a tether to the same island: a gated particle keeps + one tether. So N particles carry at most 2N tethers however many points are pinned: a 32 x 32 sheet pinned at 20 points had + 20650 tethers (3.5 ms per tick) and has 2008. Two `TETHER` attachments on different particles of one component, at least one + on a body, also get a pair tether: the rest path between their particles bounds the distance between their points (what lets + a heavy body be held at 0.1% stretch from a static point: the full excess moves the body, not only the light end particle). + Two static points never move, so their pair has no end to pull and is not derived. A pair tether sits behind a route of booking lanes (attachment -1, an edge and a parent, no bound of their own) along that path, so the tension sensors read its load on the edges it crossed; pairs cost O(A^2) lanes and a derivation runs one more Dijkstra per tether point that has a later partner. Hold a heavy body with `TETHER` at both ends: with the tether on one end only a 70 kg body hung from a 48-particle rope sinks 0.25 m below its @@ -188,7 +197,7 @@ of sqrt(2gh), point and normal), lifting gives one end, dropped counters resetti hits, facts lasting one step, overflow counted, per-step byte determinism of facts and contact lanes, and no allocation across 100 steps with fact reads. `Box3DSoaImpulseTests`: `contact_impulse` and the hit `impulse` equal the momentum change of the bodies the contact acted on, plus their weight, within 1e-4 of the peak at every step: a 5 kg ball and a 0.3 g BB at 100 m/s onto a jointed forearm (the BB reads 0.030 N s, the ball over 400 times more), the arm falling forearm-first onto a slab, a sphere dropped 1.4 m at 60 and 240 Hz, 1 and 4 sub-steps, restitution 0 and 0.5, two free bodies at restitution 0 and 0.5; a swung arm into a slab, a big sphere with 60 small ones converging (more contacts than graph colours, so the scalar overflow solver runs: the big lane is the sum of the small lanes, each equal to its own momentum change), and at rest `contact_impulse / dt` is the weight (0.1%, a lone sphere) while a body touching nothing reads 0. -`Box3DSoaParticleTests`: the ABI 8 scene's six checkpoint hashes with no particle capacity (pinned from 5104b17); a 48-particle rope (a builder in the tests: distances and soft bends) hanging from a tethered static point under 1% stretch for 4 s; a 70 kg sphere held by the same rope (from 1 s to 5 s speed under 0.001 m/s, stretch under 0.1%, the impulse per tick within 0.5% of m g dt); an anchor dragging a 5 kg box along the floor (`particle_impulse` reads it); a sphere, capsule, box and static box each pushed into a lying rope's end (no particle over 10% of its radius inside); a 16 x 16 sheet from the same two commands hung by two corners (after 20 s the corners carry the weight within 1% and no edge is past 40%); edge tension, the edge at 0, 10 and 46 and both attachment forces read the load at 1, 5, 20 and 70 kg; a cut (remove an edge of a hung 40-rope: the bends over it die, tethers 39 -> 19, the component splits, the head holds and the tail falls); overload (300 kg) removes nothing; destroying a mid-rope particle removes its constraints and releases a held body; a 24-particle cantilever at 32 substeps under a 30 and a 10 degree hard limit and a stiff and a floppy soft pass, and a limit-only bend bit-identical to no bend inside its cone; momentum of a rope, a sheet and a blob thrown into each other with no gravity within 5e-4 and energy never rising; phase rules (groups, `SELF_COLLIDE`, `SELF_FILTER`, a folded rope); an off-centre attachment spinning a free box by I^-1 (r x J) within 2%; lanes reused after a step lowest first, stale generations refused, a derivation that does not fit refused with no lane changed, bad input refused; a pile of four ropes and a sheet on two bodies byte-equal across two runs at six checkpoints (pinned), a one-ulp difference diverging, and eight concurrent worlds giving the serial bytes; no allocation across 100 steps and across a cut, a destroy and a create, and none for a 300-distance batch created and removed; gravity along each axis; a spinning box carrying its attachment point and two ends on one light box settling (the proxy's rotation); one group's `SELF_COLLIDE` needing both particles and `SELF_FILTER` either; a slack pair tether leaving its body alone; a refused `attach` leaving no lane and no tether; each particle on its nearer tether point and a tie on the lower lane; a particle held by two bodies touching neither. `Box3DSoaParticleSourceTests` reads the C source: no Box3D call in `ymir_particles.*`, no allocation outside create and free, no threads or atomics, no rope, sheet, cloth or chain identifier in the solver or the binding, the tether and component lanes written only by the derivation, every topology command ending in it, `begin` and `end` called once (in the step), `substep` once (in the callback), the callback the only user of the fork's two accessors, no topology change in the phases, and the retired names absent. +`Box3DSoaParticleTests`: the ABI 8 scene's six checkpoint hashes with no particle capacity (pinned from 5104b17); a 48-particle rope (a builder in the tests: distances and soft bends) hanging from a tethered static point under 1% stretch for 4 s; a 70 kg sphere held by the same rope (from 1 s to 5 s speed under 0.001 m/s, stretch under 0.1%, the impulse per tick within 0.5% of m g dt); an anchor dragging a 5 kg box along the floor (`particle_impulse` reads it); a sphere, capsule, box and static box each pushed into a lying rope's end (no particle over 10% of its radius inside); a 16 x 16 sheet from the same two commands hung by two corners (after 5 s the corners carry the weight within 1% and no edge is past 5%), and by two corners of two pins each (after 8 s, same bounds: it still rings at 5 s); edge tension, the edge at 0, 10 and 46 and both attachment forces read the load at 1, 5, 20 and 70 kg; a cut (remove an edge of a hung 40-rope: the bends over it die, tethers 39 -> 19, the component splits, the head holds and the tail falls); overload (300 kg) removes nothing; destroying a mid-rope particle removes its constraints and releases a held body; a 24-particle cantilever at 32 substeps under a 30 and a 10 degree hard limit and a stiff and a floppy soft pass, and a limit-only bend bit-identical to no bend inside its cone; momentum of a rope, a sheet and a blob thrown into each other with no gravity within 5e-4 and energy never rising; phase rules (groups, `SELF_COLLIDE`, `SELF_FILTER`, a folded rope); an off-centre attachment spinning a free box by I^-1 (r x J) within 2%; lanes reused after a step lowest first, stale generations refused, a derivation that does not fit refused with no lane changed, bad input refused; a pile of four ropes and a sheet on two bodies byte-equal across two runs at six checkpoints (pinned), a one-ulp difference diverging, and eight concurrent worlds giving the serial bytes; no allocation across 100 steps and across a cut, a destroy and a create, and none for a 300-distance batch created and removed; gravity along each axis; a spinning box carrying its attachment point and two ends on one light box settling (the proxy's rotation); one group's `SELF_COLLIDE` needing both particles and `SELF_FILTER` either; a slack pair tether leaving its body alone; a refused `attach` leaving no lane and no tether; each particle on the nearest point of its two nearest islands (a 5-rope held at both ends, a star whose centre keeps the two nearer arms, a 9-rope with two touching points counting as one island) and no pair between two static points; a particle held by two bodies touching neither. `Box3DSoaParticleSourceTests` reads the C source: no Box3D call in `ymir_particles.*`, no allocation outside create and free, no threads or atomics, no rope, sheet, cloth or chain identifier in the solver or the binding, the tether and component lanes written only by the derivation, every topology command ending in it, `begin` and `end` called once (in the step), `substep` once (in the callback), the callback the only user of the fork's two accessors, no topology change in the phases, and the retired names absent. `Box3DSoaCouplingTests`: a sphere thrown at 5 m/s with a 48 x 20 g rope from rest keeps x momentum within 0.1% and gains no energy, at 5 and 70 kg; thrown up it reaches the apex momentum allows; 5 kg snapping a taut rope at 6 m/s keeps at most 5% of its energy and 70 kg is still within a tick; a 45 degree pendulum for 12 s gains no energy and loses at most 1.25 times a heavy-particle control, and a hung body keeps its spin about the vertical; removing the body attachment or destroying the rope's particles frees a held 70 kg body in the step after, with no upward impulse; `particle_impulse` equals M dv minus M g dt every tick, hung and thrown; material friction 0.6 holds a rope on a 20 degree slope and friction 0 does not; no particle is farther from a tethered point than its rest path; an attached end stays on its body point; a world whose only body is static still steps the particles (a dropped rope falls g t^2 / 2 within 2%) and rests; and a cost line with 16 ropes x 48 and one 16 x 16 sheet at 4 substeps, one body and forty (printed, not asserted). @@ -210,10 +219,11 @@ largest deflection of one joint: a 10 degree limit allows 21.7 degrees at 4 subs 32.0 at 32 under a 5 kg tip; a 30 degree limit allows 31.5 at 4, 33.8 at 8 and 29.9 at 32 under a 5 kg tip. A soft bend is no stiffer than a floppy one at 4 or 8 substeps (tip drop with no load, stiff 1e-7 against floppy 1e-4: 0.764 m against 0.779 at 4, 0.835 against 0.822 at 8, 0.053 against 0.798 at 32 where it reads as pinned). Read a bend limit as a guide below about 32 substeps and -not at all under a heavy tip. A tether holds each particle to its nearest tether point only, so the edge where two points' regions -meet carries the slack: a 16 x 16 sheet hung by two corners stretches its worst edge 33% (3% when every particle was tethered to -both) and rings for about 15 s before the corners carry its weight within 1%. Pair contact -conserves momentum to float32 rounding of the positions, which grows with the particle mass ratio (0.6% at 30:1, 6% at 100:1). +not at all under a heavy tip. A 16 x 16 sheet hung by two corners rings for about 9 s before the corners carry its weight within 1% +(by two corners of two pins each, about 6 s). Pair contact +conserves momentum to float32 rounding of the positions, which grows with the particle mass ratio (0.6% at 30:1, 6% at 100:1); +the momentum test's 5e-4 is that floor, not a contact property: translating the whole scene moves its drift between 0.56e-4 and +4.0e-4 under either contact walk, and the per-particle-average mutant reads 5.6e-2. Determinism under MSVC's `/fp:precise` is unbuilt (no `cl` on the workstation). diff --git a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaCouplingTests.cs b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaCouplingTests.cs index d49d948..fee3b0a 100644 --- a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaCouplingTests.cs +++ b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaCouplingTests.cs @@ -76,7 +76,7 @@ public sealed class Box3DSoaCouplingTests [Fact] public void Attached_end_stays_on_its_point() { - // The end particle is tied to the sphere's top and skips that sphere in contact. A contact that pushed it off its own body would read as a gap of its radius (12 mm); the pair tether between the rope's two held ends keeps 0.5 mm of it at rest, so the bound is 1 mm. + // The end particle is tied to the sphere's top and skips that sphere in contact. A contact that pushed it off its own body would read as a gap of its radius (12 mm). using var world = World(); var (sphere, _, _, _) = Hung(world, 1f); var view = world.View; @@ -94,7 +94,7 @@ public sealed class Box3DSoaCouplingTests worst = MathF.Max(worst, MathF.Sqrt(Sq(view.ParticleX[47] - px) + Sq(view.ParticleY[47] - py) + Sq(view.ParticleZ[47] - pz))); } Reading($"ATTACHED_END worst gap {F(worst)} m"); - Assert.True(worst < 1e-3f, $"the end particle sat {worst} m from its body point"); + Assert.True(worst < 1e-4f, $"the end particle sat {worst} m from its body point"); } [Fact] diff --git a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs index 0919c89..029725c 100644 --- a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs +++ b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs @@ -228,7 +228,7 @@ public sealed class Box3DSoaParticleTests world.Attach(Box3DSoaAttachKind.Static, sheet.Particles[0], point: (0f, 2f, 0f), tether: true); world.Attach(Box3DSoaAttachKind.Static, sheet.Particles[15], point: (15 * sp, 2f, 0f), tether: true); var view = world.View; - Run(world, 20 * 120); // a tether holds each particle to its nearest corner only, so the sheet rings for ~15 s before it carries its weight + Run(world, 5 * 120); double fy = 0; for (var a = 0; a < 2; a++) fy += view.AttachmentForceY[a]; var weight = 256 * ParticleMass * 10.0; @@ -237,7 +237,7 @@ public sealed class Box3DSoaParticleTests var maxStretch = 0f; foreach (var e in sheet.Edges) maxStretch = MathF.Max(maxStretch, MathF.Abs(Graph.Dist(view, view.DistanceA[e.Lane], view.DistanceB[e.Lane]) / view.DistanceRest[e.Lane] - 1f)); Readings.Add($"SHEET max edge stretch {maxStretch:P3}"); - Assert.True(maxStretch < 0.4f, $"an edge stretched by {maxStretch}"); // the edge where two corners' nearest tethers meet carries the slack: 33% here, 3% when every particle was tethered to both corners + Assert.True(maxStretch < 0.05f, $"an edge stretched by {maxStretch}"); } [Theory] @@ -403,7 +403,9 @@ public sealed class Box3DSoaParticleTests public void Contact_conserves_momentum() { // Zero gravity: a self-colliding rope thrown at 3 m/s into a self-colliding sheet and a loose blob; the sum of momentum - // may not drift and the kinetic energy may not rise (a per-particle average of contacts fails both). + // may not drift and the kinetic energy may not rise (a per-particle average of contacts fails both: it drifts by 5.6e-2). + // 5e-4 is the float32 floor, not a contact property: translating the whole scene moves the position noise between + // 0.56e-4 and 4.0e-4 under both contact walks. using var world = World(particles: 512, distances: 512, bends: 512, tethers: 8, gravityY: 0f); world.AddStaticBox(1, (0f, -100f, 0f), (1f, 1f, 1f)); var sheet = Graph.Sheet(world, (0f, 0f, 0f), (0.04f, 0f, 0f), (0f, 0.04f, 0f), 12, 12, ParticleMass, 0.02f, Box3DSoaPhase.Of(7, true, true));