Skip to content

Commit

Permalink
Finished bounds calculation for issue #22
Browse files Browse the repository at this point in the history
  • Loading branch information
rehno-lindeque committed Nov 30, 2011
1 parent ad12d56 commit e69d851
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 45 deletions.
31 changes: 20 additions & 11 deletions src/compile.asm.bounds.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

compileASMBounds = (abstractSolidModel) ->
# Constants (enum)
INTERSECT = 0
UNION = 1
UNION = 0
INTERSECT = 1

preDispatch =
invert: (stack, node, flags) ->
Expand All @@ -17,31 +17,41 @@ compileASMBounds = (abstractSolidModel) ->
default: (stack, node, flags) ->
return

intersectChildren: (nodes) ->
unionChildren = (nodes) ->
bounds = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]]
for n in nodes
bounds[0][i] = Math.min n.bounds[0][i], bounds[0][i] for i in [0..2]
bounds[1][i] = Math.max n.bounds[1][i], bounds[1][i] for i in [0..2]
bounds

intersectChildren = (nodes) ->
bounds = [[-Infinity, -Infinity, -Infinity], [Infinity, Infinity, Infinity]]
for n in nodes
bounds[0][i] = Math.max n.bounds[0][i], bounds[0][i] for i in [0..2]
bounds[1][i] = Math.min n.bounds[1][i], bounds[1][i] for i in [0..2]
bounds

unionChildren: (nodes) ->
bounds = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]]
for n in nodes
bounds[0][i] = Math.min n.bounds[0][i], bounds[0][i] for i in [0..2]
bounds[1][i] = Math.max n.bounds[1][i], bounds[1][i] for i in [0..2]
bounds
collectChildren = (nodes, flags) ->
composition = flags.composition[flags.composition.length - 1]
if composition == UNION then unionChildren nodes else intersectChildren nodes

postDispatch =
invert: (stack, node, flags) ->
node.bounds = collectChildren node.nodes, flags
flags.invert = not flags.invert
stack[0].nodes.push node
union: (stack, node, flags) ->
node.bounds = collectChildren node.nodes, flags
flags.composition.pop()
stack[0].nodes.push node
intersect: (stack, node, flags) ->
node.bounds = collectChildren node.nodes, flags
flags.composition.pop()
stack[0].nodes.push node
translate: (stack, node, flags) ->
node.bounds = collectChildren node.nodes, flags
node.bounds[0][i] += node.attr.offset[i] for i in [0..2]
node.bounds[1][i] += node.attr.offset[i] for i in [0..2]
stack[0].nodes.push node
halfspace: (stack, node, flags) ->
node.bounds = [[-Infinity, -Infinity, -Infinity], [Infinity, Infinity, Infinity]]
Expand All @@ -55,9 +65,8 @@ compileASMBounds = (abstractSolidModel) ->
sphere: (stack, node, flags) ->
node.bounds = [[-node.attr.radius, -node.attr.radius, -node.attr.radius], [node.attr.radius, node.attr.radius, node.attr.radius]]
stack[0].nodes.push node
material: (stack, node, flags) ->
stack[0].nodes.push node
default: (stack, node, flags) ->
node.bounds = collectChildren node.nodes, flags
stack[0].nodes.push node

flags =
Expand Down
82 changes: 49 additions & 33 deletions static/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@
], node, flags);
};
compileASMBounds = function(abstractSolidModel) {
var INTERSECT, UNION, flags, postDispatch, preDispatch, result;
INTERSECT = 0;
UNION = 1;
var INTERSECT, UNION, collectChildren, flags, intersectChildren, postDispatch, preDispatch, result, unionChildren;
UNION = 0;
INTERSECT = 1;
preDispatch = {
invert: function(stack, node, flags) {
return flags.invert = !flags.invert;
Expand All @@ -394,50 +394,68 @@
},
"default": function(stack, node, flags) {}
};
({
intersectChildren: function(nodes) {
var bounds, i, n, _i, _len;
bounds = [[-Infinity, -Infinity, -Infinity], [Infinity, Infinity, Infinity]];
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
n = nodes[_i];
for (i = 0; i <= 2; i++) {
bounds[0][i] = Math.max(n.bounds[0][i], bounds[0][i]);
}
for (i = 0; i <= 2; i++) {
bounds[1][i] = Math.min(n.bounds[1][i], bounds[1][i]);
}
unionChildren = function(nodes) {
var bounds, i, n, _i, _len;
bounds = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
n = nodes[_i];
for (i = 0; i <= 2; i++) {
bounds[0][i] = Math.min(n.bounds[0][i], bounds[0][i]);
}
return bounds;
},
unionChildren: function(nodes) {
var bounds, i, n, _i, _len;
bounds = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
n = nodes[_i];
for (i = 0; i <= 2; i++) {
bounds[0][i] = Math.min(n.bounds[0][i], bounds[0][i]);
}
for (i = 0; i <= 2; i++) {
bounds[1][i] = Math.max(n.bounds[1][i], bounds[1][i]);
}
for (i = 0; i <= 2; i++) {
bounds[1][i] = Math.max(n.bounds[1][i], bounds[1][i]);
}
return bounds;
}
});
return bounds;
};
intersectChildren = function(nodes) {
var bounds, i, n, _i, _len;
bounds = [[-Infinity, -Infinity, -Infinity], [Infinity, Infinity, Infinity]];
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
n = nodes[_i];
for (i = 0; i <= 2; i++) {
bounds[0][i] = Math.max(n.bounds[0][i], bounds[0][i]);
}
for (i = 0; i <= 2; i++) {
bounds[1][i] = Math.min(n.bounds[1][i], bounds[1][i]);
}
}
return bounds;
};
collectChildren = function(nodes, flags) {
var composition;
composition = flags.composition[flags.composition.length - 1];
if (composition === UNION) {
return unionChildren(nodes);
} else {
return intersectChildren(nodes);
}
};
postDispatch = {
invert: function(stack, node, flags) {
node.bounds = collectChildren(node.nodes, flags);
flags.invert = !flags.invert;
return stack[0].nodes.push(node);
},
union: function(stack, node, flags) {
node.bounds = collectChildren(node.nodes, flags);
flags.composition.pop();
return stack[0].nodes.push(node);
},
intersect: function(stack, node, flags) {
node.bounds = collectChildren(node.nodes, flags);
flags.composition.pop();
return stack[0].nodes.push(node);
},
translate: function(stack, node, flags) {
var i;
node.bounds = collectChildren(node.nodes, flags);
for (i = 0; i <= 2; i++) {
node.bounds[0][i] += node.attr.offset[i];
}
for (i = 0; i <= 2; i++) {
node.bounds[1][i] += node.attr.offset[i];
}
return stack[0].nodes.push(node);
},
halfspace: function(stack, node, flags) {
Expand All @@ -455,10 +473,8 @@
node.bounds = [[-node.attr.radius, -node.attr.radius, -node.attr.radius], [node.attr.radius, node.attr.radius, node.attr.radius]];
return stack[0].nodes.push(node);
},
material: function(stack, node, flags) {
return stack[0].nodes.push(node);
},
"default": function(stack, node, flags) {
node.bounds = collectChildren(node.nodes, flags);
return stack[0].nodes.push(node);
}
};
Expand Down
Loading

0 comments on commit e69d851

Please sign in to comment.