Editor/Roof/ArchRoofAnswers.cs

Editor class that implements IArchHeadroom. It checks whether any roofs in an ArchPlan overlap a given footprint at or above a specified level and returns the highest roof top found.

File Access
namespace Sunless.Architecture;

public sealed class ArchRoofHeadroom : IArchHeadroom
{
	public bool Over( ArchPlan plan, ArchKit kit, int level, IReadOnlyList<Vector2> footprint, out float top )
	{
		top = 0f;

		var found = false;

		foreach ( var building in plan.Buildings )
		{
			foreach ( var roof in building.Roofs.Where( roof => roof.Level >= level ) )
			{
				if ( !ArchFootprint.Overlaps( roof.Outline(), footprint ) )
				{
					continue;
				}

				var peak = ArchRoofPlane.Peak( roof ) + (roof.Thickness > 0f ? roof.Thickness : kit.RoofThickness);

				top = found ? MathF.Max( top, peak ) : peak;
				found = true;
			}
		}

		return found;
	}
}