GravityField: a well of no strength digs nothing (c = 0, R = 0 gave NaN height)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fde8062931
commit
41e90d0e40
3 changed files with 21 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue