feat: port p-rec-annot elevation formatting foundation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace PRecAnnot.Core;
|
||||
|
||||
public static class LegacyElevationFormatter
|
||||
{
|
||||
public static int RoundModelElevation(double modelZ, double datumOffset)
|
||||
{
|
||||
var increments = Math.Round((modelZ + datumOffset) / 5d, MidpointRounding.AwayFromZero);
|
||||
return checked((int)Math.Round(increments * 5d, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
public static string FormatMillimetres(int millimetres)
|
||||
{
|
||||
if (millimetres == 0) return "0,000";
|
||||
var magnitude = Math.Abs((long)millimetres).ToString(CultureInfo.InvariantCulture).PadLeft(4, '0');
|
||||
var metres = magnitude[..^3];
|
||||
var fraction = magnitude[^3..];
|
||||
return $"{(millimetres > 0 ? "+" : "-")}{metres},{fraction}";
|
||||
}
|
||||
|
||||
public static string Calculate(double modelZ, double datumOffset) => FormatMillimetres(RoundModelElevation(modelZ, datumOffset));
|
||||
}
|
||||
Reference in New Issue
Block a user