Skip to content

Commit

Permalink
bugfix: make sure the value of x2 is greater than x1. (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: hybfkuf <[email protected]>
  • Loading branch information
forbearing and hybfkuf authored Aug 19, 2023
1 parent 32b17c8 commit 98022f9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions array2d/array2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down

0 comments on commit 98022f9

Please sign in to comment.