zesterer / wavefront

A Wavefront OBJ parser and utility crate
Apache License 2.0
3 stars 2 forks source link

Bug: Triangulation #2

Open faulesocke opened 3 years ago

faulesocke commented 3 years ago

I just had a quick look at this and found (besides some features I still miss) this bug:

In Polygon::triangles there is this:

        (0..this.vertices.len().saturating_sub(1) / 2)
            .map(move |i| [
                this.vertex(0).unwrap(),
                this.vertex(i * 2 + 1).unwrap(),
                this.vertex(i * 2 + 2).unwrap(),
            ])

When triangulating a quad, the calculation is (4-1) / 2 = 3 / 2 = 1, i.e. it should only yield one triangle instead of two. I haven't tested this out, just looked at the code, so please correct me if this is a brainfart and the code works as intended. Basically this should be just a saturating_sub(2), without the division, shouldn't it?

Also the indices seem wrong, for example for a quad you want the series 0, 1, 2, 0, 2, 3, right? Your code would produce 0, 1, 2, 3, 4 which is already out of bounds.

zesterer commented 3 years ago

Thanks for noticing this, you are correct! I'll amend this now.

zesterer commented 3 years ago

I've released version 0.2.1 with this fix. Thanks!