From a50a16158646640e952b6605facb9040d32bf826 Mon Sep 17 00:00:00 2001 From: interl0per Date: Tue, 8 Dec 2015 14:46:13 -0500 Subject: [PATCH] queer done --- RangeApp/RangeApp.pde | 11 ++++++++- RangeApp/Selector.pde | 15 ++++++++---- RangeApp/Tests.pde | 5 ++-- RangeApp/Tree.pde | 25 +++++++++++++------- RangeApp/circleTests.pde | 51 +++++++++++++++++++--------------------- 5 files changed, 64 insertions(+), 43 deletions(-) diff --git a/RangeApp/RangeApp.pde b/RangeApp/RangeApp.pde index 0009be1..ceb3bce 100644 --- a/RangeApp/RangeApp.pde +++ b/RangeApp/RangeApp.pde @@ -22,6 +22,12 @@ void setup() { drawGnoman = true; drawTreeRelations = true; drawTreeBoundaries = true; + + + BoundingBox tb = new BoundingBox(0,100, 0,100); + BoundingBox tb2 = new BoundingBox(50, 150, 50, 150); + + println(contains(tb,tb2)); } void draw() { @@ -78,6 +84,9 @@ void keyPressed() { case 'e': case 'E': drawGnoman = !drawGnoman; + break; + case '1': + break; } } @@ -129,4 +138,4 @@ void mouseReleased() { if(mouseButton == RIGHT) { cam.mouseReleased(); } -} +} \ No newline at end of file diff --git a/RangeApp/Selector.pde b/RangeApp/Selector.pde index fc324f7..d62d5c4 100644 --- a/RangeApp/Selector.pde +++ b/RangeApp/Selector.pde @@ -46,10 +46,17 @@ class Selector{ switch(_select_mode){ case 0: Point p1 = cam.transform(new Point(_startX, _startY)); - Point p2 = cam.transform(new Point(_endX, _endY)); + Point p2 = cam.transform(new Point(_endX+_startX, _endY+_startY)); + // ellipse(p2._x, p2._y, 10, 10); + // println(p2._x + " " + p2._y); + //println(_endX + " " + _endY); if(pot.getTree() != null){//prevents query of null/empty tree - ArrayList solution = pot.getTree().query(new BoundingBox(p1._x, p1._y, p2._x, p2._y)); - println("size of list: %d", solution.size()); + ArrayList solution = pot.getTree().query(new BoundingBox(min(p1._x, p2._x), max(p1._x, p2._x), min(p1._y, p2._y), max(p1._y, p2._y))); + for(Point pp : solution) + { + ellipse(pp._x + width/2, pp._y + height/2, 30, 30); + } + println("size of list: " + solution.size()); } break; case 1: //_tree.circleQuery(cam.transform(new Point(_a,_b)), @@ -111,4 +118,4 @@ class Selector{ _searching = false; } } -} +} \ No newline at end of file diff --git a/RangeApp/Tests.pde b/RangeApp/Tests.pde index ee1daed..3e9873d 100644 --- a/RangeApp/Tests.pde +++ b/RangeApp/Tests.pde @@ -16,7 +16,8 @@ boolean contains(BoundingBox a, BoundingBox b) boolean intersects(BoundingBox a, BoundingBox b) { - return ((a.x1 <= b.x2 && a.x1 >= b.x1) || (a.x1 <= b.x2 && a.x1 >= b.x1)) &&((a.y1 <= b.y2 && a.y1 >= b.y1) || (a.y1 <= b.y2 && a.y1 >= b.y1)); + if(contains(a,b) || contains(b,a)) return true; + return ((a.x1 <= b.x2 && a.x1 >= b.x1 && a.y1 <= b.y2 && a.y2 >= b.y1) || (b.x1 <= a.x2 && b.x1 >= a.x1 && b.y1 <= a.y2 && b.y2 >= b.y1)); } boolean inBox(Point p, BoundingBox a) @@ -29,4 +30,4 @@ ArrayList merge(ArrayList a, ArrayList b) { for(Point p : b) a.add(p); return a; -} +} \ No newline at end of file diff --git a/RangeApp/Tree.pde b/RangeApp/Tree.pde index f3b35b4..fcf5ba0 100644 --- a/RangeApp/Tree.pde +++ b/RangeApp/Tree.pde @@ -98,9 +98,8 @@ class KdTree { ArrayList rightRes = new ArrayList(); ArrayList leftRes = new ArrayList(); - if(isLeaf() && inBox(_loc, range)) { - rightRes.add(_loc); - return rightRes; + if(inBox(_loc, range)) { + rightRes.add(_loc); } if(_left != null) { @@ -114,10 +113,10 @@ class KdTree { if(_right != null) { if(contains(range, _right._bb)) { - rightRes = _right.report(); + rightRes = merge(_right.report(), rightRes); } else if(intersects(_right._bb, range)) { - rightRes = _right.query(range); + rightRes = merge(_right.query(range), rightRes); } } return merge(rightRes, leftRes); @@ -126,7 +125,17 @@ class KdTree { boolean isLeaf() { return _left==null && _right==null; } - + void dbg(BoundingBox q) + { + if(inBox(_loc, q)) + println(this); + if(_left!=null) + { + _left.dbg(q); + } + if(_right != null) + _right.dbg(q); + } void drawRelations() { pushStyle(); strokeWeight(i_relationWidth); @@ -217,6 +226,4 @@ class KdTree { float d = depth * 0.2; return color((int)255*abs(sin(d + 0.3)), (int)255*abs(sin(d+3.0)), (int)255*abs(sin(d+0.7))); } -} - - +} \ No newline at end of file diff --git a/RangeApp/circleTests.pde b/RangeApp/circleTests.pde index dc450e9..45090ad 100644 --- a/RangeApp/circleTests.pde +++ b/RangeApp/circleTests.pde @@ -1,27 +1,27 @@ -import javax.vecmath.Vector2d; - -boolean rectCircleIntersect(BoundingBox bb, Point p, float r){ - if( inBox(p, bb) ){ return true; } //circle center in rect - else if(lineIntersectsCircle (bb.x1, bb.y1, bb.x1, bb.y2, p._x, p._y, r)){ return true; }//left:bottom->top - else if(lineIntersectsCircle (bb.x1, bb.y2, bb.x2, bb.y2, p._x, p._y, r)){ return true; }//top:left->right - else if(lineIntersectsCircle (bb.x2, bb.y1, bb.x2, bb.y2, p._x, p._y, r)){ return true; }//right:bottom->top - else if(lineIntersectsCircle (bb.x1, bb.y1, bb.x2, bb.y1, p._x, p._y, r)){ return true; }//bottom: left->right - else{ return false; } -} - -boolean lineIntersectsCircle(float a1, float a2, float b1, float b2, float c1, float c2, float r) { - Vector2d v = new Vector2d((double)b1-a1, (double)b2-a2); - Vector2d c = new Vector2d((double)c1-a1, (double)c2-a2); - double dpT = v.dot(c);//numerator of projection - double dpB = c.dot(c);//denominator of projection - double projScalar = dpT/dpB;//the - double orthX = c1-projScalar*(b1-a1); - double orthY = c2-projScalar*(b2-a2); - if( !online(0,) ){return true; - if( distance(orthX, orthY, (double)c1-a1, (double)c2-a2) < r ) return true; -return false; -} +//import javax.vecmath.Vector2d; + +//boolean rectCircleIntersect(BoundingBox bb, Point p, float r){ +// if( inBox(p, bb) ){ return true; } //circle center in rect +// else if(lineIntersectsCircle (bb.x1, bb.y1, bb.x1, bb.y2, p._x, p._y, r)){ return true; }//left:bottom->top +// else if(lineIntersectsCircle (bb.x1, bb.y2, bb.x2, bb.y2, p._x, p._y, r)){ return true; }//top:left->right +// else if(lineIntersectsCircle (bb.x2, bb.y1, bb.x2, bb.y2, p._x, p._y, r)){ return true; }//right:bottom->top +// else if(lineIntersectsCircle (bb.x1, bb.y1, bb.x2, bb.y1, p._x, p._y, r)){ return true; }//bottom: left->right +// else{ return false; } +//} + +//boolean lineIntersectsCircle(float a1, float a2, float b1, float b2, float c1, float c2, float r) { +// Vector2d v = new Vector2d((double)b1-a1, (double)b2-a2); +// Vector2d c = new Vector2d((double)c1-a1, (double)c2-a2); +// double dpT = v.dot(c);//numerator of projection +// double dpB = c.dot(c);//denominator of projection +// double projScalar = dpT/dpB;//the +// double orthX = c1-projScalar*(b1-a1); +// double orthY = c2-projScalar*(b2-a2); +// //if( !onLine(0) ){return true; +// if( distance(orthX, orthY, (double)c1-a1, (double)c2-a2) < r ) return true; +//return false; +//} double distance(double x1, double y1, double x2, double y2){ float t1 = (float)x2-(float)x1; @@ -38,7 +38,4 @@ boolean onLine(double a1, double a2, double b1, double b2, double p1, double p2) if( a1<=p1 && p1<=b1 ){ return true; } else{ return false; } } -} - - - +} \ No newline at end of file