Dav1dde / gl3n

OpenGL Maths for D (not glm for D).
http://dav1dde.github.com/gl3n/
Other
103 stars 49 forks source link

AABB from_points does not work as expected #23

Closed mbj2011 closed 10 years ago

mbj2011 commented 10 years ago

The initial min/max vectors might not be part of the minimal AABB containing the provided points.

Dav1dde commented 10 years ago

I am not sure if I understand what you mean, can you provide me an example?

mbj2011 commented 10 years ago

Absolutely.

AABB aabb = AABB.from_points([vec3(1, 1, 1), vec3(2, 2, 2)]);

results in aabb.center() having the value [1, 1, 1], where it should have been [1.5, 1.5, 1.5].

I temporarily fixed it using the following code instead:

static AABBT from_points(vec3[] points) {
    AABBT res;

    res.min = res.max = points[0];

    foreach(v; points[1 .. $]) {
        res.expand(v);
    }

    return res;
}
Dav1dde commented 10 years ago

Thank you very much, I hopefully fixed it. Since I don't have access to a compiler right now, it would be great if you could report back!

mbj2011 commented 10 years ago

It compiles and works like it's supposed to :-)