Code/Brush/TileBrushFootprint.cs

The class provides a method to generate coordinates for a tile brush based on a specified diameter.

using System;
using System.Collections.Generic;

namespace Saandy.Tilemapper;

/// <summary>The same cell mask is used for painting, erasing and the editor preview.</summary>
public static class TileBrushFootprint
{
	public static IEnumerable<Vector2Int> Offsets( int diameter )
	{
		diameter = Math.Clamp( diameter, 1, 9 );
		int origin = (diameter - 1) / 2;
		float center = (diameter - 1) * 0.5f;
		float radius = diameter * 0.5f;
		for ( int y = 0; y < diameter; y++ )
		for ( int x = 0; x < diameter; x++ )
		{
			float dx = x - center, dy = y - center;
			if ( diameter <= 3 || dx * dx + dy * dy <= radius * radius )
				yield return new Vector2Int( x - origin, y - origin );
		}
	}
}