From b11be611e24bb2b7239117831f1292176406cd3c Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Mon, 12 Jun 2023 17:43:51 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=E8=8E=B7=E5=8F=96=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=BF=9E=E7=BB=AD=E4=BD=8D=E7=BD=AE=E7=9A=84=E7=9F=A9=E9=98=B5?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E7=89=B9=E5=AE=9A=E4=BD=8D=E7=BD=AE=E7=9B=B8?= =?UTF-8?q?=E9=82=BB=E7=9A=84=E6=9C=80=E5=A4=9A=E5=9B=9B=E4=B8=AA=E6=96=B9?= =?UTF-8?q?=E5=90=91=E7=9A=84=E4=BD=8D=E7=BD=AE=E6=97=B6=EF=BC=8C=E5=B7=A6?= =?UTF-8?q?=E5=8F=B3=E4=B8=A4=E6=96=B9=E5=8F=AF=E8=83=BD=E4=BC=9A=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/g2d/g2d.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/g2d/g2d.go b/utils/g2d/g2d.go index 4bd2c70..bf4880d 100644 --- a/utils/g2d/g2d.go +++ b/utils/g2d/g2d.go @@ -36,16 +36,17 @@ func GetAdjacentPositions[T any](matrix [][]T, x, y int) (result [][2]int) { // GetAdjacentPositionsWithContinuousPosition 获取一个连续位置的矩阵中,特定位置相邻的最多四个方向的位置 func GetAdjacentPositionsWithContinuousPosition[T any](matrix []T, width, pos int) (result []int) { size := len(matrix) + currentRow := pos / width if up := pos - width; up >= 0 { result = append(result, up) } if down := pos + width; down < size { result = append(result, down) } - if left := pos - 1; pos >= 0 { + if left := pos - 1; left >= 0 && currentRow == (left/width) { result = append(result, left) } - if right := pos + 1; right < size { + if right := pos + 1; right < size && currentRow == (right/width) { result = append(result, right) } return