From e521cecf3c99093e9d9d85ecc74c07b52ce86059 Mon Sep 17 00:00:00 2001 From: Jim Riecken Date: Sat, 17 Feb 2018 11:12:44 -0800 Subject: [PATCH] Release 0.7.0 --- CHANGELOG.md | 5 ++++- README.md | 2 +- SAT.js | 4 ++-- SAT.min.js | 29 +++++++++++++++-------------- package.json | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b7ef1..c99aa34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog -## In development +## O.7.0 (Feb 17, 2018) + +- Add `getCentroid` method to `Polygon` that computes the [centroid](https://en.wikipedia.org/wiki/Centroid#Centroid_of_a_polygon). (Fixes #50) + - Useful for computing the center of a polygon if you want to rotate around it. ## 0.6.0 (Sept 11, 2016) diff --git a/README.md b/README.md index dce038e..de7dff7 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.6.0`. [Annotated source code](http://jriecken.github.io/sat-js/docs/SAT.html) is available. +Current version: `0.7.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 f7a9a84..f122409 100644 --- a/SAT.js +++ b/SAT.js @@ -1,10 +1,10 @@ -// Version 0.6.0 - Copyright 2012 - 2018 - Jim Riecken +// Version 0.7.0 - Copyright 2012 - 2018 - 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.6.0 - Copyright 2012 - 2018 - Jim Riecken - released under the MIT License. https://github.com/jriecken/sat-js */ +/** @preserve SAT.js - Version 0.7.0 - Copyright 2012 - 2018 - 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 b2531e1..9abfc5b 100644 --- a/SAT.min.js +++ b/SAT.min.js @@ -1,14 +1,15 @@ -/* 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 +/* + SAT.js - Version 0.7.0 - Copyright 2012 - 2018 - Jim Riecken - released under the MIT License. https://github.com/jriecken/sat-js */ + function x(){function c(a,d){this.x=a||0;this.y=d||0}function B(a,d){this.pos=a||new c;this.r=d||0}function m(a,d){this.pos=a||new c;this.angle=0;this.offset=new c;this.u(d||[])}function p(a,d,b){this.pos=a||new c;this.w=d||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,d,b){for(var g=Number.MAX_VALUE,c=-Number.MAX_VALUE,l=a.length,v=0;vc&&(c=e)}b[0]=g;b[1]=c}function y(a,d,b,g,c,l){var k=q.pop(), +e=q.pop();a=h.pop().c(d).sub(a);d=a.f(c);C(b,c,k);C(g,c,e);e[0]+=d;e[1]+=d;if(k[0]>e[1]||e[0]>k[1])return h.push(a),q.push(k),q.push(e),!0;l&&(k[0]e[1]?(b=k[0]-e[1],l.aInB=!1):(b=k[1]-e[0],g=e[1]-k[0],b=bb&&l.overlapN.reverse()));h.push(a);q.push(k);q.push(e);return!1}function z(a,d){var b=a.g(),g=d.f(a);return 0>g?-1:g>b?1:0} +function D(a,d,b){for(var g=h.pop().c(d.pos).sub(a.pos),c=d.r,l=c*c,v=a.calcPoints,e=v.length,t=h.pop(),f=h.pop(),m=0;ml&&(b.aInB=!1);var n=z(t,f);if(-1===n){t.c(a.edges[q]);u=h.pop().c(g).sub(v[q]);n=z(t,u);if(1===n){n=f.j();if(n>c)return h.push(g),h.push(t),h.push(f),h.push(u),!1;b&&(b.bInA=!1,r=f.normalize(),p=c-n)}h.push(u)}else if(1===n){if(t.c(a.edges[u]),f.c(g).sub(v[u]),n=z(t,f),-1===n){n=f.j(); +if(n>c)return h.push(g),h.push(t),h.push(f),!1;b&&(b.bInA=!1,r=f.normalize(),p=c-n)}}else{u=t.m().normalize();n=f.f(u);q=Math.abs(n);if(0c)return h.push(g),h.push(u),h.push(f),!1;b&&(r=u,p=c-n,0<=n||p<2*c)&&(b.bInA=!1)}r&&b&&Math.abs(p)k&&(k=e.x);e.yl&&(l=e.y)}return(new p(this.pos.clone().add(new c(b,g)),k-b,l-g)).l()};m.prototype.getCentroid=function(){for(var a=this.calcPoints, +d=a.length,b=0,g=0,k=0,f=0;fr;r++)h.push(new c);var q=[];for(r=0;5>r;r++)q.push([]); +var A=new w,F=(new p(new c,1E-6,1E-6)).l();f.isSeparatingAxis=y;f.pointInCircle=function(a,c){var b=h.pop().c(a).sub(c.pos),d=c.r*c.r,f=b.g();h.push(b);return f<=d};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 d=h.pop().c(c.pos).sub(a.pos),f=a.r+c.r,l=d.g();if(l>f*f)return h.push(d),!1;b&&(l=Math.sqrt(l),b.a=a,b.b=c,b.overlap=f-l,b.overlapN.c(d.normalize()),b.overlapV.c(d).scale(b.overlap),b.aInB=a.r<=c.r&&l<=c.r- +a.r,b.bInA=c.r<=a.r&&l<=a.r-c.r);h.push(d);return!0};f.testPolygonCircle=D;f.testCirclePolygon=function(a,c,b){if((a=D(c,a,b))&&b){c=b.a;var d=b.aInB;b.overlapN.reverse();b.overlapV.reverse();b.a=b.b;b.b=c;b.aInB=b.bInA;b.bInA=d}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 5738ecb..e378367 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sat", "description": "Library for performing 2D collision detection", - "version": "0.6.0", + "version": "0.7.0", "author": "Jim Riecken ", "keywords": [ "collision detection",