diff --git a/Consequences/Geography/BoundingBox.cs b/Consequences/Geography/BoundingBox.cs index 1f827fc..d5d2e0f 100644 --- a/Consequences/Geography/BoundingBox.cs +++ b/Consequences/Geography/BoundingBox.cs @@ -1,33 +1,30 @@ namespace USACE.HEC.Geography; public class BoundingBox { - private Location _upperLeft; - private Location _lowerRight; + public Location UpperLeft { get; } + public Location LowerRight { get; } public BoundingBox(Location upperLeft, Location lowerRight) { - _upperLeft = upperLeft; - _lowerRight = lowerRight; + UpperLeft = upperLeft; + LowerRight = lowerRight; } - public Location GetUpperLeft() { return _upperLeft; } - public Location GetLowerRight() { return _lowerRight; } - public string NSIFormat() { return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", - _upperLeft.X, _upperLeft.Y, - _lowerRight.X, _upperLeft.Y, - _lowerRight.X, _lowerRight.Y, - _upperLeft.X, _lowerRight.Y, - _upperLeft.X, _upperLeft.Y); + UpperLeft.X, UpperLeft.Y, + LowerRight.X, UpperLeft.Y, + LowerRight.X, LowerRight.Y, + UpperLeft.X, LowerRight.Y, + UpperLeft.X, UpperLeft.Y); } // not sure about this functionality right now, just a placeholder public string GDALFormat() { return string.Format("{0}{1}{2}{3}", - _upperLeft.X, _upperLeft.Y, - _lowerRight.X, _lowerRight.X); + UpperLeft.X, UpperLeft.Y, + LowerRight.X, LowerRight.X); } } diff --git a/Consequences/Hazards/IHazardProvider.cs b/Consequences/Hazards/IHazardProvider.cs index faee462..dc2561c 100644 --- a/Consequences/Hazards/IHazardProvider.cs +++ b/Consequences/Hazards/IHazardProvider.cs @@ -4,6 +4,6 @@ namespace USACE.HEC.Hazards; public interface IHazardProvider { - public BoundingBox Extent(); + public BoundingBox Extent { get; set; } public IHazard Hazard(Location location); } diff --git a/Consequences/Hazards/RandomDepthHazardProvider.cs b/Consequences/Hazards/RandomDepthHazardProvider.cs index 763c88b..f2f8f96 100644 --- a/Consequences/Hazards/RandomDepthHazardProvider.cs +++ b/Consequences/Hazards/RandomDepthHazardProvider.cs @@ -3,6 +3,8 @@ namespace USACE.HEC.Hazards; public class RandomDepthHazardProvider : IHazardProvider { + private BoundingBox _bbox; + private Random _rng; public RandomDepthHazardProvider(int seed) @@ -10,11 +12,10 @@ public RandomDepthHazardProvider(int seed) _rng = new Random(seed); } - public BoundingBox Extent() + public BoundingBox Extent { - Location upperLeft = new Location { X = 0, Y = 0 }; - Location lowerRight = new Location { X = 0, Y = 0 }; - return new BoundingBox(upperLeft, lowerRight); + get { return _bbox; } + set { _bbox = value; } } public IHazard Hazard(Location location) diff --git a/Consequences/Results/ConsoleWriter.cs b/Consequences/Results/ConsoleWriter.cs index 59dd53b..50f550f 100644 --- a/Consequences/Results/ConsoleWriter.cs +++ b/Consequences/Results/ConsoleWriter.cs @@ -11,14 +11,14 @@ public class ConsoleWriter : IResultsWriter private void CheckIfSameHeaders(Result res) { // different number of headers - if (res.GetResultItems().Length != headers.Count) + if (res.ResultItems.Length != headers.Count) { throw new InvalidOperationException(); } for (int i = 0; i < headers.Count; i++) { // headers do not match - if (res.GetResultItems()[i].ResultName != headers[i]) + if (res.ResultItems[i].ResultName != headers[i]) { throw new InvalidOperationException(); } @@ -31,15 +31,15 @@ public string WriteString(Result res) if (!hasHeaderWritten) { // write the headers to the top of the file - for (int i = 0; i < res.GetResultItems().Length; i++) + for (int i = 0; i < res.ResultItems.Length; i++) { //sb.Append(res.GetResultItems()[i].ResultName); - output.Append(res.GetResultItems()[i].ResultName); - if (i < res.GetResultItems().Length - 1) + output.Append(res.ResultItems[i].ResultName); + if (i < res.ResultItems.Length - 1) { output.Append(','); } - headers.Add(res.GetResultItems()[i].ResultName); + headers.Add(res.ResultItems[i].ResultName); } output.Append("\r\n"); hasHeaderWritten = true; diff --git a/Consequences/Results/Result.cs b/Consequences/Results/Result.cs index a85f231..bf4004d 100644 --- a/Consequences/Results/Result.cs +++ b/Consequences/Results/Result.cs @@ -1,24 +1,19 @@ namespace USACE.HEC.Results; public class Result { - private ResultItem[] _resultItems; + public ResultItem[] ResultItems { get; } public Result(ResultItem[] resultItems) { - _resultItems = resultItems; - } - - public ResultItem[] GetResultItems() - { - return _resultItems; + ResultItems = resultItems; } // retrieve a ResultItem from a Result by name public ResultItem Fetch(string name) { - for (int i = 0; i < _resultItems.Length; i++) - if (_resultItems[i].ResultName == name) - return _resultItems[i]; + for (int i = 0; i < ResultItems.Length; i++) + if (ResultItems[i].ResultName == name) + return ResultItems[i]; // return empty ResultItem if not found ResultItem item = new ResultItem(); item.ResultName = name; diff --git a/ConsequencesTest/NSIStreamingProcessorTest.cs b/ConsequencesTest/NSIStreamingProcessorTest.cs index e7542e4..f7de2c8 100644 --- a/ConsequencesTest/NSIStreamingProcessorTest.cs +++ b/ConsequencesTest/NSIStreamingProcessorTest.cs @@ -20,7 +20,7 @@ public void Test() IHazardProvider depthHazardProvider = new RandomDepthHazardProvider(25); IResultsWriter consoleWriter = new ConsoleWriter(); - sp.Process(depthHazardProvider.Extent(), (IConsequencesReceptor s) => { + sp.Process(depthHazardProvider.Extent, (IConsequencesReceptor s) => { Result r = s.Compute(depthHazardProvider.Hazard(s.GetLocation())); consoleWriter.Write(r); }); diff --git a/ConsequencesTest/RandomDepthHazardProviderTest.cs b/ConsequencesTest/RandomDepthHazardProviderTest.cs index e2a797f..7c25ab4 100644 --- a/ConsequencesTest/RandomDepthHazardProviderTest.cs +++ b/ConsequencesTest/RandomDepthHazardProviderTest.cs @@ -7,14 +7,16 @@ public class RandomDepthHazardProviderTest [Fact] public void ExtentTest() { - IHazardProvider depthProvider = new RandomDepthHazardProvider(26); + Location location1 = new Location { X = 0, Y = 0 }; + Location location2 = new Location { X = 0, Y = 0 }; + IHazardProvider depthProvider = new RandomDepthHazardProvider(26) { Extent = new BoundingBox(location1, location2) }; - BoundingBox box = depthProvider.Extent(); + BoundingBox box = depthProvider.Extent; - Assert.Equal(0, box.GetUpperLeft().X); - Assert.Equal(0, box.GetUpperLeft().Y); - Assert.Equal(0, box.GetLowerRight().X); - Assert.Equal(0, box.GetLowerRight().Y); + Assert.Equal(0, box.UpperLeft.X); + Assert.Equal(0, box.UpperLeft.Y); + Assert.Equal(0, box.LowerRight.X); + Assert.Equal(0, box.LowerRight.Y); } [Fact]