joshuahall / elm-2d-array Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://package.elm-lang.org/packages/JoshuaHall/elm-2d-array/latest/
License: BSD 3-Clause "New" or "Revised" License
Home Page: https://package.elm-lang.org/packages/JoshuaHall/elm-2d-array/latest/
License: BSD 3-Clause "New" or "Revised" License
Hi!
I recently had a bug when searching for neighbours in an Array2D.
It looks like when calling Array2D.get
with a negative column will return values from the previous row, if any, starting from the end.
array = Array2D.fromRows <|
Array.fromList
[ Array.fromList [ 1, 2 ]
, Array.fromList [ 3, 4 ]
]
result = Maybe.map (Array.get 1 -1) array -- returns (Just 2) instead of Nothing
Please see the following Ellie: https://ellie-app.com/gbCSDCn2r9ka1
Is it intended behaviour?
[EDIT]
If is not intended behaviour, I guess I could add a check against row
/column
begin greater than numRows
/numColumns
here:
get : Int -> Int -> Array2D a -> Maybe a
get row column (InternalArray2D array) =
if row >= array.numRows || column >= array.numColumns then
Nothing
else
Array.get
(indexFromRowAndColumn (InternalArray2D array) row column)
array.array
In the first example indices are correct in the provided function, but in the second example, you can see that the indices are wrong.
I think the problem occurs when rows are greater than cols.
Array2D.initialize 4 4 (\row col -> (String.fromInt row ++ ":" ++ String.fromInt col))
["0:0","0:1","0:2","0:3"
,"1:0","1:1","1:2","1:3"
,"2:0","2:1","2:2","2:3"
,"3:0","3:1","3:2","3:3"
]
Array2D.initialize 4 2 (\row col -> (String.fromInt row ++ ":" ++ String.fromInt col))
["0:0","0:1"
,"0:0","0:1"
,"1:0","1:1"
,"1:0","1:1
]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.