diff --git a/Assets/Scripts/ServerShared/GravityField.cs b/Assets/Scripts/ServerShared/GravityField.cs index 53c2755a0..71e1f0c2a 100644 --- a/Assets/Scripts/ServerShared/GravityField.cs +++ b/Assets/Scripts/ServerShared/GravityField.cs @@ -11,7 +11,9 @@ using float2 = CultMath.float2; public static class GravityField { // The potential at distance r from the body, defined up to a constant (callers subtract their reference). + // A well of no strength (a body whose curves are unauthored, so c = 0 and R = 0) digs nothing. public static float Potential(float c, float coreRadius, float r) => + c == 0f ? 0f : r < coreRadius ? c * r * r / (2 * coreRadius * coreRadius) : c * (log(r / coreRadius) + .5f); diff --git a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs index fbf68bf79..b86ef459f 100644 --- a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs +++ b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs @@ -184,7 +184,7 @@ public sealed class FloatingBodyTests : IDisposable QualityPriceModifier = new ExponentialLerp() }; var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); - var planets = new PlanetSettings(); + var planets = new PlanetSettings { HeightExaggeration = 10f }; // the tilt reads force / K, which K = 1 would hide var pack = new ZonePack { Radius = 1000 }; WellFixture.Dig(cache, pack, planets, 300, 100); zone = new Zone(items, planets, pack, new GalaxyZone { Name = "Test Zone", Owner = null }, null); diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index e1d6e8606..7111bccb4 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -73,6 +73,24 @@ public sealed class PotentialOwnerTests : IDisposable // The law written out: potential c r^2 / 2R^2 inside the core, c (ln(r / R) + 1/2) beyond. private static float Phi(float c, float core, float r) => r < core ? c * r * r / (2 * core * core) : c * (log(r / core) + .5f); + // A zone whose bodies have no authored gravity curves (most test zones) has no pull and no dip, and no NaN either. + [Fact] + public void BodiesWithNoAuthoredWellPullAndDigNothing() + { + var planets = new PlanetSettings + { + BodyRadius = new ExponentialCurve(), GravityRadius = new ExponentialCurve(), GravityDepth = new ExponentialCurve(), + LightRadius = new ExponentialCurve(), OrbitPeriod = new ExponentialCurve() + }; + var zone = ZoneOf(planets, (100f, float2.zero), (5000f, new float2(200f, 0f))); + foreach (var p in new[] { float2.zero, float2(200f, 0f), float2(37f, -911f), float2(5000f, 5000f) }) + { + Assert.Equal(0f, zone.GetHeight(p)); + Assert.Equal(0f, zone.GetForce(p).x); + Assert.Equal(0f, zone.GetForce(p).y); + } + } + [Fact] public void StrengthFollowsTheAuthoredMassCurve() {