Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvexPolyhedron calculateWorldAABB() can return undefined values in max #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/shapes/ConvexPolyhedron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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