From a178eb5eccb6b8c7721a3a0fb41a7fe7057f6442 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 29 Aug 2023 09:39:50 +0100 Subject: [PATCH 1/9] Full circles Full circles with radius and centre: `;Arc centre N051.29.02.000 W000.36.14.000 radius 1.25` --- .../Input/AbstractSectorDataReader.cs | 13 ++++- src/Compiler/Input/SectorDataFile.cs | 56 ++++++++++++++++++- src/Compiler/Model/Coordinate.cs | 38 +++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Input/AbstractSectorDataReader.cs b/src/Compiler/Input/AbstractSectorDataReader.cs index 656eb074..fd9ebf2d 100644 --- a/src/Compiler/Input/AbstractSectorDataReader.cs +++ b/src/Compiler/Input/AbstractSectorDataReader.cs @@ -15,12 +15,23 @@ public bool IsBlankLine(string line) return line.Trim() == ""; } + /* + * Returns whether or not the line is an arc gen line + */ + public bool IsArcGenLine(string line) { + try { + return line.TrimStart().StartsWith(this.GetCommentDelimiter()) && line.Substring(1, 3) == "Arc"; + } catch (ArgumentOutOfRangeException) { + return false; + } + } + /* * Returns whether or not the line is a comment line */ public bool IsCommentLine(string line) { - return line.TrimStart().StartsWith(this.GetCommentDelimiter()); + return !IsArcGenLine(line) && line.TrimStart().StartsWith(this.GetCommentDelimiter()); } /* diff --git a/src/Compiler/Input/SectorDataFile.cs b/src/Compiler/Input/SectorDataFile.cs index ca154967..6e62f3a3 100644 --- a/src/Compiler/Input/SectorDataFile.cs +++ b/src/Compiler/Input/SectorDataFile.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using Compiler.Model; @@ -39,6 +40,59 @@ public override IEnumerator GetEnumerator() { docblock.AddLine(reader.GetCommentSegment(line)); } + else if (reader.IsArcGenLine(line)) { + // Return new SectorData for each new region + + const int DELTA_THETA = 5; + + System.Console.WriteLine(line); + + string[] blocks = line.Split(' '); + + if (blocks[1] != "centre" || blocks[4] != "radius") { + throw new System.Exception("Invalid ArcGen Line: " + line); // todo: FIX! + } + + double lat = Coordinate.DegreeMinSecToDecimalDegree(blocks[2]); + double lon = Coordinate.DegreeMinSecToDecimalDegree(blocks[3]); + + float radius = float.Parse(blocks[5]); + + string prevLat = ""; + string prevLon = ""; + + for (int theta = 0; theta <= 360; theta += DELTA_THETA) { + double deltaLat = (radius * Math.Cos(theta * Math.PI / 180)) / 60.0d; + double deltaLon = (radius * Math.Sin(theta * Math.PI / 180)) / 60.0d; + deltaLon /= Math.Cos((lat) * Math.PI / 180); // account for length of nautical mile changing with latitude + + string newLat = Coordinate.DecimalDegreeToDegreeMinSec(lat + deltaLat, true); + string newLon = Coordinate.DecimalDegreeToDegreeMinSec(lon + deltaLon, false); + + if (theta == 0) { + prevLat = newLat; + prevLon = newLon; + continue; + } + + string outLine = $"EGR156 {prevLat} {prevLon} {newLat} {newLon}"; + + prevLat = newLat; + prevLon = newLon; + //System.Console.WriteLine(newLat + "," + newLon); + + // For each new coordinate, yield return it. + + yield return new SectorData( + docblock, + reader.GetCommentSegment(outLine), + reader.GetDataSegments(outLine), + reader.GetRawData(outLine), + new Definition(this.FullPath, this.CurrentLineNumber) // sus + ); + docblock = new Docblock(); + } + } else { yield return new SectorData( diff --git a/src/Compiler/Model/Coordinate.cs b/src/Compiler/Model/Coordinate.cs index 1b8e0289..5245a6b8 100644 --- a/src/Compiler/Model/Coordinate.cs +++ b/src/Compiler/Model/Coordinate.cs @@ -11,6 +11,44 @@ public Coordinate(string latitude, string longitude) this.longitude = longitude; } + public static double DegreeMinSecToDecimalDegree(string latOrLong) { + double output = 0; + string[] sections = latOrLong.Split('.'); + output += int.Parse(sections[0].Substring(1)); + output += int.Parse(sections[1]) / 60.0d; + output += int.Parse(sections[2]) / 3600.0d; + output += int.Parse(sections[3]) / 3600000.0d; + if (sections[0].StartsWith("S") || sections[0].StartsWith("W")) { + output = -output; + } + return output; + } + + public static string DecimalDegreeToDegreeMinSec(double decimalDegree, bool isLat) { + string output = ""; + if (decimalDegree > 0) { + if (isLat) output += "N"; + else output += "E"; + } else { + decimalDegree = -decimalDegree; + if (isLat) output += "S"; + else output += "W"; + } + + output += ((int)decimalDegree).ToString().PadLeft(3, '0') + "."; + decimalDegree = decimalDegree - (int)decimalDegree; + decimalDegree *= 60; + output += ((int)decimalDegree).ToString().PadLeft(2, '0') + "."; + decimalDegree = decimalDegree - (int)decimalDegree; + decimalDegree *= 60; + output += ((int)decimalDegree).ToString().PadLeft(2, '0') + "."; + decimalDegree = decimalDegree - (int)decimalDegree; + decimalDegree *= 1000; + output += ((int)decimalDegree).ToString().PadLeft(3, '0'); + + return output; + } + public override bool Equals(object obj) { return (obj is Coordinate) && From 474a824e471289568e529d5baec1052baf3c0772 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 29 Aug 2023 11:36:37 +0100 Subject: [PATCH 2/9] Switch to regex --- src/Compiler/Input/SectorDataFile.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Input/SectorDataFile.cs b/src/Compiler/Input/SectorDataFile.cs index 6e62f3a3..af44514c 100644 --- a/src/Compiler/Input/SectorDataFile.cs +++ b/src/Compiler/Input/SectorDataFile.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.RegularExpressions; using Compiler.Model; namespace Compiler.Input @@ -47,16 +48,16 @@ public override IEnumerator GetEnumerator() System.Console.WriteLine(line); - string[] blocks = line.Split(' '); + Regex rx = new Regex(@";Arc region (.*) centre ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) radius (\d*(?:\.\d*){0,1})(?: from ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) to ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3})){0,1}", RegexOptions.None); + GroupCollection groups = rx.Match(line).Groups; // error catching! - if (blocks[1] != "centre" || blocks[4] != "radius") { - throw new System.Exception("Invalid ArcGen Line: " + line); // todo: FIX! - } + string regionName = groups[1].Value; + System.Console.WriteLine(groups[1].Value); - double lat = Coordinate.DegreeMinSecToDecimalDegree(blocks[2]); - double lon = Coordinate.DegreeMinSecToDecimalDegree(blocks[3]); + double lat = Coordinate.DegreeMinSecToDecimalDegree(groups[2].Value); + double lon = Coordinate.DegreeMinSecToDecimalDegree(groups[3].Value); - float radius = float.Parse(blocks[5]); + float radius = float.Parse(groups[4].Value); string prevLat = ""; string prevLon = ""; @@ -75,7 +76,7 @@ public override IEnumerator GetEnumerator() continue; } - string outLine = $"EGR156 {prevLat} {prevLon} {newLat} {newLon}"; + string outLine = $"{regionName} {prevLat} {prevLon} {newLat} {newLon}"; prevLat = newLat; prevLon = newLon; From 524822866f0c5dff93083727f7d34728deb15c08 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 29 Aug 2023 13:51:15 +0100 Subject: [PATCH 3/9] all logic implemented --- src/Compiler/Input/SectorDataFile.cs | 70 ++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Input/SectorDataFile.cs b/src/Compiler/Input/SectorDataFile.cs index af44514c..93a9c71a 100644 --- a/src/Compiler/Input/SectorDataFile.cs +++ b/src/Compiler/Input/SectorDataFile.cs @@ -45,6 +45,7 @@ public override IEnumerator GetEnumerator() // Return new SectorData for each new region const int DELTA_THETA = 5; + const double R = 6372.795477598; System.Console.WriteLine(line); @@ -59,10 +60,62 @@ public override IEnumerator GetEnumerator() float radius = float.Parse(groups[4].Value); + int initialTheta = 0; + int finalTheta = 360; + string prevLat = ""; string prevLon = ""; - for (int theta = 0; theta <= 360; theta += DELTA_THETA) { + bool includesFromTo = false; + + if (groups.Count > 5) { // includes a from / to as well + includesFromTo = true; + prevLat = groups[5].Value; + prevLon = groups[6].Value; + + double fromLat = Coordinate.DegreeMinSecToDecimalDegree(groups[5].Value); + double fromLon = Coordinate.DegreeMinSecToDecimalDegree(groups[6].Value); + + double toLat = Coordinate.DegreeMinSecToDecimalDegree(groups[7].Value); + double toLon = Coordinate.DegreeMinSecToDecimalDegree(groups[8].Value); + + // Calculate angle to from / to coordinate + + double fromTheta = Math.Atan2(Math.Cos(fromLat * Math.PI / 180) * Math.Sin((fromLon - lon) * Math.PI / 180), + Math.Cos(lat * Math.PI / 180) * Math.Sin(fromLat * Math.PI / 180) - Math.Sin(lat * Math.PI / 180) * Math.Cos(fromLat * Math.PI / 180) * Math.Cos((fromLon - lon) * Math.PI / 180) + ); + fromTheta = (180 * fromTheta / Math.PI + 360) % 360; + + double toTheta = Math.Atan2(Math.Cos(toLat * Math.PI / 180) * Math.Sin((toLon - lon) * Math.PI / 180), + Math.Cos(lat * Math.PI / 180) * Math.Sin(toLat * Math.PI / 180) - Math.Sin(lat * Math.PI / 180) * Math.Cos(toLat * Math.PI / 180) * Math.Cos((toLon - lon) * Math.PI / 180) + ); + toTheta = (180 * toTheta / Math.PI + 360) % 360; + + initialTheta = (int)Math.Min(fromTheta, toTheta); + finalTheta = (int)Math.Max(fromTheta, toTheta); + + // calculate actual radius + + double fromDist = R * Math.Acos(Math.Sin(lat * Math.PI / 180) * Math.Sin(fromLat * Math.PI / 180) + Math.Cos(lat * Math.PI / 180) * Math.Cos(fromLat * Math.PI / 180) * Math.Cos((lon - fromLon) * Math.PI / 180)); + fromDist = fromDist / 1.852; + double toDist = R * Math.Acos(Math.Sin(lat * Math.PI / 180) * Math.Sin(toLat * Math.PI / 180) + Math.Cos(lat * Math.PI / 180) * Math.Cos(toLat * Math.PI / 180) * Math.Cos((lon - toLon) * Math.PI / 180)); + toDist = toDist / 1.852; + + float meanRadius = (float)Math.Round((fromDist + toDist) / 2, 2); + + if (meanRadius != radius) { + System.Console.WriteLine("RADIUS ERROR REPLACE ME BEFORE RELEASE"); + radius = meanRadius; + } + + + + //System.Console.WriteLine(fromTheta); + //System.Console.WriteLine(toTheta); + //throw new System.Exception(); + } + + for (int theta = initialTheta + 1; theta < finalTheta; theta += DELTA_THETA) { double deltaLat = (radius * Math.Cos(theta * Math.PI / 180)) / 60.0d; double deltaLon = (radius * Math.Sin(theta * Math.PI / 180)) / 60.0d; deltaLon /= Math.Cos((lat) * Math.PI / 180); // account for length of nautical mile changing with latitude @@ -70,7 +123,7 @@ public override IEnumerator GetEnumerator() string newLat = Coordinate.DecimalDegreeToDegreeMinSec(lat + deltaLat, true); string newLon = Coordinate.DecimalDegreeToDegreeMinSec(lon + deltaLon, false); - if (theta == 0) { + if (theta == initialTheta + 1 && !includesFromTo) { prevLat = newLat; prevLon = newLon; continue; @@ -80,7 +133,6 @@ public override IEnumerator GetEnumerator() prevLat = newLat; prevLon = newLon; - //System.Console.WriteLine(newLat + "," + newLon); // For each new coordinate, yield return it. @@ -93,6 +145,18 @@ public override IEnumerator GetEnumerator() ); docblock = new Docblock(); } + + if (includesFromTo) { + string outLine = $"{regionName} {prevLat} {prevLon} {groups[7].Value} {groups[8].Value}"; + yield return new SectorData( + docblock, + reader.GetCommentSegment(outLine), + reader.GetDataSegments(outLine), + reader.GetRawData(outLine), + new Definition(this.FullPath, this.CurrentLineNumber) // sus + ); + docblock = new Docblock(); + } } else { From 87f9445c5d382a4d5606b08b2d10c4e0bdadee6d Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 29 Aug 2023 14:21:42 +0100 Subject: [PATCH 4/9] CoordinateTest --- src/Compiler/Model/Coordinate.cs | 12 +++++++----- tests/CompilerTest/Model/CoordinateTest.cs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Model/Coordinate.cs b/src/Compiler/Model/Coordinate.cs index 5245a6b8..050fc4c0 100644 --- a/src/Compiler/Model/Coordinate.cs +++ b/src/Compiler/Model/Coordinate.cs @@ -1,4 +1,6 @@ -namespace Compiler.Model +using System; + +namespace Compiler.Model { public struct Coordinate { @@ -36,15 +38,15 @@ public static string DecimalDegreeToDegreeMinSec(double decimalDegree, bool isLa } output += ((int)decimalDegree).ToString().PadLeft(3, '0') + "."; - decimalDegree = decimalDegree - (int)decimalDegree; + decimalDegree -= (int)decimalDegree; decimalDegree *= 60; output += ((int)decimalDegree).ToString().PadLeft(2, '0') + "."; - decimalDegree = decimalDegree - (int)decimalDegree; + decimalDegree -= (int)decimalDegree; decimalDegree *= 60; output += ((int)decimalDegree).ToString().PadLeft(2, '0') + "."; - decimalDegree = decimalDegree - (int)decimalDegree; + decimalDegree -= (int)decimalDegree; decimalDegree *= 1000; - output += ((int)decimalDegree).ToString().PadLeft(3, '0'); + output += Math.Round(decimalDegree).ToString().PadLeft(3, '0'); return output; } diff --git a/tests/CompilerTest/Model/CoordinateTest.cs b/tests/CompilerTest/Model/CoordinateTest.cs index c818e70a..453260c5 100644 --- a/tests/CompilerTest/Model/CoordinateTest.cs +++ b/tests/CompilerTest/Model/CoordinateTest.cs @@ -29,5 +29,23 @@ public void TestItRepresentsAsString() { Assert.Equal("abc def", coordinate.ToString()); } + + [Fact] + public void TestDegreeMinSecToDecimalDegree() { + Assert.Equal(54.51555556, Coordinate.DegreeMinSecToDecimalDegree("N054.30.56.000"), 0.00000001); // tolerance for float precision + Assert.Equal(51.26757306, Coordinate.DegreeMinSecToDecimalDegree("N051.16.03.263"), 0.00000001); + Assert.Equal(-23.85944194, Coordinate.DegreeMinSecToDecimalDegree("S023.51.33.991"), 0.00000001); + Assert.Equal(0.52033000, Coordinate.DegreeMinSecToDecimalDegree("E000.31.13.188"), 0.00000001); + Assert.Equal(-3.19839500, Coordinate.DegreeMinSecToDecimalDegree("W003.11.54.222"), 0.00000001); + } + + [Fact] + public void TestDecimalDegreeToDegreeMinSec() { + Assert.Equal("N054.30.56.000", Coordinate.DecimalDegreeToDegreeMinSec(54.51555556, true)); + Assert.Equal("N051.16.03.263", Coordinate.DecimalDegreeToDegreeMinSec(51.26757306, true)); + Assert.Equal("S023.51.33.991", Coordinate.DecimalDegreeToDegreeMinSec(-23.85944194, true)); + Assert.Equal("E000.31.13.188", Coordinate.DecimalDegreeToDegreeMinSec(0.52033000, false)); + Assert.Equal("W003.11.54.222", Coordinate.DecimalDegreeToDegreeMinSec(-3.19839500, false)); + } } } From 961e35518b87ca303455cef477b0f9621c8a0317 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 29 Aug 2023 14:31:00 +0100 Subject: [PATCH 5/9] AbstractSectorDataReaderTests --- .../CompilerTest/Input/EseSectorDataReaderTest.cs | 15 +++++++++++++++ .../CompilerTest/Input/SctSectorDataReaderTest.cs | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/CompilerTest/Input/EseSectorDataReaderTest.cs b/tests/CompilerTest/Input/EseSectorDataReaderTest.cs index e67df2c3..71706dd3 100644 --- a/tests/CompilerTest/Input/EseSectorDataReaderTest.cs +++ b/tests/CompilerTest/Input/EseSectorDataReaderTest.cs @@ -48,6 +48,21 @@ public void ItDetectsACommentLine(string line, bool expected) Assert.Equal(expected, this.reader.IsCommentLine(line)); } + [Fact] + public void ItIgnoresArcGenLineAsComment() { + Assert.False(this.reader.IsCommentLine(";Arc xxx")); + } + + [Fact] + public void ItIgnoresShortComments() { + Assert.False(this.reader.IsArcGenLine(";Ar")); + } + + [Fact] + public void ItRecognisesArcGenLines() { + Assert.True(this.reader.IsArcGenLine(";Arc xxx")); + } + [Theory] [InlineData("abc ;", "")] [InlineData("abc ;comment", "comment")] diff --git a/tests/CompilerTest/Input/SctSectorDataReaderTest.cs b/tests/CompilerTest/Input/SctSectorDataReaderTest.cs index 6cf97a58..c5764432 100644 --- a/tests/CompilerTest/Input/SctSectorDataReaderTest.cs +++ b/tests/CompilerTest/Input/SctSectorDataReaderTest.cs @@ -48,6 +48,21 @@ public void ItDetectsACommentLine(string line, bool expected) Assert.Equal(expected, this.reader.IsCommentLine(line)); } + [Fact] + public void ItIgnoresArcGenLineAsComment() { + Assert.False(this.reader.IsCommentLine(";Arc xxx")); + } + + [Fact] + public void ItIgnoresShortComments() { + Assert.False(this.reader.IsArcGenLine(";Ar")); + } + + [Fact] + public void ItRecognisesArcGenLines() { + Assert.True(this.reader.IsArcGenLine(";Arc xxx")); + } + [Theory] [InlineData("abc ;", "")] [InlineData("abc ;comment", "comment")] From 6cabb4ac005cd10422b88c799657e3ebca26193d Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 29 Aug 2023 15:39:46 +0100 Subject: [PATCH 6/9] ArcGenTest --- src/Compiler/Input/SectorDataFile.cs | 73 +++++++++---------- src/Compiler/Model/Coordinate.cs | 4 +- tests/CompilerTest/CompilerTest.csproj | 9 +++ .../CompilerTest/Input/SectorDataFileTest.cs | 26 ++++++- .../_TestData/SectorDataFile/ArcGenTest.txt | 4 + 5 files changed, 75 insertions(+), 41 deletions(-) create mode 100644 tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt diff --git a/src/Compiler/Input/SectorDataFile.cs b/src/Compiler/Input/SectorDataFile.cs index 93a9c71a..84cd2a79 100644 --- a/src/Compiler/Input/SectorDataFile.cs +++ b/src/Compiler/Input/SectorDataFile.cs @@ -47,13 +47,10 @@ public override IEnumerator GetEnumerator() const int DELTA_THETA = 5; const double R = 6372.795477598; - System.Console.WriteLine(line); - Regex rx = new Regex(@";Arc region (.*) centre ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) radius (\d*(?:\.\d*){0,1})(?: from ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) to ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3})){0,1}", RegexOptions.None); GroupCollection groups = rx.Match(line).Groups; // error catching! string regionName = groups[1].Value; - System.Console.WriteLine(groups[1].Value); double lat = Coordinate.DegreeMinSecToDecimalDegree(groups[2].Value); double lon = Coordinate.DegreeMinSecToDecimalDegree(groups[3].Value); @@ -68,54 +65,52 @@ public override IEnumerator GetEnumerator() bool includesFromTo = false; - if (groups.Count > 5) { // includes a from / to as well - includesFromTo = true; - prevLat = groups[5].Value; - prevLon = groups[6].Value; - - double fromLat = Coordinate.DegreeMinSecToDecimalDegree(groups[5].Value); - double fromLon = Coordinate.DegreeMinSecToDecimalDegree(groups[6].Value); + if (groups.Count > 5) { // includes a from / to as + if (groups[5].Value.Length > 0) { + includesFromTo = true; + prevLat = groups[5].Value; + prevLon = groups[6].Value; - double toLat = Coordinate.DegreeMinSecToDecimalDegree(groups[7].Value); - double toLon = Coordinate.DegreeMinSecToDecimalDegree(groups[8].Value); + double fromLat = Coordinate.DegreeMinSecToDecimalDegree(groups[5].Value); + double fromLon = Coordinate.DegreeMinSecToDecimalDegree(groups[6].Value); - // Calculate angle to from / to coordinate + double toLat = Coordinate.DegreeMinSecToDecimalDegree(groups[7].Value); + double toLon = Coordinate.DegreeMinSecToDecimalDegree(groups[8].Value); - double fromTheta = Math.Atan2(Math.Cos(fromLat * Math.PI / 180) * Math.Sin((fromLon - lon) * Math.PI / 180), - Math.Cos(lat * Math.PI / 180) * Math.Sin(fromLat * Math.PI / 180) - Math.Sin(lat * Math.PI / 180) * Math.Cos(fromLat * Math.PI / 180) * Math.Cos((fromLon - lon) * Math.PI / 180) - ); - fromTheta = (180 * fromTheta / Math.PI + 360) % 360; + // Calculate angle to from / to coordinate - double toTheta = Math.Atan2(Math.Cos(toLat * Math.PI / 180) * Math.Sin((toLon - lon) * Math.PI / 180), - Math.Cos(lat * Math.PI / 180) * Math.Sin(toLat * Math.PI / 180) - Math.Sin(lat * Math.PI / 180) * Math.Cos(toLat * Math.PI / 180) * Math.Cos((toLon - lon) * Math.PI / 180) - ); - toTheta = (180 * toTheta / Math.PI + 360) % 360; + double fromTheta = Math.Atan2(Math.Cos(fromLat * Math.PI / 180) * Math.Sin((fromLon - lon) * Math.PI / 180), + Math.Cos(lat * Math.PI / 180) * Math.Sin(fromLat * Math.PI / 180) - Math.Sin(lat * Math.PI / 180) * Math.Cos(fromLat * Math.PI / 180) * Math.Cos((fromLon - lon) * Math.PI / 180) + ); + fromTheta = (180 * fromTheta / Math.PI + 360) % 360; - initialTheta = (int)Math.Min(fromTheta, toTheta); - finalTheta = (int)Math.Max(fromTheta, toTheta); + double toTheta = Math.Atan2(Math.Cos(toLat * Math.PI / 180) * Math.Sin((toLon - lon) * Math.PI / 180), + Math.Cos(lat * Math.PI / 180) * Math.Sin(toLat * Math.PI / 180) - Math.Sin(lat * Math.PI / 180) * Math.Cos(toLat * Math.PI / 180) * Math.Cos((toLon - lon) * Math.PI / 180) + ); + toTheta = (180 * toTheta / Math.PI + 360) % 360; - // calculate actual radius + initialTheta = (int)Math.Min(fromTheta, toTheta); + finalTheta = (int)Math.Max(fromTheta, toTheta); - double fromDist = R * Math.Acos(Math.Sin(lat * Math.PI / 180) * Math.Sin(fromLat * Math.PI / 180) + Math.Cos(lat * Math.PI / 180) * Math.Cos(fromLat * Math.PI / 180) * Math.Cos((lon - fromLon) * Math.PI / 180)); - fromDist = fromDist / 1.852; - double toDist = R * Math.Acos(Math.Sin(lat * Math.PI / 180) * Math.Sin(toLat * Math.PI / 180) + Math.Cos(lat * Math.PI / 180) * Math.Cos(toLat * Math.PI / 180) * Math.Cos((lon - toLon) * Math.PI / 180)); - toDist = toDist / 1.852; + initialTheta += 1; // padding + finalTheta -= DELTA_THETA; - float meanRadius = (float)Math.Round((fromDist + toDist) / 2, 2); + // calculate actual radius - if (meanRadius != radius) { - System.Console.WriteLine("RADIUS ERROR REPLACE ME BEFORE RELEASE"); - radius = meanRadius; - } + double fromDist = R * Math.Acos(Math.Sin(lat * Math.PI / 180) * Math.Sin(fromLat * Math.PI / 180) + Math.Cos(lat * Math.PI / 180) * Math.Cos(fromLat * Math.PI / 180) * Math.Cos((lon - fromLon) * Math.PI / 180)); + fromDist = fromDist / 1.852; + double toDist = R * Math.Acos(Math.Sin(lat * Math.PI / 180) * Math.Sin(toLat * Math.PI / 180) + Math.Cos(lat * Math.PI / 180) * Math.Cos(toLat * Math.PI / 180) * Math.Cos((lon - toLon) * Math.PI / 180)); + toDist = toDist / 1.852; - + float meanRadius = (float)Math.Round((fromDist + toDist) / 2, 2); - //System.Console.WriteLine(fromTheta); - //System.Console.WriteLine(toTheta); - //throw new System.Exception(); + if (meanRadius != radius) { + radius = meanRadius; // AIP radius was wrong + } + } } - for (int theta = initialTheta + 1; theta < finalTheta; theta += DELTA_THETA) { + for (int theta = initialTheta; theta <= finalTheta; theta += DELTA_THETA) { double deltaLat = (radius * Math.Cos(theta * Math.PI / 180)) / 60.0d; double deltaLon = (radius * Math.Sin(theta * Math.PI / 180)) / 60.0d; deltaLon /= Math.Cos((lat) * Math.PI / 180); // account for length of nautical mile changing with latitude @@ -123,7 +118,7 @@ public override IEnumerator GetEnumerator() string newLat = Coordinate.DecimalDegreeToDegreeMinSec(lat + deltaLat, true); string newLon = Coordinate.DecimalDegreeToDegreeMinSec(lon + deltaLon, false); - if (theta == initialTheta + 1 && !includesFromTo) { + if (theta == initialTheta && !includesFromTo) { prevLat = newLat; prevLon = newLon; continue; diff --git a/src/Compiler/Model/Coordinate.cs b/src/Compiler/Model/Coordinate.cs index 050fc4c0..6bcec7e0 100644 --- a/src/Compiler/Model/Coordinate.cs +++ b/src/Compiler/Model/Coordinate.cs @@ -16,6 +16,7 @@ public Coordinate(string latitude, string longitude) public static double DegreeMinSecToDecimalDegree(string latOrLong) { double output = 0; string[] sections = latOrLong.Split('.'); + Console.WriteLine(latOrLong); output += int.Parse(sections[0].Substring(1)); output += int.Parse(sections[1]) / 60.0d; output += int.Parse(sections[2]) / 3600.0d; @@ -46,7 +47,8 @@ public static string DecimalDegreeToDegreeMinSec(double decimalDegree, bool isLa output += ((int)decimalDegree).ToString().PadLeft(2, '0') + "."; decimalDegree -= (int)decimalDegree; decimalDegree *= 1000; - output += Math.Round(decimalDegree).ToString().PadLeft(3, '0'); + if (Math.Round(decimalDegree) > 999) output += "999"; + else output += Math.Round(decimalDegree).ToString().PadLeft(3, '0'); return output; } diff --git a/tests/CompilerTest/CompilerTest.csproj b/tests/CompilerTest/CompilerTest.csproj index b5297070..39728e3c 100644 --- a/tests/CompilerTest/CompilerTest.csproj +++ b/tests/CompilerTest/CompilerTest.csproj @@ -34,6 +34,14 @@ + + + + + + + + @@ -47,6 +55,7 @@ + diff --git a/tests/CompilerTest/Input/SectorDataFileTest.cs b/tests/CompilerTest/Input/SectorDataFileTest.cs index 3ca9fdcb..47bcf019 100644 --- a/tests/CompilerTest/Input/SectorDataFileTest.cs +++ b/tests/CompilerTest/Input/SectorDataFileTest.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Compiler.Input; using Compiler.Model; using Xunit; @@ -8,6 +9,7 @@ namespace CompilerTest.Input public class SectorDataFileTest { private readonly SectorDataFile file; + private readonly SectorDataFile arcGenFile; public SectorDataFileTest() { @@ -17,6 +19,13 @@ public SectorDataFileTest() InputDataType.ESE_AGREEMENTS, new EseSectorDataReader() ); + + arcGenFile = new SectorDataFile( + "_TestData/SectorDataFile/ArcGenTest.txt", + new InputFileStreamFactory(), + InputDataType.ESE_AGREEMENTS, + new EseSectorDataReader() + ); } [Fact] @@ -85,6 +94,21 @@ public void TestItIteratesTheInputFile() Assert.Equal(33, file.CurrentLineNumber); } + + [Fact] + public void TestItIteratesArcGen() { + string[] lines = { "Test Region N051.31.15.000 W000.07.30.000 N051.31.14.715 W000.07.19.500", "Test Region N051.31.14.715 W000.07.19.500 N051.31.13.861 W000.07.09.079", "Test Region N051.31.13.861 W000.07.09.079 N051.31.12.444 W000.06.58.818", "Test Region N051.31.12.444 W000.06.58.818 N051.31.10.477 W000.06.48.794", "Test Region N051.31.10.477 W000.06.48.794 N051.31.07.973 W000.06.39.083", "Test Region N051.31.07.973 W000.06.39.083 N051.31.04.952 W000.06.29.760", "Test Region N051.31.04.952 W000.06.29.760 N051.31.01.436 W000.06.20.896", "Test Region N051.31.01.436 W000.06.20.896 N051.30.57.453 W000.06.12.558", "Test Region N051.30.57.453 W000.06.12.558 N051.30.53.033 W000.06.04.808", "Test Region N051.30.53.033 W000.06.04.808 N051.30.48.209 W000.05.57.708", "Test Region N051.30.48.209 W000.05.57.708 N051.30.43.018 W000.05.51.309", "Test Region N051.30.43.018 W000.05.51.309 N051.30.37.500 W000.05.45.662", "Test Region N051.30.37.500 W000.05.45.662 N051.30.31.696 W000.05.40.809", "Test Region N051.30.31.696 W000.05.40.809 N051.30.25.652 W000.05.36.787", "Test Region N051.30.25.652 W000.05.36.787 N051.30.19.411 W000.05.33.626", "Test Region N051.30.19.411 W000.05.33.626 N051.30.13.024 W000.05.31.351", "Test Region N051.30.13.024 W000.05.31.351 N051.30.06.537 W000.05.29.979", "Test Region N051.30.06.537 W000.05.29.979 N051.30.00.000 W000.05.29.521", "Test Region N051.30.00.000 W000.05.29.521 N051.29.53.463 W000.05.29.979", "Test Region N051.29.53.463 W000.05.29.979 N051.29.46.976 W000.05.31.351", "Test Region N051.29.46.976 W000.05.31.351 N051.29.40.589 W000.05.33.626", "Test Region N051.29.40.589 W000.05.33.626 N051.29.34.348 W000.05.36.787", "Test Region N051.29.34.348 W000.05.36.787 N051.29.28.304 W000.05.40.809", "Test Region N051.29.28.304 W000.05.40.809 N051.29.22.500 W000.05.45.662", "Test Region N051.29.22.500 W000.05.45.662 N051.29.16.982 W000.05.51.309", "Test Region N051.29.16.982 W000.05.51.309 N051.29.11.791 W000.05.57.708", "Test Region N051.29.11.791 W000.05.57.708 N051.29.06.967 W000.06.04.808", "Test Region N051.29.06.967 W000.06.04.808 N051.29.02.547 W000.06.12.558", "Test Region N051.29.02.547 W000.06.12.558 N051.28.58.564 W000.06.20.896", "Test Region N051.28.58.564 W000.06.20.896 N051.28.55.048 W000.06.29.760", "Test Region N051.28.55.048 W000.06.29.760 N051.28.52.027 W000.06.39.083", "Test Region N051.28.52.027 W000.06.39.083 N051.28.49.523 W000.06.48.794", "Test Region N051.28.49.523 W000.06.48.794 N051.28.47.556 W000.06.58.818", "Test Region N051.28.47.556 W000.06.58.818 N051.28.46.139 W000.07.09.079", "Test Region N051.28.46.139 W000.07.09.079 N051.28.45.285 W000.07.19.500", "Test Region N051.28.45.285 W000.07.19.500 N051.28.44.999 W000.07.30.000", "Test Region N051.28.44.999 W000.07.30.000 N051.28.45.285 W000.07.40.500", "Test Region N051.28.45.285 W000.07.40.500 N051.28.46.139 W000.07.50.921", "Test Region N051.28.46.139 W000.07.50.921 N051.28.47.556 W000.08.01.182", "Test Region N051.28.47.556 W000.08.01.182 N051.28.49.523 W000.08.11.206", "Test Region N051.28.49.523 W000.08.11.206 N051.28.52.027 W000.08.20.917", "Test Region N051.28.52.027 W000.08.20.917 N051.28.55.048 W000.08.30.240", "Test Region N051.28.55.048 W000.08.30.240 N051.28.58.564 W000.08.39.104", "Test Region N051.28.58.564 W000.08.39.104 N051.29.02.547 W000.08.47.442", "Test Region N051.29.02.547 W000.08.47.442 N051.29.06.967 W000.08.55.192", "Test Region N051.29.06.967 W000.08.55.192 N051.29.11.791 W000.09.02.292", "Test Region N051.29.11.791 W000.09.02.292 N051.29.16.982 W000.09.08.691", "Test Region N051.29.16.982 W000.09.08.691 N051.29.22.500 W000.09.14.338", "Test Region N051.29.22.500 W000.09.14.338 N051.29.28.304 W000.09.19.191", "Test Region N051.29.28.304 W000.09.19.191 N051.29.34.348 W000.09.23.213", "Test Region N051.29.34.348 W000.09.23.213 N051.29.40.589 W000.09.26.374", "Test Region N051.29.40.589 W000.09.26.374 N051.29.46.976 W000.09.28.649", "Test Region N051.29.46.976 W000.09.28.649 N051.29.53.463 W000.09.30.021", "Test Region N051.29.53.463 W000.09.30.021 N051.30.00.000 W000.09.30.479", "Test Region N051.30.00.000 W000.09.30.479 N051.30.06.537 W000.09.30.021", "Test Region N051.30.06.537 W000.09.30.021 N051.30.13.024 W000.09.28.649", "Test Region N051.30.13.024 W000.09.28.649 N051.30.19.411 W000.09.26.374", "Test Region N051.30.19.411 W000.09.26.374 N051.30.25.652 W000.09.23.213", "Test Region N051.30.25.652 W000.09.23.213 N051.30.31.696 W000.09.19.191", "Test Region N051.30.31.696 W000.09.19.191 N051.30.37.500 W000.09.14.338", "Test Region N051.30.37.500 W000.09.14.338 N051.30.43.018 W000.09.08.691", "Test Region N051.30.43.018 W000.09.08.691 N051.30.48.209 W000.09.02.292", "Test Region N051.30.48.209 W000.09.02.292 N051.30.53.033 W000.08.55.192", "Test Region N051.30.53.033 W000.08.55.192 N051.30.57.453 W000.08.47.442", "Test Region N051.30.57.453 W000.08.47.442 N051.31.01.436 W000.08.39.104", "Test Region N051.31.01.436 W000.08.39.104 N051.31.04.952 W000.08.30.240", "Test Region N051.31.04.952 W000.08.30.240 N051.31.07.973 W000.08.20.917", "Test Region N051.31.07.973 W000.08.20.917 N051.31.10.477 W000.08.11.206", "Test Region N051.31.10.477 W000.08.11.206 N051.31.12.444 W000.08.01.182", "Test Region N051.31.12.444 W000.08.01.182 N051.31.13.861 W000.07.50.921", "Test Region N051.31.13.861 W000.07.50.921 N051.31.14.715 W000.07.40.500", "Test Region N051.31.14.715 W000.07.40.500 N051.31.15.000 W000.07.30.000" }; + string[] lines2 = { "Test Region N051.29.17.000 W000.06.34.000 N051.29.16.696 W000.06.34.039", "Test Region N051.29.16.696 W000.06.34.039 N051.29.13.869 W000.06.33.999", "Test Region N051.29.13.869 W000.06.33.999 N051.29.11.051 W000.06.34.355", "Test Region N051.29.11.051 W000.06.34.355 N051.29.08.264 W000.06.35.104", "Test Region N051.29.08.264 W000.06.35.104 N051.29.05.527 W000.06.36.241", "Test Region N051.29.05.527 W000.06.36.241 N051.29.02.863 W000.06.37.756", "Test Region N051.29.02.863 W000.06.37.756 N051.29.00.291 W000.06.39.639", "Test Region N051.29.00.291 W000.06.39.639 N051.28.57.831 W000.06.41.874", "Test Region N051.28.57.831 W000.06.41.874 N051.28.55.501 W000.06.44.445", "Test Region N051.28.55.501 W000.06.44.445 N051.28.52.000 W000.06.49.000" }; + int i = 0; + foreach (SectorData dataLine in arcGenFile) { + if (i < lines.Length) { + Assert.Equal(lines[i], dataLine.rawData); + } else { + Assert.Equal(lines2[i - lines.Length], dataLine.rawData); + } + i += 1; + } + } [Fact] public void ItsEqualIfPathTheSame() diff --git a/tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt b/tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt new file mode 100644 index 00000000..e1337fbb --- /dev/null +++ b/tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt @@ -0,0 +1,4 @@ +;Simple +;Arc region Test Region centre N051.30.00.000 W000.07.30.000 radius 1.25 +;Complex +;Arc region Test Region centre N051.29.15.000 W000.07.26.000 radius 0.55 from N051.29.17.000 W000.06.34.000 to N051.28.52.000 W000.06.49.000 \ No newline at end of file From b6b5ce9876f74ac82b56b8a018ab263b22cf7583 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 29 Aug 2023 15:47:35 +0100 Subject: [PATCH 7/9] fix csproj --- src/Compiler/Model/Coordinate.cs | 1 - tests/CompilerTest/CompilerTest.csproj | 10 +--------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Compiler/Model/Coordinate.cs b/src/Compiler/Model/Coordinate.cs index 6bcec7e0..04bc31ad 100644 --- a/src/Compiler/Model/Coordinate.cs +++ b/src/Compiler/Model/Coordinate.cs @@ -16,7 +16,6 @@ public Coordinate(string latitude, string longitude) public static double DegreeMinSecToDecimalDegree(string latOrLong) { double output = 0; string[] sections = latOrLong.Split('.'); - Console.WriteLine(latOrLong); output += int.Parse(sections[0].Substring(1)); output += int.Parse(sections[1]) / 60.0d; output += int.Parse(sections[2]) / 3600.0d; diff --git a/tests/CompilerTest/CompilerTest.csproj b/tests/CompilerTest/CompilerTest.csproj index 39728e3c..92e1a581 100644 --- a/tests/CompilerTest/CompilerTest.csproj +++ b/tests/CompilerTest/CompilerTest.csproj @@ -34,14 +34,6 @@ - - - - - - - - @@ -55,7 +47,7 @@ - + From 68a0d3d823b15b4947f510756ed68bbbef87c3c2 Mon Sep 17 00:00:00 2001 From: Alice Date: Sat, 2 Sep 2023 15:44:07 +0100 Subject: [PATCH 8/9] requested changes --- .../Input/AbstractSectorDataReader.cs | 4 +-- src/Compiler/Input/SectorDataFile.cs | 2 +- .../Input/EseSectorDataReaderTest.cs | 10 ++----- .../Input/SctSectorDataReaderTest.cs | 13 +++----- tests/CompilerTest/Model/CoordinateTest.cs | 30 ++++++++++--------- .../_TestData/SectorDataFile/ArcGenTest.txt | 4 +-- 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/Compiler/Input/AbstractSectorDataReader.cs b/src/Compiler/Input/AbstractSectorDataReader.cs index fd9ebf2d..dde435f7 100644 --- a/src/Compiler/Input/AbstractSectorDataReader.cs +++ b/src/Compiler/Input/AbstractSectorDataReader.cs @@ -20,7 +20,7 @@ public bool IsBlankLine(string line) */ public bool IsArcGenLine(string line) { try { - return line.TrimStart().StartsWith(this.GetCommentDelimiter()) && line.Substring(1, 3) == "Arc"; + return line.TrimStart().StartsWith("@ARC"); } catch (ArgumentOutOfRangeException) { return false; } @@ -31,7 +31,7 @@ public bool IsArcGenLine(string line) { */ public bool IsCommentLine(string line) { - return !IsArcGenLine(line) && line.TrimStart().StartsWith(this.GetCommentDelimiter()); + return line.TrimStart().StartsWith(this.GetCommentDelimiter()); } /* diff --git a/src/Compiler/Input/SectorDataFile.cs b/src/Compiler/Input/SectorDataFile.cs index 84cd2a79..9c8b4933 100644 --- a/src/Compiler/Input/SectorDataFile.cs +++ b/src/Compiler/Input/SectorDataFile.cs @@ -47,7 +47,7 @@ public override IEnumerator GetEnumerator() const int DELTA_THETA = 5; const double R = 6372.795477598; - Regex rx = new Regex(@";Arc region (.*) centre ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) radius (\d*(?:\.\d*){0,1})(?: from ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) to ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3})){0,1}", RegexOptions.None); + Regex rx = new Regex(@"@ARC\(region (.*) centre ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) radius (\d*(?:\.\d*){0,1})(?: from ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3}) to ([NS]\d{3}\.\d{2}\.\d{2}\.\d{3}) ([EW]\d{3}\.\d{2}\.\d{2}\.\d{3})){0,1}\)", RegexOptions.None); GroupCollection groups = rx.Match(line).Groups; // error catching! string regionName = groups[1].Value; diff --git a/tests/CompilerTest/Input/EseSectorDataReaderTest.cs b/tests/CompilerTest/Input/EseSectorDataReaderTest.cs index 71706dd3..05d0d4d5 100644 --- a/tests/CompilerTest/Input/EseSectorDataReaderTest.cs +++ b/tests/CompilerTest/Input/EseSectorDataReaderTest.cs @@ -43,24 +43,20 @@ public void ItDetectsABlankLine(string line, bool expected) [InlineData("", false)] [InlineData("// comment", false)] [InlineData("/* comment */", false)] + [InlineData("@ARC", false)] public void ItDetectsACommentLine(string line, bool expected) { Assert.Equal(expected, this.reader.IsCommentLine(line)); } - [Fact] - public void ItIgnoresArcGenLineAsComment() { - Assert.False(this.reader.IsCommentLine(";Arc xxx")); - } - [Fact] public void ItIgnoresShortComments() { - Assert.False(this.reader.IsArcGenLine(";Ar")); + Assert.False(this.reader.IsArcGenLine("@AR")); } [Fact] public void ItRecognisesArcGenLines() { - Assert.True(this.reader.IsArcGenLine(";Arc xxx")); + Assert.True(this.reader.IsArcGenLine("@ARC(xxx)")); } [Theory] diff --git a/tests/CompilerTest/Input/SctSectorDataReaderTest.cs b/tests/CompilerTest/Input/SctSectorDataReaderTest.cs index c5764432..8544303d 100644 --- a/tests/CompilerTest/Input/SctSectorDataReaderTest.cs +++ b/tests/CompilerTest/Input/SctSectorDataReaderTest.cs @@ -43,24 +43,19 @@ public void ItDetectsABlankLine(string line, bool expected) [InlineData("", false)] [InlineData("// comment", false)] [InlineData("/* comment */", false)] - public void ItDetectsACommentLine(string line, bool expected) - { + [InlineData("@ARC", false)] + public void ItDetectsACommentLine(string line, bool expected) { Assert.Equal(expected, this.reader.IsCommentLine(line)); } - [Fact] - public void ItIgnoresArcGenLineAsComment() { - Assert.False(this.reader.IsCommentLine(";Arc xxx")); - } - [Fact] public void ItIgnoresShortComments() { - Assert.False(this.reader.IsArcGenLine(";Ar")); + Assert.False(this.reader.IsArcGenLine("@AR")); } [Fact] public void ItRecognisesArcGenLines() { - Assert.True(this.reader.IsArcGenLine(";Arc xxx")); + Assert.True(this.reader.IsArcGenLine("@ARC(xxx)")); } [Theory] diff --git a/tests/CompilerTest/Model/CoordinateTest.cs b/tests/CompilerTest/Model/CoordinateTest.cs index 453260c5..e0c3f455 100644 --- a/tests/CompilerTest/Model/CoordinateTest.cs +++ b/tests/CompilerTest/Model/CoordinateTest.cs @@ -30,22 +30,24 @@ public void TestItRepresentsAsString() Assert.Equal("abc def", coordinate.ToString()); } - [Fact] - public void TestDegreeMinSecToDecimalDegree() { - Assert.Equal(54.51555556, Coordinate.DegreeMinSecToDecimalDegree("N054.30.56.000"), 0.00000001); // tolerance for float precision - Assert.Equal(51.26757306, Coordinate.DegreeMinSecToDecimalDegree("N051.16.03.263"), 0.00000001); - Assert.Equal(-23.85944194, Coordinate.DegreeMinSecToDecimalDegree("S023.51.33.991"), 0.00000001); - Assert.Equal(0.52033000, Coordinate.DegreeMinSecToDecimalDegree("E000.31.13.188"), 0.00000001); - Assert.Equal(-3.19839500, Coordinate.DegreeMinSecToDecimalDegree("W003.11.54.222"), 0.00000001); + [Theory] + [InlineData(54.51555556, "N054.30.56.000")] + [InlineData(51.26757306, "N051.16.03.263")] + [InlineData(-23.85944194, "S023.51.33.991")] + [InlineData(0.52033000, "E000.31.13.188")] + [InlineData(-3.19839500, "W003.11.54.222")] + public void TestDegreeMinSecToDecimalDegree(double expected, string coordinateString) { + Assert.Equal(expected, Coordinate.DegreeMinSecToDecimalDegree(coordinateString), 0.00000001); // tolerance for float precision } - [Fact] - public void TestDecimalDegreeToDegreeMinSec() { - Assert.Equal("N054.30.56.000", Coordinate.DecimalDegreeToDegreeMinSec(54.51555556, true)); - Assert.Equal("N051.16.03.263", Coordinate.DecimalDegreeToDegreeMinSec(51.26757306, true)); - Assert.Equal("S023.51.33.991", Coordinate.DecimalDegreeToDegreeMinSec(-23.85944194, true)); - Assert.Equal("E000.31.13.188", Coordinate.DecimalDegreeToDegreeMinSec(0.52033000, false)); - Assert.Equal("W003.11.54.222", Coordinate.DecimalDegreeToDegreeMinSec(-3.19839500, false)); + [Theory] + [InlineData(54.51555556, "N054.30.56.000")] + [InlineData(51.26757306, "N051.16.03.263")] + [InlineData(-23.85944194, "S023.51.33.991")] + [InlineData(0.52033000, "E000.31.13.188")] + [InlineData(-3.19839500, "W003.11.54.222")] + public void TestDecimalDegreeToDegreeMinSec(double coordinate, string expected) { + Assert.Equal(expected, Coordinate.DecimalDegreeToDegreeMinSec(coordinate, true)); } } } diff --git a/tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt b/tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt index e1337fbb..61e4af70 100644 --- a/tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt +++ b/tests/CompilerTest/_TestData/SectorDataFile/ArcGenTest.txt @@ -1,4 +1,4 @@ ;Simple -;Arc region Test Region centre N051.30.00.000 W000.07.30.000 radius 1.25 +@ARC(region Test Region centre N051.30.00.000 W000.07.30.000 radius 1.25) ;Complex -;Arc region Test Region centre N051.29.15.000 W000.07.26.000 radius 0.55 from N051.29.17.000 W000.06.34.000 to N051.28.52.000 W000.06.49.000 \ No newline at end of file +@ARC(region Test Region centre N051.29.15.000 W000.07.26.000 radius 0.55 from N051.29.17.000 W000.06.34.000 to N051.28.52.000 W000.06.49.000) \ No newline at end of file From 0b738afdb447003bcf1d272fa79c8aa5d167c146 Mon Sep 17 00:00:00 2001 From: Alice Date: Sat, 2 Sep 2023 15:47:34 +0100 Subject: [PATCH 9/9] running the tests does help --- tests/CompilerTest/Model/CoordinateTest.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/CompilerTest/Model/CoordinateTest.cs b/tests/CompilerTest/Model/CoordinateTest.cs index e0c3f455..a105d530 100644 --- a/tests/CompilerTest/Model/CoordinateTest.cs +++ b/tests/CompilerTest/Model/CoordinateTest.cs @@ -41,13 +41,13 @@ public void TestDegreeMinSecToDecimalDegree(double expected, string coordinateSt } [Theory] - [InlineData(54.51555556, "N054.30.56.000")] - [InlineData(51.26757306, "N051.16.03.263")] - [InlineData(-23.85944194, "S023.51.33.991")] - [InlineData(0.52033000, "E000.31.13.188")] - [InlineData(-3.19839500, "W003.11.54.222")] - public void TestDecimalDegreeToDegreeMinSec(double coordinate, string expected) { - Assert.Equal(expected, Coordinate.DecimalDegreeToDegreeMinSec(coordinate, true)); + [InlineData(54.51555556, "N054.30.56.000", true)] + [InlineData(51.26757306, "N051.16.03.263", true)] + [InlineData(-23.85944194, "S023.51.33.991", true)] + [InlineData(0.52033000, "E000.31.13.188", false)] + [InlineData(-3.19839500, "W003.11.54.222", false)] + public void TestDecimalDegreeToDegreeMinSec(double coordinate, string expected, bool isLat) { + Assert.Equal(expected, Coordinate.DecimalDegreeToDegreeMinSec(coordinate, isLat)); } } }