mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 08:19:25 -05:00
On a linear scale topped by the cells at the torch, nearly the whole sheet drew in the coolest blue. Color rises logarithmically from 10 °C to the 99.5th percentile of the cut's peaks, held between 100 and 1000 °C, and label the colors with a bar down the plate view's right edge. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace OpenNest.Desktop.Interaction;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static class HeatColorScale
|
|
{
|
|
/// <summary>Rises up to this, in °C, are not colored.</summary>
|
|
public const float Floor = 10;
|
|
|
|
/// <summary>The least rise the hottest color stands for, so a barely warm plate is not all red.</summary>
|
|
public const float MinTop = 100;
|
|
|
|
/// <summary>The most it stands for; anything hotter gets the same color.</summary>
|
|
public const float MaxTop = 1000;
|
|
|
|
/// <summary>The top of the scale for a cut whose hot areas reach <paramref name="rise"/>.</summary>
|
|
public static float Top(float rise) => rise > MinTop ? MathF.Min(rise, MaxTop) : MinTop;
|
|
|
|
/// <summary>
|
|
/// Where <paramref name="rise"/> falls between the floor (0) and <paramref name="top"/> (1).
|
|
/// </summary>
|
|
public static float Fraction(float rise, float top) =>
|
|
!(rise > Floor) ? 0 : rise >= top ? 1 : MathF.Log(rise / Floor) / MathF.Log(top / Floor);
|
|
|
|
/// <summary>
|
|
/// The rises to label on a scale up to <paramref name="top"/>: the floor, then 1 and 3 times
|
|
/// each power of ten, then the top. A mark crowding the top is left out.
|
|
/// </summary>
|
|
public static IReadOnlyList<float> Ticks(float top)
|
|
{
|
|
var ticks = new List<float> { 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;
|
|
}
|
|
}
|