Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue #23

  • Loading branch information...
commit b6391e3f0dd8c6259354d6e30c181b36462c0377 1 parent 456573f
@Dav1dde authored
Showing with 13 additions and 3 deletions.
  1. +13 −3 gl3n/aabb.d
View
16 gl3n/aabb.d
@@ -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;
}
@@ -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.
@@ -174,4 +184,4 @@ struct AABBT(type) {
}
}
-alias AABBT!(float) AABB;
+alias AABBT!(float) AABB;
Please sign in to comment.
Something went wrong with that request. Please try again.