fix: preserve legacy p-rec-annot elevation quotient formatting

This commit is contained in:
codex
2026-08-07 09:32:11 +03:00
parent a8749ffa69
commit f9cd0a43bf
3 changed files with 11 additions and 8 deletions
@@ -6,8 +6,11 @@ public static class LegacyElevationFormatter
{ {
public static int RoundModelElevation(double modelZ, double datumOffset) public static int RoundModelElevation(double modelZ, double datumOffset)
{ {
var increments = Math.Round((modelZ + datumOffset) / 5d, MidpointRounding.AwayFromZero); // InsertElevation.BlockJig divides the model-space ordinate by five,
return checked((int)Math.Round(increments * 5d, MidpointRounding.AwayFromZero)); // rounds that quotient away from zero, then formats the resulting
// integer as a signed metres/millimetres value. It does not multiply
// the rounded quotient back by five.
return checked((int)Math.Round((modelZ + datumOffset) / 5d, MidpointRounding.AwayFromZero));
} }
public static string FormatMillimetres(int millimetres) public static string FormatMillimetres(int millimetres)
@@ -10,7 +10,7 @@ public sealed class ElevationAnnotationPlannerTests
{ {
var a = new ElevationCandidate("a", 5, 0, new(0, 0), 0, "PXP", "GOSTC"); var a = new ElevationCandidate("a", 5, 0, new(0, 0), 0, "PXP", "GOSTC");
var b = new ElevationCandidate("b", 10, 0, new(1, 0), 0, "PXP", "GOSTC"); var b = new ElevationCandidate("b", 10, 0, new(1, 0), 0, "PXP", "GOSTC");
var plan = new ElevationAnnotationPlanner().Build([b, a, a], [new("old-a", "a", "+0,005", new(0, 0)), new("old-b1", "b", "+0,010", new()), new("old-b2", "b", "+0,010", new())]); var plan = new ElevationAnnotationPlanner().Build([b, a, a], [new("old-a", "a", "+0,001", new(0, 0)), new("old-b1", "b", "+0,002", new()), new("old-b2", "b", "+0,002", new())]);
Assert.Collection(plan.Operations, Assert.Collection(plan.Operations,
value => Assert.Equal(AnnotationOperationKind.Skip, value.Kind), value => Assert.Equal(AnnotationOperationKind.Skip, value.Kind),
value => Assert.Equal(AnnotationOperationKind.Conflict, value.Kind), value => Assert.Equal(AnnotationOperationKind.Conflict, value.Kind),
@@ -23,6 +23,6 @@ public sealed class ElevationAnnotationPlannerTests
{ {
var plan = new ElevationAnnotationPlanner().Build([new ElevationCandidate("a", 13, 0, new(), 0, "PXP", "GOSTC")], [new("old", "a", "+0,010", new())]); var plan = new ElevationAnnotationPlanner().Build([new ElevationCandidate("a", 13, 0, new(), 0, "PXP", "GOSTC")], [new("old", "a", "+0,010", new())]);
Assert.Equal(AnnotationOperationKind.Update, plan.Operations.Single().Kind); Assert.Equal(AnnotationOperationKind.Update, plan.Operations.Single().Kind);
Assert.Equal("+0,015", plan.Operations.Single().Text); Assert.Equal("+0,003", plan.Operations.Single().Text);
} }
} }
@@ -7,10 +7,10 @@ public sealed class LegacyElevationFormatterTests
[Theory] [Theory]
[InlineData(0, 0, "0,000")] [InlineData(0, 0, "0,000")]
[InlineData(2.49, 0, "0,000")] [InlineData(2.49, 0, "0,000")]
[InlineData(2.5, 0, "+0,005")] [InlineData(2.5, 0, "+0,001")]
[InlineData(-2.5, 0, "-0,005")] [InlineData(-2.5, 0, "-0,001")]
[InlineData(1233, 2, "+1,235")] [InlineData(1233, 2, "+0,247")]
[InlineData(-1233, -2, "-1,235")] [InlineData(-1233, -2, "-0,247")]
public void PreservesFiveMillimetreAwayFromZeroLegacyRule(double modelZ, double datum, string expected) => public void PreservesFiveMillimetreAwayFromZeroLegacyRule(double modelZ, double datum, string expected) =>
Assert.Equal(expected, LegacyElevationFormatter.Calculate(modelZ, datum)); Assert.Equal(expected, LegacyElevationFormatter.Calculate(modelZ, datum));