-
Notifications
You must be signed in to change notification settings - Fork 0
/
p5.collide2d.min.js
1 lines (1 loc) · 6.06 KB
/
p5.collide2d.min.js
1
console.log("### p5.collide v0.7.1 ###"),p5.prototype._collideDebug=!1,p5.prototype.collideDebug=function(a){_collideDebug=a},p5.prototype.collideRectRect=function(a,b,c,d,e,f,g,h){return!!(a+c>=e&&a<=e+g&&b+d>=f&&b<=f+h)},p5.prototype.collideRectRectVector=function(a,b,c,d){return p5.prototype.collideRectRect(a.x,a.y,b.x,b.y,c.x,c.y,d.x,d.y)},p5.prototype.collideRectCircle=function(a,b,c,d,e,f,g){var h=e,i=f;e<a?h=a:e>a+c&&(h=a+c),f<b?i=b:f>b+d&&(i=b+d);var j=this.dist(e,f,h,i);return!!(j<=g/2)},p5.prototype.collideRectCircleVector=function(a,b,d,c){return p5.prototype.collideRectCircle(a.x,a.y,b.x,b.y,d.x,d.y,c)},p5.prototype.collideCircleCircle=function(a,b,c,d,e,f){return!!(this.dist(a,b,d,e)<=c/2+f/2)},p5.prototype.collideCircleCircleVector=function(a,b,c,d){return p5.prototype.collideCircleCircle(a.x,a.y,b,c.x,c.y,d)},p5.prototype.collidePointCircle=function(a,b,c,e,f){return!!(this.dist(a,b,c,e)<=f/2)},p5.prototype.collidePointCircleVector=function(a,b,c){return p5.prototype.collidePointCircle(a.x,a.y,b.x,b.y,c)},p5.prototype.collidePointEllipse=function(a,b,c,d,e,f){var g=e/2,h=f/2;if(a>c+g||a<c-g||b>d+h||b<d-h)return!1;var i=a-c,j=b-d,k=h*this.sqrt(this.abs(g*g-i*i))/g;return j<=k&&j>=-k},p5.prototype.collidePointEllipseVector=function(a,b,c){return p5.prototype.collidePointEllipse(a.x,a.y,b.x,b.y,c.x,c.y)},p5.prototype.collidePointRect=function(a,b,c,d,e,f){return!!(a>=c&&a<=c+e&&b>=d&&b<=d+f)},p5.prototype.collidePointRectVector=function(a,b,c){return p5.prototype.collidePointRect(a.x,a.y,b.x,b.y,c.x,c.y)},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&&h+i<=j+g)},p5.prototype.collidePointLineVector=function(a,b,c,d){return p5.prototype.collidePointLine(a.x,a.y,b.x,b.y,c.x,c.y,d)},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!!(q<=g/2)},p5.prototype.collideLineCircleVector=function(a,b,d,c){return p5.prototype.collideLineCircle(a.x,a.y,b.x,b.y,d.x,d.y,c)},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(0<=k&&1>=k&&0<=l&&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},j)}return!!i&&(j={x:!1,y:!1},j)},p5.prototype.collideLineLineVector=function(a,b,c,d,e){return p5.prototype.collideLineLine(a.x,a.y,b.x,b.y,c.x,c.y,d.x,d.y,e)},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)},p5.prototype.collideLineRectVector=function(a,b,c,d,e){return p5.prototype.collideLineRect(a.x,a.y,b.x,b.y,c.x,c.y,d.x,d.y,e)},p5.prototype.collidePointPoly=function(a,b,c){for(var d=!1,e=0,f=0;f<c.length;f++){e=f+1,e===c.length&&(e=0);var g=c[f],h=c[e];(g.y>b&&h.y<b||g.y<b&&h.y>b)&&a<(h.x-g.x)*(b-g.y)/(h.y-g.y)+g.x&&(d=!d)}return d},p5.prototype.collidePointPolyVector=function(a,b){return p5.prototype.collidePointPoly(a.x,a.y,b)},p5.prototype.collideCirclePoly=function(a,b,c,d,e){e===void 0&&(e=!1);for(var f=0,g=0;g<d.length;g++){f=g+1,f===d.length&&(f=0);var h=d[g],i=d[f],j=this.collideLineCircle(h.x,h.y,i.x,i.y,a,b,c);if(j)return!0}if(!0===e){var k=this.collidePointPoly(a,b,d);if(k)return!0}return!1},p5.prototype.collideCirclePolyVector=function(a,b,c,d){return p5.prototype.collideCirclePoly(a.x,a.y,b,c,d)},p5.prototype.collideRectPoly=function(a,b,c,d,e,f){f==null&&(f=!1);for(var g=0,h=0;h<e.length;h++){g=h+1,g===e.length&&(g=0);var i=e[h],j=e[g],k=this.collideLineRect(i.x,i.y,j.x,j.y,a,b,c,d);if(k)return!0;if(!0===f){var l=this.collidePointPoly(a,b,e);if(l)return!0}}return!1},p5.prototype.collideRectPolyVector=function(a,b,c,d){return p5.prototype.collideRectPoly(a.x,a.y,b.x,b.y,c,d)},p5.prototype.collideLinePoly=function(a,b,c,d,e){for(var f=0,g=0;g<e.length;g++){f=g+1,f===e.length&&(f=0);var h=e[g].x,i=e[g].y,j=e[f].x,k=e[f].y,l=this.collideLineLine(a,b,c,d,h,i,j,k);if(l)return!0}return!1},p5.prototype.collideLinePolyVector=function(a,b,c){return p5.prototype.collideLinePoly(a.x,a.y,b.x,b.y,c)},p5.prototype.collidePolyPoly=function(a,b,c){c===void 0&&(c=!1);for(var d=0,e=0;e<a.length;e++){d=e+1,d===a.length&&(d=0);var f=a[e],g=a[d],h=this.collideLinePoly(f.x,f.y,g.x,g.y,b);if(h)return!0;if(!0===c&&(h=this.collidePointPoly(b[0].x,b[0].y,a),h))return!0}return!1},p5.prototype.collidePolyPolyVector=function(a,b,c){return p5.prototype.collidePolyPoly(a,b,c)},p5.prototype.collidePointTriangle=function(a,b,c,d,e,f,g,h){var i=this.abs((e-c)*(h-d)-(g-c)*(f-d)),j=this.abs((c-a)*(f-b)-(e-a)*(d-b)),k=this.abs((e-a)*(h-b)-(g-a)*(f-b)),l=this.abs((g-a)*(d-b)-(c-a)*(h-b));return!(j+k+l!==i)},p5.prototype.collidePointTriangleVector=function(a,b,c,d){return p5.prototype.collidePointTriangle(a.x,a.y,b.x,b.y,c.x,c.y,d.x,d.y)},p5.prototype.collidePointPoint=function(a,b,c,d,e){return void 0===e&&(e=0),!!(this.dist(a,b,c,d)<=e)},p5.prototype.collidePointPointVector=function(a,b,c){return p5.prototype.collidePointPoint(a.x,a.y,b.x,b.y,c)},p5.prototype.collidePointArc=function(a,b,c,d,e,f,g,h){h===void 0&&(h=0);var i=this.createVector(a,b),j=this.createVector(c,d),k=this.createVector(e,0).rotate(f),l=i.copy().sub(j);if(i.dist(j)<=e+h){var m=k.dot(l),n=k.angleBetween(l);if(0<m&&n<=g/2&&n>=-g/2)return!0}return!1},p5.prototype.collidePointArcVector=function(b,c,a,d,e,f){return p5.prototype.collidePointArc(b.x,b.y,c.x,c.y,a,d,e,f)};