using System.Globalization;
using System.Numerics;
using System.Text;
using System.Text.Json.Nodes;
namespace RynthNav.TownNet;
///
/// A floor plan of the network as SVG, for looking the walks over: floors (grey, one shade per
/// height), walls and solid objects (dark), portals (blue rings: the reach that uses them), arrival
/// points (green), and the walks from one arrival (or all).
///
internal static class MapSvg
{
public static string Draw(Indoor w, IEnumerable cells, JsonObject doc, string? onlyFrom, float level)
{
var ci = CultureInfo.InvariantCulture;
var cellList = cells.Select(id => w.Cells[id]).Where(c => c.Floors.Any(f => MathF.Abs(f[0].Z - level) < 3f)).ToList();
var all = cellList.SelectMany(c => c.Floors).SelectMany(f => f).ToList();
float minX = all.Min(v => v.X) - 3, maxX = all.Max(v => v.X) + 3, minY = all.Min(v => v.Y) - 3, maxY = all.Max(v => v.Y) + 3;
const float S = 6f; // pixels per metre
string P(float x, float y) => ((x - minX) * S).ToString("F1", ci) + "," + ((maxY - y) * S).ToString("F1", ci);
var sb = new StringBuilder();
sb.Append(ci, $"\n");
return sb.ToString();
}
}