Editor/Output/ArchShot.Format.cs

Editor utility methods for the ArchShot tool. Provides Step to choose a snapping/grid unit given a span, Snap to round a value up to that step, and Say to format a Vector3 as a short string.

File Access
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox;

namespace Sunless.Architecture;

public static partial class ArchShot
{
	// Feet to room scale, then metres - the units the kit and palette are authored in.
	static float Step( float span )
	{
		var candidates = new[] { 1f, 2f, 3f, 6f, 12f, 24f, 36f, MetresToInches, MetresToInches * 2f, MetresToInches * 5f, MetresToInches * 10f, MetresToInches * 25f };

		foreach ( var candidate in candidates )
		{
			if ( span / candidate <= 14f )
			{
				return candidate;
			}
		}

		return MetresToInches * 50f;
	}

	static float Snap( float value, float step ) => MathF.Ceiling( value / step ) * step;

	static string Say( Vector3 point ) => $"({point.x:0.#}, {point.y:0.#}, {point.z:0.#})";
}