using System.Globalization; namespace PrivaPub.Domain.Media { // A focal point as Mastodon's API takes it ("x,y", each within -1..1): finite numbers only, clamped to the frame. A NaN // once stored here made every status, timeline and Note holding the post fail to serialise, for every viewer. public static class FocalPoint { public static float[] Parse(string value) { if (value?.Split(',') is not [var x, var y] || !float.TryParse(x, NumberStyles.Float, CultureInfo.InvariantCulture, out var fx) || !float.IsFinite(fx) || !float.TryParse(y, NumberStyles.Float, CultureInfo.InvariantCulture, out var fy) || !float.IsFinite(fy)) return default; return [Math.Clamp(fx, -1, 1), Math.Clamp(fy, -1, 1)]; } /// Whether a stored focal point can be written out: two finite numbers. public static bool IsSound(float[] focus) => focus is [var x, var y] && float.IsFinite(x) && float.IsFinite(y); } }