Skip to content

Commit

Permalink
added auto properties where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jackschonherr committed Aug 26, 2024
1 parent 060bf64 commit 430f050
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 42 deletions.
25 changes: 11 additions & 14 deletions Consequences/Geography/BoundingBox.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion Consequences/Hazards/IHazardProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace USACE.HEC.Hazards;

public interface IHazardProvider
{
public BoundingBox Extent();
public BoundingBox Extent { get; set; }
public IHazard Hazard(Location location);
}
9 changes: 5 additions & 4 deletions Consequences/Hazards/RandomDepthHazardProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
namespace USACE.HEC.Hazards;
public class RandomDepthHazardProvider : IHazardProvider
{
private BoundingBox _bbox;

private Random _rng;

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)
Expand Down
12 changes: 6 additions & 6 deletions Consequences/Results/ConsoleWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down
15 changes: 5 additions & 10 deletions Consequences/Results/Result.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ConsequencesTest/NSIStreamingProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
14 changes: 8 additions & 6 deletions ConsequencesTest/RandomDepthHazardProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 430f050

Please sign in to comment.