diff --git a/WindStressPRM/Utils/Matrix.cs b/WindStressPRM/Utils/Matrix.cs index 12fd947bf794373f5253f57a4d8a9b18cf0a6565..e01281a4d084a12883954662f1c97d955aa9e4e8 100644 --- a/WindStressPRM/Utils/Matrix.cs +++ b/WindStressPRM/Utils/Matrix.cs @@ -25,7 +25,7 @@ namespace WindStressPRM /// get index of cell for coordinate /// </summary> /// <param name="coordinate"></param> - /// <returns></returns> + /// <returns>null if it doesn't exist</returns> public Index ProjectionToCell(Coordinate coordinate) { double rwDiff = (coordinate.X - Origin.X) / Size.Width; @@ -35,7 +35,7 @@ namespace WindStressPRM if (iRow < 0 || iCol < 0 || iRow >= RowsCount() || iCol >= ColumnCount()) { - throw new Exception("projectionToCell method trying to find uncorrect index"); + return null; } return new Index(iRow, iCol); } diff --git a/WindStressPRM/WindStressPRM.cs b/WindStressPRM/WindStressPRM.cs index 8538d20a1c61b4f5a2231d70f0a090cee6445582..aef8b4c2c2f8781f4a2b34311b0f635d0d46d3bf 100644 --- a/WindStressPRM/WindStressPRM.cs +++ b/WindStressPRM/WindStressPRM.cs @@ -319,6 +319,10 @@ namespace WindStressPRM const bool normalX = true;// true - East, false West const bool normalY = false;// true - North, false South Index rc = matrix.ProjectionToCell(coords); + if (rc == null) { + // return NaN, because there is no correct index + return Double.NaN; + } Coordinate center = matrix.CellToProjection(rc); double xDiff = coords.X - center.X; double yDiff = coords.Y - center.Y;