marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 793 forks source link

Ch 6. matrix representation not obvious. #482

Closed rbakaou closed 5 years ago

rbakaou commented 5 years ago

Hello, thanks for the book good materials in it. I just wanted to point that the matrix representation in a single array like you did was not obvious for new comers. When i read it . the most obvious representation of matrix to me was array of arrays. and when i saw your representation i didn't understood why the need for the width in the index calculus. it is only after seeing it in an other code base (ReiNX splash screen) and some googling i understood it was something really simple as explained here :https://stackoverflow.com/questions/14015556/how-to-map-the-indexes-of-a-matrix-to-a-1-dimensional-array-c/14015582 and that it was called row major order. and the width was added to prevent x:2,y:1 to not point to the same element as x:1,y:2.

marijnh commented 5 years ago

The first paragraph after the code explains this representation. This is a common technique, and with the explanation, seems clear enough.