Files
Rail_Enterprise/tests/ViaFerrea.Tests/Rail/SyntheticTerrain.cs
T
Claude 259e6ab65f F2: pianificatore dei binari, profilo altimetrico e scenario Valdoria
- TrackGeometry: polilinea raccordata con il raggio della classe
- TrackPlanner: campioni ogni 25 m, due passate di pendenza, smussatura,
  franchi sui fiumi, classificazione delle opere, costi, giorni, vincoli
  per era (campate per classe di fiume, lunghezza delle gallerie)
- Scenari a mano (ScenarioLoader) e tests/scenarios/valdoria.json
- viaferrea-tools profile; industrie al prezzo globale; servizi di base

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
2026-10-01 22:54:57 +00:00

45 lines
1.9 KiB
C#

using ViaFerrea.Core.Map;
namespace ViaFerrea.Tests.Rail;
/// <summary>Terreni costruiti a mano per i test del pianificatore (celle da 100 m).</summary>
public static class SyntheticTerrain
{
public static Terrain Build(int width, int height, Func<double, double, double> heightAtMeters, Func<int, int, CellType>? type = null)
{
var t = new Terrain(width, height, 100, 64);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
double hx = (x + 0.5) * 100, hy = (y + 0.5) * 100;
t.Heights[t.Index(x, y)] = Terrain.ToDecimeters(heightAtMeters(hx, hy));
t.Types[t.Index(x, y)] = (byte)(type?.Invoke(x, y) ?? CellType.Plain);
}
}
return t;
}
public static Terrain Flat(int size = 60, double h = 100) => Build(size, size, (_, _) => h);
/// <summary>Collina a cupola centrata in (cx, cy) metri.</summary>
public static Func<double, double, double> Hill(double cx, double cy, double radiusM, double heightM, double baseM = 100) =>
(x, y) =>
{
double r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy)) / radiusM;
return baseM + (r >= 1 ? 0 : heightM * (1 - r * r) * (1 - r * r));
};
/// <summary>Pianura con un fiume nord-sud largo «widthCells» celle intorno a x = riverX metri.</summary>
public static Terrain River(int size, double riverXm, int widthCells, double baseM = 100, double waterM = 96)
{
int x0 = (int)(riverXm / 100) - widthCells / 2;
var t = Build(size, size, (x, _) => (int)(x / 100) >= x0 && (int)(x / 100) < x0 + widthCells ? waterM : baseM,
(x, _) => x >= x0 && x < x0 + widthCells ? CellType.Water : CellType.Plain);
for (int y = 0; y < size; y++)
for (int x = x0; x < x0 + widthCells; x++)
t.RiverWidth[t.Index(x, y)] = (byte)Math.Min(4, widthCells);
return t;
}
}