From ba0d62aea8ae1c7a997d5d47859eedb884b6da86 Mon Sep 17 00:00:00 2001 From: Anton Kudryashov <qubabox@mail.ru> Date: Wed, 23 Nov 2016 14:48:22 +0300 Subject: [PATCH] fixed interpol with null index value --- WindStressPRM/Utils/Matrix.cs | 4 ++-- WindStressPRM/WindStressPRM.cs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/WindStressPRM/Utils/Matrix.cs b/WindStressPRM/Utils/Matrix.cs index 12fd947..e01281a 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 8538d20..aef8b4c 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; -- GitLab