Skip to content

Commit

Permalink
queer done
Browse files Browse the repository at this point in the history
  • Loading branch information
interl0per committed Dec 8, 2015
1 parent 5f7a4a9 commit a50a161
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 43 deletions.
11 changes: 10 additions & 1 deletion RangeApp/RangeApp.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -78,6 +84,9 @@ void keyPressed() {
case 'e':
case 'E':
drawGnoman = !drawGnoman;
break;
case '1':

break;
}
}
Expand Down Expand Up @@ -129,4 +138,4 @@ void mouseReleased() {
if(mouseButton == RIGHT) {
cam.mouseReleased();
}
}
}
15 changes: 11 additions & 4 deletions RangeApp/Selector.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point> solution = pot.getTree().query(new BoundingBox(p1._x, p1._y, p2._x, p2._y));
println("size of list: %d", solution.size());
ArrayList<Point> 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)),
Expand Down Expand Up @@ -111,4 +118,4 @@ class Selector{
_searching = false;
}
}
}
}
5 changes: 3 additions & 2 deletions RangeApp/Tests.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,4 +30,4 @@ ArrayList<Point> merge(ArrayList<Point> a, ArrayList<Point> b) {
for(Point p : b)
a.add(p);
return a;
}
}
25 changes: 16 additions & 9 deletions RangeApp/Tree.pde
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ class KdTree {
ArrayList<Point> rightRes = new ArrayList<Point>();
ArrayList<Point> leftRes = new ArrayList<Point>();

if(isLeaf() && inBox(_loc, range)) {
rightRes.add(_loc);
return rightRes;
if(inBox(_loc, range)) {
rightRes.add(_loc);
}

if(_left != null) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)));
}
}


}
51 changes: 24 additions & 27 deletions RangeApp/circleTests.pde
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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; }
}
}



}

0 comments on commit a50a161

Please sign in to comment.