diff --git a/CHANGELOG.md b/CHANGELOG.md index 5537423..e5b7ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ ## In development +## 0.6.0 (Sept 11, 2016) + - Fix "Vornoi" -> "Voronoi" everywhere. Changes are all in private code, no functional changes. (Fixes #27) + - Exposed isSeparatingAxis() function - thanks [hexus](https://github.com/hexus)! + - Allow pointInPolygon to work with small polygons. (Fixes #41) ## 0.5.0 (Dec 26, 2014) diff --git a/README.md b/README.md index de81ca5..dce038e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ It also supports checking whether a point is inside a circle or polygon. It's released under the [MIT](http://en.wikipedia.org/wiki/MIT_License) license. -Current version: `0.5.0`. [Annotated source code](http://jriecken.github.io/sat-js/docs/SAT.html) is available. +Current version: `0.6.0`. [Annotated source code](http://jriecken.github.io/sat-js/docs/SAT.html) is available. Nicely compresses with the [Google Closure Compiler](https://developers.google.com/closure/compiler/) in **Advanced** mode to about 6KB (2KB gzipped) diff --git a/SAT.js b/SAT.js index 1fffbbe..164b3e9 100644 --- a/SAT.js +++ b/SAT.js @@ -1,10 +1,10 @@ -// Version 0.5.0 - Copyright 2012 - 2015 - Jim Riecken +// Version 0.6.0 - Copyright 2012 - 2016 - Jim Riecken // // Released under the MIT License - https://github.com/jriecken/sat-js // // A simple library for determining intersections of circles and // polygons using the Separating Axis Theorem. -/** @preserve SAT.js - Version 0.5.0 - Copyright 2012 - 2015 - Jim Riecken - released under the MIT License. https://github.com/jriecken/sat-js */ +/** @preserve SAT.js - Version 0.6.0 - Copyright 2012 - 2016 - Jim Riecken - released under the MIT License. https://github.com/jriecken/sat-js */ /*global define: false, module: false*/ /*jshint shadow:true, sub:true, forin:true, noarg:true, noempty:true, diff --git a/SAT.min.js b/SAT.min.js index 43691bb..b2531e1 100644 --- a/SAT.min.js +++ b/SAT.min.js @@ -1,14 +1,14 @@ -/* SAT.js - Version 0.5.0 - Copyright 2012 - 2015 - Jim Riecken - released under the MIT License. https://github.com/jriecken/sat-js */ -function x(){function c(a,e){this.x=a||0;this.y=e||0}function A(a,e){this.pos=a||new c;this.r=e||0}function m(a,e){this.pos=a||new c;this.angle=0;this.offset=new c;this.m(e||[])}function r(a,e,b){this.pos=a||new c;this.w=e||0;this.h=b||0}function w(){this.b=this.a=null;this.overlapN=new c;this.overlapV=new c;this.clear()}function B(a,e,b){for(var f=Number.MAX_VALUE,c=-Number.MAX_VALUE,k=a.length,h=0;hc&&(c=d)}b[0]=f;b[1]=c}function C(a,e,b,f,c,k){var h=t.pop(), -d=t.pop();a=g.pop().c(e).sub(a);e=a.d(c);B(b,c,h);B(f,c,d);d[0]+=e;d[1]+=e;if(h[0]>d[1]||d[0]>h[1])return g.push(a),t.push(h),t.push(d),!0;k&&(b=0,h[0]d[1]?(b=h[0]-d[1],k.aInB=!1):(b=h[1]-d[0],f=d[1]-h[0],b=bb&&k.overlapN.reverse()));g.push(a);t.push(h);t.push(d);return!1}function y(a,e){var b=a.e(),c=e.d(a);return 0>c?-1:c>b? -1:0}function D(a,e,b){for(var c=g.pop().c(e.pos).sub(a.pos),l=e.r,k=l*l,h=a.calcPoints,d=h.length,v=g.pop(),q=g.pop(),n=0;nk&&(b.aInB=!1);var p=y(v,q);if(-1===p){v.c(a.edges[t]);m=g.pop().c(c).sub(h[t]);p=y(v,m);if(1===p){p=q.g();if(p>l)return g.push(c),g.push(v),g.push(q),g.push(m),!1;b&&(b.bInA=!1,u=q.normalize(),r=l-p)}g.push(m)}else if(1===p){if(v.c(a.edges[m]),q.c(c).sub(h[m]),p=y(v,q),-1===p){p= -q.g();if(p>l)return g.push(c),g.push(v),g.push(q),!1;b&&(b.bInA=!1,u=q.normalize(),r=l-p)}}else{m=v.j().normalize();p=q.d(m);t=Math.abs(p);if(0l)return g.push(c),g.push(m),g.push(q),!1;b&&(u=m,r=l-p,0<=p||r<2*l)&&(b.bInA=!1)}u&&b&&Math.abs(r)g&&(g=d.x);d.yk&&(k=d.y)}return(new r(this.pos.clone().add(new c(b,f)),g-b,k-f)).i()};n.Box=r;r.prototype.toPolygon=r.prototype.i= -function(){var a=this.pos,e=this.w,b=this.h;return new m(new c(a.x,a.y),[new c,new c(e,0),new c(e,b),new c(0,b)])};n.Response=w;w.prototype.clear=w.prototype.clear=function(){this.bInA=this.aInB=!0;this.overlap=Number.MAX_VALUE;return this};for(var g=[],u=0;10>u;u++)g.push(new c);for(var t=[],u=0;5>u;u++)t.push([]);var z=new w,F=(new r(new c,1,1)).i();n.pointInCircle=function(a,c){var b=g.pop().c(a).sub(c.pos),f=c.r*c.r,l=b.e();g.push(b);return l<=f};n.pointInPolygon=function(a,c){F.pos.c(a);z.clear(); -var b=E(F,c,z);b&&(b=z.aInB);return b};n.testCircleCircle=function(a,c,b){var f=g.pop().c(c.pos).sub(a.pos),l=a.r+c.r,k=f.e();if(k>l*l)return g.push(f),!1;b&&(k=Math.sqrt(k),b.a=a,b.b=c,b.overlap=l-k,b.overlapN.c(f.normalize()),b.overlapV.c(f).scale(b.overlap),b.aInB=a.r<=c.r&&k<=c.r-a.r,b.bInA=c.r<=a.r&&k<=a.r-c.r);g.push(f);return!0};n.testPolygonCircle=D;n.testCirclePolygon=function(a,c,b){if((a=D(c,a,b))&&b){c=b.a;var f=b.aInB;b.overlapN.reverse();b.overlapV.reverse();b.a=b.b;b.b=c;b.aInB=b.bInA; -b.bInA=f}return a};n.testPolygonPolygon=E;return n}"function"===typeof define&&define.amd?define(x):"object"===typeof exports?module.exports=x():this.SAT=x(); \ No newline at end of file +/* SAT.js - Version 0.6.0 - Copyright 2012 - 2016 - Jim Riecken - released under the MIT License. https://github.com/jriecken/sat-js */ +function x(){function c(a,e){this.x=a||0;this.y=e||0}function B(a,e){this.pos=a||new c;this.r=e||0}function n(a,e){this.pos=a||new c;this.angle=0;this.offset=new c;this.u(e||[])}function q(a,e,b){this.pos=a||new c;this.w=e||0;this.h=b||0}function w(){this.b=this.a=null;this.overlapN=new c;this.overlapV=new c;this.clear()}function C(a,e,b){for(var h=Number.MAX_VALUE,c=-Number.MAX_VALUE,k=a.length,g=0;gc&&(c=d)}b[0]=h;b[1]=c}function y(a,e,b,h,c,k){var g=r.pop(), +d=r.pop();a=m.pop().c(e).sub(a);e=a.f(c);C(b,c,g);C(h,c,d);d[0]+=e;d[1]+=e;if(g[0]>d[1]||d[0]>g[1])return m.push(a),r.push(g),r.push(d),!0;k&&(g[0]d[1]?(b=g[0]-d[1],k.aInB=!1):(b=g[1]-d[0],h=d[1]-g[0],b=bb&&k.overlapN.reverse()));m.push(a);r.push(g);r.push(d);return!1}function z(a,e){var b=a.g(),c=e.f(a);return 0>c?-1:c>b?1:0} +function D(a,e,b){for(var c=m.pop().c(e.pos).sub(a.pos),l=e.r,k=l*l,g=a.calcPoints,d=g.length,u=m.pop(),f=m.pop(),n=0;nk&&(b.aInB=!1);var p=z(u,f);if(-1===p){u.c(a.edges[r]);v=m.pop().c(c).sub(g[r]);p=z(u,v);if(1===p){p=f.j();if(p>l)return m.push(c),m.push(u),m.push(f),m.push(v),!1;b&&(b.bInA=!1,t=f.normalize(),q=l-p)}m.push(v)}else if(1===p){if(u.c(a.edges[v]),f.c(c).sub(g[v]),p=z(u,f),-1===p){p=f.j(); +if(p>l)return m.push(c),m.push(u),m.push(f),!1;b&&(b.bInA=!1,t=f.normalize(),q=l-p)}}else{v=u.m().normalize();p=f.f(v);r=Math.abs(p);if(0l)return m.push(c),m.push(v),m.push(f),!1;b&&(t=v,q=l-p,0<=p||q<2*l)&&(b.bInA=!1)}t&&b&&Math.abs(q)f&&(f=d.x);d.yk&&(k=d.y)}return(new q(this.pos.clone().add(new c(b,h)),f-b,k-h)).l()};f.Box=q;q.prototype.toPolygon=q.prototype.l= +function(){var a=this.pos,e=this.w,b=this.h;return new n(new c(a.x,a.y),[new c,new c(e,0),new c(e,b),new c(0,b)])};f.Response=w;w.prototype.clear=w.prototype.clear=function(){this.bInA=this.aInB=!0;this.overlap=Number.MAX_VALUE;return this};for(var m=[],t=0;10>t;t++)m.push(new c);for(var r=[],t=0;5>t;t++)r.push([]);var A=new w,F=(new q(new c,1E-6,1E-6)).l();f.isSeparatingAxis=y;f.pointInCircle=function(a,c){var b=m.pop().c(a).sub(c.pos),h=c.r*c.r,f=b.g();m.push(b);return f<=h};f.pointInPolygon=function(a, +c){F.pos.c(a);A.clear();var b=E(F,c,A);b&&(b=A.aInB);return b};f.testCircleCircle=function(a,c,b){var f=m.pop().c(c.pos).sub(a.pos),l=a.r+c.r,k=f.g();if(k>l*l)return m.push(f),!1;b&&(k=Math.sqrt(k),b.a=a,b.b=c,b.overlap=l-k,b.overlapN.c(f.normalize()),b.overlapV.c(f).scale(b.overlap),b.aInB=a.r<=c.r&&k<=c.r-a.r,b.bInA=c.r<=a.r&&k<=a.r-c.r);m.push(f);return!0};f.testPolygonCircle=D;f.testCirclePolygon=function(a,c,b){if((a=D(c,a,b))&&b){c=b.a;var f=b.aInB;b.overlapN.reverse();b.overlapV.reverse(); +b.a=b.b;b.b=c;b.aInB=b.bInA;b.bInA=f}return a};f.testPolygonPolygon=E;return f}"function"===typeof define&&define.amd?define(x):"object"===typeof exports?module.exports=x():this.SAT=x(); \ No newline at end of file diff --git a/package.json b/package.json index 13d295f..29a30e8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sat", "description": "Library for performing 2D collision detection", - "version": "0.5.0", + "version": "0.6.0", "author": "Jim Riecken ", "keywords": [ "collision detection",