From 98022f93823f04bab6eeb0840af421268c9a2e59 Mon Sep 17 00:00:00 2001 From: hybfkuf Date: Sun, 20 Aug 2023 06:34:07 +0800 Subject: [PATCH] bugfix: make sure the value of x2 is greater than x1. (#50) Co-authored-by: hybfkuf --- array2d/array2d.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/array2d/array2d.go b/array2d/array2d.go index db09fc7..172283c 100644 --- a/array2d/array2d.go +++ b/array2d/array2d.go @@ -131,6 +131,9 @@ func (a Array2D[T]) RowSpan(x1, x2, y int) []T { if x2 < 0 || x2 >= a.width { panic(fmt.Sprintf("array2d: x2 index out of range [%d] with width %d", x2, a.width)) } + if x2 < x1 { + x1, x2 = x2, x1 + } return a.slice[x1+y*a.height : 1+x2+y*a.height] }