PositionToInt 注释优化

This commit is contained in:
kercylan98 2023-06-09 17:39:23 +08:00
parent 7bafaed072
commit 44a4823712
2 changed files with 4 additions and 0 deletions

View File

@ -52,6 +52,7 @@ func GetAdjacentPositionsWithContinuousPosition[T any](matrix []T, width, pos in
} }
// PositionToInt 将坐标转换为二维数组的顺序位置 // PositionToInt 将坐标转换为二维数组的顺序位置
// - 需要确保x的取值范围必须小于width或者将会得到不正确的值
func PositionToInt(width, x, y int) int { func PositionToInt(width, x, y int) int {
return y*width + x return y*width + x
} }

View File

@ -10,4 +10,7 @@ func TestPositionIntToXY(t *testing.T) {
fmt.Println(pos) fmt.Println(pos)
fmt.Println(PositionIntToXY(9, pos)) fmt.Println(PositionIntToXY(9, pos))
fmt.Println(PositionToInt(65000, 61411, 158266))
fmt.Println(PositionIntToXY(65000, 10287351411))
} }