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:
Meta Vens 2026-10-15 05:02:48 +02:00
commit 41e90d0e40
3 changed files with 21 additions and 1 deletions

View file

@ -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);