Navigation Menu

Skip to content

Commit

Permalink
Fix obvious inconsistencies in SegmentQuery, but it's still broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Jan 2, 2012
1 parent 3fa1936 commit 17d5615
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
24 changes: 12 additions & 12 deletions cp.js
Expand Up @@ -605,10 +605,10 @@ var bbSegmentQuery = function(bb, a, b)
var tymax = max(ty1, ty2);

if(tymin <= txmax && txmin <= tymax){
var min = max(txmin, tymin);
var max = min(txmax, tymax);
var min_ = max(txmin, tymin);
var max_ = min(txmax, tymax);

if(0.0 <= max && min <= 1.0) return max(min, 0.0);
if(0.0 <= max_ && min_ <= 1.0) return max(min_, 0.0);
}

return Infinity;
Expand Down Expand Up @@ -2120,10 +2120,10 @@ var bbTreeSegmentQuery = function(node, a, b)
var tymax = max(ty1, ty2);

if(tymin <= txmax && txmin <= tymax){
var min = max(txmin, tymin);
var max = min(txmax, tymax);
var min_ = max(txmin, tymin);
var max_ = min(txmax, tymax);

if(0.0 <= max && min <= 1.0) return max(min, 0.0);
if(0.0 <= max_ && min_ <= 1.0) return max(min_, 0.0);
}

return Infinity;
Expand All @@ -2138,11 +2138,11 @@ var subtreeSegmentQuery = function(subtree, a, b, t_exit, func)
var t_b = bbTreeSegmentQuery(subtree.B, a, b);

if(t_a < t_b){
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func, data));
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func, data));
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func));
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func));
} else {
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func, data));
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func, data));
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func));
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func));
}

return t_exit;
Expand Down Expand Up @@ -2367,7 +2367,7 @@ BBTree.prototype.pointQuery = function(point, func)

BBTree.prototype.segmentQuery = function(a, b, t_exit, func)
{
if(this.root) subtreeSegmentQuery(this, a, b, t_exit, func);
if(this.root) subtreeSegmentQuery(this.root, a, b, t_exit, func);
};

BBTree.prototype.query = function(bb, func)
Expand Down Expand Up @@ -4227,7 +4227,7 @@ Space.prototype.segmentQuery = function(start, end, layers, group, func)
/// Perform a directed line segment query (like a raycast) against the space and return the first shape hit. Returns null if no shapes were hit.
Space.prototype.segmentQueryFirst = function(start, end, layers, group)
{
var out = null;
var out = new SegmentQueryInfo(null, 1, vzero);

var helper = function(shape){
var info;
Expand Down
4 changes: 2 additions & 2 deletions cp.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/cpBB.js
Expand Up @@ -123,10 +123,10 @@ var bbSegmentQuery = function(bb, a, b)
var tymax = max(ty1, ty2);

if(tymin <= txmax && txmin <= tymax){
var min = max(txmin, tymin);
var max = min(txmax, tymax);
var min_ = max(txmin, tymin);
var max_ = min(txmax, tymax);

if(0.0 <= max && min <= 1.0) return max(min, 0.0);
if(0.0 <= max_ && min_ <= 1.0) return max(min_, 0.0);
}

return Infinity;
Expand Down
16 changes: 8 additions & 8 deletions lib/cpBBTree.js
Expand Up @@ -360,10 +360,10 @@ var bbTreeSegmentQuery = function(node, a, b)
var tymax = max(ty1, ty2);

if(tymin <= txmax && txmin <= tymax){
var min = max(txmin, tymin);
var max = min(txmax, tymax);
var min_ = max(txmin, tymin);
var max_ = min(txmax, tymax);

if(0.0 <= max && min <= 1.0) return max(min, 0.0);
if(0.0 <= max_ && min_ <= 1.0) return max(min_, 0.0);
}

return Infinity;
Expand All @@ -378,11 +378,11 @@ var subtreeSegmentQuery = function(subtree, a, b, t_exit, func)
var t_b = bbTreeSegmentQuery(subtree.B, a, b);

if(t_a < t_b){
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func, data));
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func, data));
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func));
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func));
} else {
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func, data));
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func, data));
if(t_b < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.B, a, b, t_exit, func));
if(t_a < t_exit) t_exit = min(t_exit, subtreeSegmentQuery(subtree.A, a, b, t_exit, func));
}

return t_exit;
Expand Down Expand Up @@ -607,7 +607,7 @@ BBTree.prototype.pointQuery = function(point, func)

BBTree.prototype.segmentQuery = function(a, b, t_exit, func)
{
if(this.root) subtreeSegmentQuery(this, a, b, t_exit, func);
if(this.root) subtreeSegmentQuery(this.root, a, b, t_exit, func);
};

BBTree.prototype.query = function(bb, func)
Expand Down
2 changes: 1 addition & 1 deletion lib/cpSpaceQuery.js
Expand Up @@ -73,7 +73,7 @@ Space.prototype.segmentQuery = function(start, end, layers, group, func)
/// Perform a directed line segment query (like a raycast) against the space and return the first shape hit. Returns null if no shapes were hit.
Space.prototype.segmentQueryFirst = function(start, end, layers, group)
{
var out = null;
var out = new SegmentQueryInfo(null, 1, vzero);

var helper = function(shape){
var info;
Expand Down

0 comments on commit 17d5615

Please sign in to comment.