Editor/LinePath.cs
using System;
using System.Collections.Generic;
using Sandbox;

namespace TerrainLines;

internal static class LinePath
{
	internal static IReadOnlyList<Vector3> Build( IReadOnlyList<Vector3> points, IReadOnlyList<bool> corners, float spacing )
	{
		if ( points.Count < 3 ) return points;
		var path = new List<Vector3> { points[0] };
		for ( int i = 1; i < points.Count - 1; i++ )
		{
			if ( corners[i] ) { path.Add( points[i] ); continue; }
			// Round freehand joins with local quadratic curves. Clicked bends remain exact.
			var a = (points[i - 1] + points[i]) * 0.5f;
			var b = points[i];
			var c = (points[i] + points[i + 1]) * 0.5f;
			path.Add( a );
			int count = Math.Max( 2, (int)MathF.Ceiling( (LineRaster.Distance2D( a, b ) + LineRaster.Distance2D( b, c )) / spacing ) );
			for ( int step = 1; step <= count; step++ )
			{
				float t = (float)step / count;
				path.Add( a * ((1 - t) * (1 - t)) + b * (2 * (1 - t) * t) + c * (t * t) );
			}
		}
		path.Add( points[^1] );
		return path;
	}
}