#Ray Tracer Challenge
9 messages · Page 1 of 1 (latest)
Yeah, I'm unsure what to do at this point, beside changing the structure to use nested vectors
nested vectors are a terrible data structure
if you're going to go for dynamic lengths, the right way is to use a single vector and calculate indices in it
https://docs.rs/ndarray/ is one library that does that, though I haven't used it myself
The ndarray crate provides an n-dimensional container for general elements and for numerics.
Gotcha, so just use a single vector and calc the row / col offsets? I'm trying to avoid using crates at this point so I can learn as much about the language as possible.
Yep. Given this is n-dimensional, using a Vec is probably the best option. Or at least the simplest. If the matrices were specific sizes like 2x2, 3x3, and 4x4, then you could use a bunch of "row" structs of the respective size. Or perhaps const generics depending on your use-case. https://docs.rs/cgmath/ is a good example of fixed-sized matrices and (math) vectors.
For a Vec implementation, you can calculate the index as (row * width) + col. And then you can convert the other way with row = index / width and col = index % width.