From 27e9f9d63aae7c3229ab2877bf538c24c8cd3220 Mon Sep 17 00:00:00 2001 From: zwarenelle Date: Mon, 24 Jun 2024 21:09:18 +0200 Subject: [PATCH] update GetNeighbors --- src/CoveragePathPlanner/CoveragePathPlanner.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CoveragePathPlanner/CoveragePathPlanner.cs b/src/CoveragePathPlanner/CoveragePathPlanner.cs index 1054677..7305dd9 100644 --- a/src/CoveragePathPlanner/CoveragePathPlanner.cs +++ b/src/CoveragePathPlanner/CoveragePathPlanner.cs @@ -144,9 +144,13 @@ public class Cell int neighborX = X + x; int neighborY = Y + y; - if (neighborX >= 0 && neighborX < cells.Count / cells[0].Y && neighborY >= 0 && neighborY < cells[0].Y) + if (neighborX >= 0 && neighborX < _width && neighborY >= 0 && neighborY < _height) { - yield return cells[neighborX + neighborY * cells.Count / cells[0].Y]; + int index = neighborX + neighborY * _width; + if (index >= 0 && index < cells.Count) + { + yield return cells[index]; + } } } }