using System; using System.Collections.Generic; namespace OpenNest.Desktop.Interaction; /// /// The heat layer's logarithmic color scale. Most of a sheet sits tens to a few hundred degrees /// above ambient while the cells at the torch reach thousands, so a linear scale leaves nearly /// everything the coolest color. /// public static class HeatColorScale { /// Rises up to this, in °C, are not colored. public const float Floor = 10; /// The least rise the hottest color stands for, so a barely warm plate is not all red. public const float MinTop = 100; /// The most it stands for; anything hotter gets the same color. public const float MaxTop = 1000; /// The top of the scale for a cut whose hot areas reach . public static float Top(float rise) => rise > MinTop ? MathF.Min(rise, MaxTop) : MinTop; /// /// Where falls between the floor (0) and (1). /// public static float Fraction(float rise, float top) => !(rise > Floor) ? 0 : rise >= top ? 1 : MathF.Log(rise / Floor) / MathF.Log(top / Floor); /// /// The rises to label on a scale up to : the floor, then 1 and 3 times /// each power of ten, then the top. A mark crowding the top is left out. /// public static IReadOnlyList Ticks(float top) { var ticks = new List { Floor }; for (var decade = Floor; decade < top; decade *= 10) { foreach (var tick in new[] { decade, 3 * decade }) { if (tick > Floor && Fraction(tick, top) < 0.9f) ticks.Add(tick); } } ticks.Add(top); return ticks; } }