From 586361ad67487fb59cdbf943b32df6e5040c3e9b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 02:07:15 +0100 Subject: [PATCH] SoA grab tests: the angular spring follows the anchor's rotation, and off leaves the body free Co-Authored-By: Claude Sonnet 5.5 --- .../Ymir.Box3D.Soa.Tests/Box3DSoaGrabTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaGrabTests.cs b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaGrabTests.cs index b564c38..4a64904 100644 --- a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaGrabTests.cs +++ b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaGrabTests.cs @@ -48,6 +48,29 @@ public sealed class Box3DSoaGrabTests Assert.Equal(0f, view.Size0[anchor]); // no shape, so no size } + [Fact] + public void The_angular_spring_turns_the_grabbed_body_to_the_anchors_rotation_and_off_leaves_it_free() + { + static float Turned(float angularHertz) + { + using var world = new Box3DSoaWorld(capacity: 3, gravityY: 0f, jointCapacity: 1); + var box = world.AddBox(1, (0f, 5f, 0f), (0.2f, 0.2f, 0.2f), Density); + var anchor = world.AddAnchor(2, (0f, 5f, 0f)); + world.AddMotorJoint(anchor, box, (0f, 5f, 0f), (5f, 0.7f, 1e5f), (angularHertz, 0.7f, 1e5f)); + var view = world.View; + var quarterTurnZ = (0f, 0f, MathF.Sin(MathF.PI / 4), MathF.Cos(MathF.PI / 4)); + for (var i = 0; i < 90; i++) + { + world.SetAnchorTarget(anchor, (0f, 5f, 0f), quarterTurnZ, Dt); + world.Step(Dt); + } + return 2f * MathF.Atan2(view.RotationZ[box], view.RotationW[box]); + } + + Assert.Equal(MathF.PI / 2, Turned(angularHertz: 5f), 0.05f); + Assert.Equal(0f, Turned(angularHertz: 0f), 1e-3f); + } + [Fact] public void A_weak_grab_is_bounded_by_its_max_force() {