From 66d44ed0524eba3dbb7f429c11f38acfb5d67125 Mon Sep 17 00:00:00 2001 From: David Granstrom Date: Tue, 6 Jun 2017 15:11:21 +0200 Subject: [PATCH 1/2] Use angleBetween instance method --- p5.collide2d.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p5.collide2d.js b/p5.collide2d.js index f076054..9b5b017 100644 --- a/p5.collide2d.js +++ b/p5.collide2d.js @@ -402,7 +402,7 @@ p5.prototype.collidePointArc = function(px, py, ax, ay, arcRadius, arcHeading, a if (point.dist(arcPos) <= (arcRadius + buffer)) { var dot = radius.dot(pointToArc); - var angle = p5.Vector.angleBetween(radius, pointToArc); + var angle = radius.angleBetween(pointToArc); if (dot > 0 && angle <= arcAngle / 2 && angle >= -arcAngle / 2) { return true; } From e24063a85b4b94495c1f06ead026fe8abb0119e7 Mon Sep 17 00:00:00 2001 From: David Granstrom Date: Tue, 6 Jun 2017 15:13:22 +0200 Subject: [PATCH 2/2] Update minified version --- p5.collide2d.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p5.collide2d.min.js b/p5.collide2d.min.js index 1974212..b672e48 100644 --- a/p5.collide2d.min.js +++ b/p5.collide2d.min.js @@ -1 +1 @@ -console.log("### p5.collide ###");p5.prototype._collideDebug=false;p5.prototype.collideDebug=function(debugMode){_collideDebug=debugMode};p5.prototype.collideRectRect=function(x,y,w,h,x2,y2,w2,h2){if(x+w>=x2&&x<=x2+w2&&y+h>=y2&&y<=y2+h2){return true}return false};p5.prototype.collideRectCircle=function(rx,ry,rw,rh,cx,cy,diameter){var testX=cx;var testY=cy;if(cxrx+rw){testX=rx+rw}if(cyry+rh){testY=ry+rh}var distance=this.dist(cx,cy,testX,testY);if(distance<=diameter/2){return true}return false};p5.prototype.collideCircleCircle=function(x,y,d,x2,y2,d2){if(this.dist(x,y,x2,y2)<=d/2+d2/2){return true}return false};p5.prototype.collidePointCircle=function(x,y,cx,cy,d){if(this.dist(x,y,cx,cy)<=d/2){return true}return false};p5.prototype.collidePointRect=function(pointX,pointY,x,y,xW,yW){if(pointX>=x&&pointX<=x+xW&&pointY>=y&&pointY<=y+yW){return true}return false};p5.prototype.collidePointLine=function(px,py,x1,y1,x2,y2,buffer){var d1=this.dist(px,py,x1,y1);var d2=this.dist(px,py,x2,y2);var lineLen=this.dist(x1,y1,x2,y2);if(buffer===undefined){buffer=.1}if(d1+d2>=lineLen-buffer&&d1+d2<=lineLen+buffer){return true}return false};p5.prototype.collideLineCircle=function(x1,y1,x2,y2,cx,cy,diameter){var inside1=this.collidePointCircle(x1,y1,cx,cy,diameter);var inside2=this.collidePointCircle(x2,y2,cx,cy,diameter);if(inside1||inside2)return true;var distX=x1-x2;var distY=y1-y2;var len=this.sqrt(distX*distX+distY*distY);var dot=((cx-x1)*(x2-x1)+(cy-y1)*(y2-y1))/this.pow(len,2);var closestX=x1+dot*(x2-x1);var closestY=y1+dot*(y2-y1);var onSegment=this.collidePointLine(closestX,closestY,x1,y1,x2,y2);if(!onSegment)return false;if(this._collideDebug){this.ellipse(closestX,closestY,10,10)}distX=closestX-cx;distY=closestY-cy;var distance=this.sqrt(distX*distX+distY*distY);if(distance<=diameter/2){return true}return false};p5.prototype.collideLineLine=function(x1,y1,x2,y2,x3,y3,x4,y4,calcIntersection){var intersection;var uA=((x4-x3)*(y1-y3)-(y4-y3)*(x1-x3))/((y4-y3)*(x2-x1)-(x4-x3)*(y2-y1));var uB=((x2-x1)*(y1-y3)-(y2-y1)*(x1-x3))/((y4-y3)*(x2-x1)-(x4-x3)*(y2-y1));if(uA>=0&&uA<=1&&uB>=0&&uB<=1){if(this._collideDebug||calcIntersection){var intersectionX=x1+uA*(x2-x1);var intersectionY=y1+uA*(y2-y1)}if(this._collideDebug){this.ellipse(intersectionX,intersectionY,10,10)}if(calcIntersection){intersection={x:intersectionX,y:intersectionY};return intersection}else{return true}}if(calcIntersection){intersection={x:false,y:false};return intersection}return false};p5.prototype.collideLineRect=function(x1,y1,x2,y2,rx,ry,rw,rh,calcIntersection){var left,right,top,bottom,intersection;if(calcIntersection){left=this.collideLineLine(x1,y1,x2,y2,rx,ry,rx,ry+rh,true);right=this.collideLineLine(x1,y1,x2,y2,rx+rw,ry,rx+rw,ry+rh,true);top=this.collideLineLine(x1,y1,x2,y2,rx,ry,rx+rw,ry,true);bottom=this.collideLineLine(x1,y1,x2,y2,rx,ry+rh,rx+rw,ry+rh,true);intersection={left:left,right:right,top:top,bottom:bottom}}else{left=this.collideLineLine(x1,y1,x2,y2,rx,ry,rx,ry+rh);right=this.collideLineLine(x1,y1,x2,y2,rx+rw,ry,rx+rw,ry+rh);top=this.collideLineLine(x1,y1,x2,y2,rx,ry,rx+rw,ry);bottom=this.collideLineLine(x1,y1,x2,y2,rx,ry+rh,rx+rw,ry+rh)}if(left||right||top||bottom){if(calcIntersection){return intersection}return true}return false};p5.prototype.collidePointPoly=function(px,py,vertices){var collision=false;var next=0;for(var current=0;currentpy&&vn.ypy)&&px<(vn.x-vc.x)*(py-vc.y)/(vn.y-vc.y)+vc.x){collision=!collision}}return collision};p5.prototype.collideCirclePoly=function(cx,cy,diameter,vertices,interior){if(interior==undefined){interior=false}var next=0;for(var current=0;current=e&&e+g>=a&&b+d>=f&&f+h>=b?!0:!1},p5.prototype.collideRectCircle=function(a,b,c,d,e,f,g){var h=e,i=f;a>e?h=a:e>a+c&&(h=a+c),b>f?i=b:f>b+d&&(i=b+d);var j=this.dist(e,f,h,i);return g/2>=j?!0:!1},p5.prototype.collideCircleCircle=function(a,b,c,d,e,f){return this.dist(a,b,d,e)<=c/2+f/2?!0:!1},p5.prototype.collidePointCircle=function(a,b,c,d,e){return this.dist(a,b,c,d)<=e/2?!0:!1},p5.prototype.collidePointRect=function(a,b,c,d,e,f){return a>=c&&c+e>=a&&b>=d&&d+f>=b?!0:!1},p5.prototype.collidePointLine=function(a,b,c,d,e,f,g){var h=this.dist(a,b,c,d),i=this.dist(a,b,e,f),j=this.dist(c,d,e,f);return void 0===g&&(g=.1),h+i>=j-g&&j+g>=h+i?!0:!1},p5.prototype.collideLineCircle=function(a,b,c,d,e,f,g){var h=this.collidePointCircle(a,b,e,f,g),i=this.collidePointCircle(c,d,e,f,g);if(h||i)return!0;var j=a-c,k=b-d,l=this.sqrt(j*j+k*k),m=((e-a)*(c-a)+(f-b)*(d-b))/this.pow(l,2),n=a+m*(c-a),o=b+m*(d-b),p=this.collidePointLine(n,o,a,b,c,d);if(!p)return!1;this._collideDebug&&this.ellipse(n,o,10,10),j=n-e,k=o-f;var q=this.sqrt(j*j+k*k);return g/2>=q?!0:!1},p5.prototype.collideLineLine=function(a,b,c,d,e,f,g,h,i){var j,k=((g-e)*(b-f)-(h-f)*(a-e))/((h-f)*(c-a)-(g-e)*(d-b)),l=((c-a)*(b-f)-(d-b)*(a-e))/((h-f)*(c-a)-(g-e)*(d-b));if(k>=0&&1>=k&&l>=0&&1>=l){if(this._collideDebug||i)var m=a+k*(c-a),n=b+k*(d-b);return this._collideDebug&&this.ellipse(m,n,10,10),i?j={x:m,y:n}:!0}return i?j={x:!1,y:!1}:!1},p5.prototype.collideLineRect=function(a,b,c,d,e,f,g,h,i){var j,k,l,m,n;return i?(j=this.collideLineLine(a,b,c,d,e,f,e,f+h,!0),k=this.collideLineLine(a,b,c,d,e+g,f,e+g,f+h,!0),l=this.collideLineLine(a,b,c,d,e,f,e+g,f,!0),m=this.collideLineLine(a,b,c,d,e,f+h,e+g,f+h,!0),n={left:j,right:k,top:l,bottom:m}):(j=this.collideLineLine(a,b,c,d,e,f,e,f+h),k=this.collideLineLine(a,b,c,d,e+g,f,e+g,f+h),l=this.collideLineLine(a,b,c,d,e,f,e+g,f),m=this.collideLineLine(a,b,c,d,e,f+h,e+g,f+h)),j||k||l||m?i?n:!0:!1},p5.prototype.collidePointPoly=function(a,b,c){for(var d=!1,e=0,f=0;fb&&h.yb)&&a<(h.x-g.x)*(b-g.y)/(h.y-g.y)+g.x&&(d=!d)}return d},p5.prototype.collideCirclePoly=function(a,b,c,d,e){void 0==e&&(e=!1);for(var f=0,g=0;g0&&g/2>=n&&n>=-g/2)return!0}return!1}; \ No newline at end of file