#Ray Tracer Challenge

9 messages · Page 1 of 1 (latest)

golden helm
#

currently, Rust's const-generics are not powerful enough to do this

molten locust
#

Yeah, I'm unsure what to do at this point, beside changing the structure to use nested vectors

golden helm
#

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

molten locust
#

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.

sacred turtle
#

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.

molten locust
#

Gotcha. Thanks

#

I am using specific sizes, but I wanted to challenge myself in creating something more dynamic, which I regret now, but still learned a little bit about generics in practice.