Editor/Pillar/ArchPillarSeat.cs
using System;
using Sandbox;

namespace Sunless.Architecture;

public static class ArchPillarSeat {
	public const float Clear = 8f;

	// Highest surface under the ceiling — bounded by soffit, not storey
	public static float Under( ArchPlan plan, ArchBuilding building, ArchKit kit, ArchGround ground, Vector2 at, float datum, float ceiling ) {
		if ( Poured( plan, kit, at, ceiling ) is { } seat ) {
			return seat;
		}

		// On grade, not embedded — FootingBuried already buries the footing itself
		var lift = plan is null || building is null ? 0f : ArchAsks.Lift( plan, building, kit );

		return ground.Under( at, datum + lift ) - lift;
	}

	// Highest poured surface under the ceiling at this point
	public static float? Poured( ArchPlan plan, ArchKit kit, Vector2 at, float ceiling ) {
		return ArchContacts.Under( plan, kit, ArchReach.Anywhere, at, ceiling );
	}

	public static float Sunk( ArchKit kit, ArchPillarPart part ) {
		return MathF.Max( kit?.FloorThickness ?? 0f, MathF.Max( 0f, part.FootingBuried ) ) + Clear;
	}
}