Skip to content

Commit

Permalink
ConvexPolyhedron calculateWorldAABB() can return undefined values in max
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yau committed May 28, 2021
1 parent b2b1fb3 commit c5eb05b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/shapes/ConvexPolyhedron.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ var tempWorldVertex = new Vec3();
* @param {Vec3} min
* @param {Vec3} max
*/
ConvexPolyhedron.prototype.calculateWorldAABB = function(pos,quat,min,max){
ConvexPolyhedron.prototype.calculateWorldAABB = function(pos,quat,min,max){
var n = this.vertices.length, verts = this.vertices;
var minx,miny,minz,maxx,maxy,maxz;
for(var i=0; i<n; i++){
Expand All @@ -741,19 +741,25 @@ ConvexPolyhedron.prototype.calculateWorldAABB = function(pos,quat,min,max){
var v = tempWorldVertex;
if (v.x < minx || minx===undefined){
minx = v.x;
} else if(v.x > maxx || maxx===undefined){
}

if(v.x > maxx || maxx===undefined){
maxx = v.x;
}

if (v.y < miny || miny===undefined){
miny = v.y;
} else if(v.y > maxy || maxy===undefined){
}

if(v.y > maxy || maxy===undefined){
maxy = v.y;
}

if (v.z < minz || minz===undefined){
minz = v.z;
} else if(v.z > maxz || maxz===undefined){
}

if(v.z > maxz || maxz===undefined){
maxz = v.z;
}
}
Expand Down
35 changes: 35 additions & 0 deletions test/ConvexPolyhedron.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ module.exports = {
test.done();
},

calculateWorldAABBAlwaysDecreasingVertsNoUndefined: function(test) {
var vertices = [
new Vec3( 4, 4, 4),
new Vec3( 3, 3, 3),
new Vec3( 2, 2, 2),
new Vec3( 1, 1, 1),
new Vec3( 0, 0, 0),
new Vec3(-1,-1,-1),
new Vec3(-2,-2,-2),
new Vec3(-3,-3,-3)
];

var indices = [
[3,2,1,0],
[4,5,6,7],
[5,4,0,1],
[2,3,7,6],
[0,4,7,3],
[1,2,6,5],
];

var poly = new ConvexPolyhedron(vertices, indices);
var min = new Vec3();
var max = new Vec3();
poly.calculateWorldAABB(new Vec3(0, 0, 0), new Quaternion(0, 0, 0, 1), min, max);

test.notEqual(min.x, undefined);
test.notEqual(max.x, undefined);
test.notEqual(min.y, undefined);
test.notEqual(max.y, undefined);
test.notEqual(min.z, undefined);
test.notEqual(max.z, undefined);
test.done();
},

clipFaceAgainstPlane : function(test){
var h = createBoxHull();

Expand Down

0 comments on commit c5eb05b

Please sign in to comment.