From b6391e3f0dd8c6259354d6e30c181b36462c0377 Mon Sep 17 00:00:00 2001 From: David Herberth Date: Thu, 5 Dec 2013 17:41:42 +0100 Subject: [PATCH] Fix issue #23 --- gl3n/aabb.d | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gl3n/aabb.d b/gl3n/aabb.d index 2c78f7e..b9092bf 100644 --- a/gl3n/aabb.d +++ b/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; \ No newline at end of file +alias AABBT!(float) AABB;