From f9cd0a43bf2eeb42608bd03977297dcdeaa0dce0 Mon Sep 17 00:00:00 2001 From: codex Date: Fri, 7 Aug 2026 09:32:11 +0300 Subject: [PATCH] fix: preserve legacy p-rec-annot elevation quotient formatting --- .../src/PRecAnnot.Core/LegacyElevationFormatter.cs | 7 +++++-- .../ElevationAnnotationPlannerTests.cs | 4 ++-- .../PRecAnnot.Core.Tests/LegacyElevationFormatterTests.cs | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/LegacyElevationFormatter.cs b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/LegacyElevationFormatter.cs index d214ac4..954772c 100644 --- a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/LegacyElevationFormatter.cs +++ b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/LegacyElevationFormatter.cs @@ -6,8 +6,11 @@ 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)); + // InsertElevation.BlockJig divides the model-space ordinate by five, + // 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) diff --git a/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ElevationAnnotationPlannerTests.cs b/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ElevationAnnotationPlannerTests.cs index ce80fce..1c2a092 100644 --- a/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ElevationAnnotationPlannerTests.cs +++ b/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ElevationAnnotationPlannerTests.cs @@ -10,7 +10,7 @@ public sealed class ElevationAnnotationPlannerTests { 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 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, value => Assert.Equal(AnnotationOperationKind.Skip, 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())]); Assert.Equal(AnnotationOperationKind.Update, plan.Operations.Single().Kind); - Assert.Equal("+0,015", plan.Operations.Single().Text); + Assert.Equal("+0,003", plan.Operations.Single().Text); } } diff --git a/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/LegacyElevationFormatterTests.cs b/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/LegacyElevationFormatterTests.cs index 65be66c..5cb057b 100644 --- a/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/LegacyElevationFormatterTests.cs +++ b/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/LegacyElevationFormatterTests.cs @@ -7,10 +7,10 @@ public sealed class LegacyElevationFormatterTests [Theory] [InlineData(0, 0, "0,000")] [InlineData(2.49, 0, "0,000")] - [InlineData(2.5, 0, "+0,005")] - [InlineData(-2.5, 0, "-0,005")] - [InlineData(1233, 2, "+1,235")] - [InlineData(-1233, -2, "-1,235")] + [InlineData(2.5, 0, "+0,001")] + [InlineData(-2.5, 0, "-0,001")] + [InlineData(1233, 2, "+0,247")] + [InlineData(-1233, -2, "-0,247")] public void PreservesFiveMillimetreAwayFromZeroLegacyRule(double modelZ, double datum, string expected) => Assert.Equal(expected, LegacyElevationFormatter.Calculate(modelZ, datum));