Skip to content

Commit

Permalink
Fix issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Dec 5, 2013
1 parent 456573f commit b6391e3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions gl3n/aabb.d
Expand Up @@ -31,10 +31,16 @@ struct AABBT(type) {
static AABBT from_points(vec3[] points) {
AABBT res;

foreach(v; points) {
res.expand(v);
if(points.length == 0) {
return res;
}

res.min = points[0];
res.max = points[0];
foreach(v; points[1..$]) {
res.expand(v);
}

return res;
}

Expand All @@ -46,6 +52,10 @@ struct AABBT(type) {
a = AABB.from_points([vec3(0.0f, 0.0f, 0.0f), vec3(-1.0f, 2.0f, 3.0f), vec3(0.0f, 0.0f, 4.0f)]);
assert(a.min == vec3(-1.0f, 0.0f, 0.0f));
assert(a.max == vec3(0.0f, 2.0f, 4.0f));

a = AABB.from_points([vec3(1.0f, 1.0f, 1.0f), vec3(2.0f, 2.0f, 2.0f)]);
assert(a.min == vec3(1.0f, 1.0f, 1.0f));
assert(a.max == vec3(2.0f, 2.0f, 2.0f));
}

/// Expands the AABB by another AABB.
Expand Down Expand Up @@ -174,4 +184,4 @@ struct AABBT(type) {
}
}

alias AABBT!(float) AABB;
alias AABBT!(float) AABB;

0 comments on commit b6391e3

Please sign in to comment.