Socket
Socket
Sign inDemoInstall

sat

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.1 to 0.5.0

14

CHANGELOG.md
# Changelog
## In development
## 0.5.0 (Dec 26, 2014)
- **(POTENTIALLY BREAKING CHANGE)** Make `recalc` on `Polygon` more memory efficient. It no longer does any allocations. The `calcPoints`,`edges` and `normals` vector arrays are reused and only created in `setPoints` when the number of new points is different than the current ones. (Fixes #15)
- `points`, `angle` and `offset` can no longer be manually changed. The `setPoints`, `setAngle`, and `setOffset` methods **must** be used.
- As a result of this, the `recalc` method is no longer part of the API.
- Add `getAABB` to `Polygon` and `Circle` that calculate Axis-Aligned Bounding Boxes - thanks [TuurDutoit](https://github.com/TuurDutoit)! (Fixes #17)
## 0.4.1 (Mar 23, 2014)
- Fix missing `T_VECTORS.push()` (thanks shakiba!) - Fixes #8
- Fix missing `T_VECTORS.push()` - thanks [shakiba](https://github.com/shakiba)! (Fixes #8)
- Add `package.json` - released as `npm` module (Fixes #11, Fixes #12)

@@ -32,2 +42,2 @@ ## 0.4 (Mar 2, 2014)

Initial release
- Initial release

2

package.json
{
"name": "sat",
"description": "Library for performing 2D collision detection",
"version": "0.4.1",
"version": "0.5.0",
"author": "Jim Riecken <jriecken@gmail.com>",

@@ -6,0 +6,0 @@ "keywords": [

@@ -21,5 +21,7 @@ SAT.js

Current version: `0.4.1`. [Annotated source code](http://jriecken.github.io/sat-js/docs/SAT.html) is available.
Current version: `0.5.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)
To use it in node.js, you can run `npm install sat` and then use it with `var SAT = require('sat');`

@@ -96,12 +98,13 @@ <a name="classes"></a>

- `offset` - Translation to apply to the polygon before the `angle` rotation (affects `calcPoints`)
- `calcPoints` - The "calculated" collision polygon - effectively `points` with `angle` and `offset` applied.
- `edges` - Array of Vectors representing the edges of the calculated polygon
- `normals` - Array of Vectors representing the edge normals of the calculated polygon (perpendiculars)
- `calcPoints` - (Calculated) The collision polygon - effectively `points` with `angle` and `offset` applied.
- `edges` - (Calculated) Array of Vectors representing the edges of the calculated polygon
- `normals` - (Calculated) Array of Vectors representing the edge normals of the calculated polygon (perpendiculars)
You should _not_ manually change any of the properties except `pos` - use the `setPoints`, `setAngle`, and `setOffset` methods to ensure that the calculated properties are updated correctly.
It has the following methods:
- `setPoints(points)` - Set the original points (calls `recalc` for you)
- `setAngle(angle)` - Set the rotation angle (calls `recalc` for you)
- `setOffset(offset)` - Set the offset (calls `recalc` for you)
- `recalc()` - Call this method if you manually change `points`, `angle`, or `offset`.
- `setPoints(points)` - Set the original points
- `setAngle(angle)` - Set the current rotation angle (in radians)
- `setOffset(offset)` - Set the current offset
- `rotate(angle)` - Rotate the original points of this polygon counter-clockwise (around its local coordinate system) by the specified number of radians. The `angle` rotation will be applied on top of this rotation.

@@ -120,3 +123,3 @@ - `translate(x, y)` - Translate the original points of this polygin (relative to the local coordinate system) by the specified amounts. The `offset` translation will be applied on top of this translation.

- `pos` - The top-left coordinate of the box.
- `pos` - The bottom-left coordinate of the box.
- `w` - The width of the box.

@@ -123,0 +126,0 @@ - `h` - The height of the box.

@@ -1,2 +0,2 @@

// Version 0.4.1 - Copyright 2014 - Jim Riecken <jimr@jimr.ca>
// Version 0.5.0 - Copyright 2012 - 2015 - Jim Riecken <jimr@jimr.ca>
//

@@ -7,3 +7,3 @@ // Released under the MIT License - https://github.com/jriecken/sat-js

// polygons using the Separating Axis Theorem.
/** @preserve SAT.js - Version 0.4.1 - Copyright 2014 - Jim Riecken <jimr@jimr.ca> - released under the MIT License. https://github.com/jriecken/sat-js */
/** @preserve SAT.js - Version 0.5.0 - Copyright 2012 - 2015 - Jim Riecken <jimr@jimr.ca> - released under the MIT License. https://github.com/jriecken/sat-js */

@@ -263,2 +263,14 @@ /*global define: false, module: false*/

SAT['Circle'] = Circle;
// Compute the axis-aligned bounding box (AABB) of this Circle.
//
// Note: Returns a _new_ `Polygon` each time you call this.
/**
* @return {Polygon} The AABB
*/
Circle.prototype['getAABB'] = Circle.prototype.getAABB = function() {
var r = this['r'];
var corner = this["pos"].clone().sub(new Vector(r, r));
return new Box(corner, r*2, r*2).toPolygon();
};

@@ -269,4 +281,6 @@ // ## Polygon

//
// Note: If you manually change the `points`, `angle`, or `offset` properties, you **must** call `recalc`
// afterwards so that the changes get applied correctly.
// Note: Do _not_ manually change the `points`, `angle`, or `offset` properties. Use the
// provided setters. Otherwise the calculated properties will not be updated correctly.
//
// `pos` can be changed directly.

@@ -285,6 +299,5 @@ // Create a new polygon, passing in a position vector, and an array of points (represented

this['pos'] = pos || new Vector();
this['points'] = points || [];
this['angle'] = 0;
this['offset'] = new Vector();
this.recalc();
this.setPoints(points || []);
}

@@ -294,4 +307,2 @@ SAT['Polygon'] = Polygon;

// Set the points of the polygon.
//
// Note: This calls `recalc` for you.
/**

@@ -303,4 +314,18 @@ * @param {Array.<Vector>=} points An array of vectors representing the points in the polygon,

Polygon.prototype['setPoints'] = Polygon.prototype.setPoints = function(points) {
// Only re-allocate if this is a new polygon or the number of points has changed.
var lengthChanged = !this['points'] || this['points'].length !== points.length;
if (lengthChanged) {
var i;
var calcPoints = this['calcPoints'] = [];
var edges = this['edges'] = [];
var normals = this['normals'] = [];
// Allocate the vector arrays for the calculated properties
for (i = 0; i < points.length; i++) {
calcPoints.push(new Vector());
edges.push(new Vector());
normals.push(new Vector());
}
}
this['points'] = points;
this.recalc();
this._recalc();
return this;

@@ -310,4 +335,2 @@ };

// Set the current rotation angle of the polygon.
//
// Note: This calls `recalc` for you.
/**

@@ -319,3 +342,3 @@ * @param {number} angle The current rotation angle (in radians).

this['angle'] = angle;
this.recalc();
this._recalc();
return this;

@@ -325,4 +348,2 @@ };

// Set the current offset to apply to the `points` before applying the `angle` rotation.
//
// Note: This calls `recalc` for you.
/**

@@ -334,3 +355,3 @@ * @param {Vector} offset The new offset vector.

this['offset'] = offset;
this.recalc();
this._recalc();
return this;

@@ -341,4 +362,3 @@ };

//
// Note: This changes the **original** points (so any `angle` will be applied on top of this rotation)
// Note: This calls `recalc` for you.
// Note: This changes the **original** points (so any `angle` will be applied on top of this rotation).
/**

@@ -354,3 +374,3 @@ * @param {number} angle The angle to rotate (in radians)

}
this.recalc();
this._recalc();
return this;

@@ -366,3 +386,2 @@ };

// Note: This changes the **original** points (so any `offset` will be applied on top of this translation)
// Note: This calls `recalc` for you.
/**

@@ -380,3 +399,3 @@ * @param {number} x The horizontal amount to translate.

}
this.recalc();
this._recalc();
return this;

@@ -388,20 +407,17 @@ };

// edges and normals of the collision polygon.
//
// This **must** be called if the `points` array, `angle`, or `offset` is modified manualy.
/**
* @return {Polygon} This for chaining.
*/
Polygon.prototype['recalc'] = Polygon.prototype.recalc = function() {
var i;
Polygon.prototype._recalc = function() {
// Calculated points - this is what is used for underlying collisions and takes into account
// the angle/offset set on the polygon.
var calcPoints = this['calcPoints'] = [];
var calcPoints = this['calcPoints'];
// The edges here are the direction of the `n`th edge of the polygon, relative to
// the `n`th point. If you want to draw a given edge from the edge value, you must
// first translate to the position of the starting point.
var edges = this['edges'] = [];
var edges = this['edges'];
// The normals here are the direction of the normal for the `n`th edge of the polygon, relative
// to the position of the `n`th point. If you want to draw an edge normal, you must first
// translate to the position of the starting point.
var normals = this['normals'] = [];
var normals = this['normals'];
// Copy the original points array and apply the offset/angle

@@ -412,5 +428,5 @@ var points = this['points'];

var len = points.length;
var i;
for (i = 0; i < len; i++) {
var calcPoint = points[i].clone();
calcPoints.push(calcPoint);
var calcPoint = calcPoints[i].copy(points[i]);
calcPoint.x += offset.x;

@@ -426,9 +442,41 @@ calcPoint.y += offset.y;

var p2 = i < len - 1 ? calcPoints[i + 1] : calcPoints[0];
var e = new Vector().copy(p2).sub(p1);
var n = new Vector().copy(e).perp().normalize();
edges.push(e);
normals.push(n);
var e = edges[i].copy(p2).sub(p1);
normals[i].copy(e).perp().normalize();
}
return this;
};
// Compute the axis-aligned bounding box. Any current state
// (translations/rotations) will be applied before constructing the AABB.
//
// Note: Returns a _new_ `Polygon` each time you call this.
/**
* @return {Polygon} The AABB
*/
Polygon.prototype["getAABB"] = Polygon.prototype.getAABB = function() {
var points = this["calcPoints"];
var len = points.length;
var xMin = points[0]["x"];
var yMin = points[0]["y"];
var xMax = points[0]["x"];
var yMax = points[0]["y"];
for (var i = 1; i < len; i++) {
var point = points[i];
if (point["x"] < xMin) {
xMin = point["x"];
}
else if (point["x"] > xMax) {
xMax = point["x"];
}
if (point["y"] < yMin) {
yMin = point["y"];
}
else if (point["y"] > yMax) {
yMax = point["y"];
}
}
return new Box(this["pos"].clone().add(new Vector(xMin, yMin)), xMax - xMin, yMax - yMin).toPolygon();
};

@@ -435,0 +483,0 @@ // ## Box

@@ -1,13 +0,14 @@

/* SAT.js - Version 0.4.1 - Copyright 2014 - Jim Riecken <jimr@jimr.ca> - released under the MIT License. https://github.com/jriecken/sat-js */
function w(){function a(b,k){this.x=b||0;this.y=k||0}function e(b,k){this.pos=b||new a;this.points=k||[];this.angle=0;this.offset=new a;this.recalc()}function u(b,k,c){this.pos=b||new a;this.w=k||0;this.h=c||0}function v(){this.b=this.a=null;this.overlapN=new a;this.overlapV=new a;this.clear()}function z(b,k,c){for(var a=Number.MAX_VALUE,f=-Number.MAX_VALUE,h=b.length,l=0;l<h;l++){var g=b[l].d(k);g<a&&(a=g);g>f&&(f=g)}c[0]=a;c[1]=f}function A(b,k,c,a,f,h){var l=q.pop(),g=q.pop();b=d.pop().c(k).sub(b);
k=b.d(f);z(c,f,l);z(a,f,g);g[0]+=k;g[1]+=k;if(l[0]>g[1]||g[0]>l[1])return d.push(b),q.push(l),q.push(g),!0;h&&(c=0,l[0]<g[0]?(h.aInB=!1,l[1]<g[1]?(c=l[1]-g[0],h.bInA=!1):(c=l[1]-g[0],a=g[1]-l[0],c=c<a?c:-a)):(h.bInA=!1,l[1]>g[1]?(c=l[0]-g[1],h.aInB=!1):(c=l[1]-g[0],a=g[1]-l[0],c=c<a?c:-a)),a=Math.abs(c),a<h.overlap&&(h.overlap=a,h.overlapN.c(f),0>c&&h.overlapN.reverse()));d.push(b);q.push(l);q.push(g);return!1}function x(b,k){var c=b.e(),a=k.d(b);return 0>a?-1:a>c?1:0}function B(b,k,c){for(var a=
d.pop().c(k.pos).sub(b.pos),f=k.r,h=f*f,l=b.calcPoints,g=l.length,s=d.pop(),p=d.pop(),m=0;m<g;m++){var e=m===g-1?0:m+1,q=0===m?g-1:m-1,t=0,r=null;s.c(b.edges[m]);p.c(a).sub(l[m]);c&&p.e()>h&&(c.aInB=!1);var n=x(s,p);if(-1===n){s.c(b.edges[q]);e=d.pop().c(a).sub(l[q]);n=x(s,e);if(1===n){n=p.f();if(n>f)return d.push(a),d.push(s),d.push(p),d.push(e),!1;c&&(c.bInA=!1,r=p.normalize(),t=f-n)}d.push(e)}else if(1===n){if(s.c(b.edges[e]),p.c(a).sub(l[e]),n=x(s,p),-1===n){n=p.f();if(n>f)return d.push(a),d.push(s),
d.push(p),!1;c&&(c.bInA=!1,r=p.normalize(),t=f-n)}}else{e=s.g().normalize();n=p.d(e);q=Math.abs(n);if(0<n&&q>f)return d.push(a),d.push(e),d.push(p),!1;c&&(r=e,t=f-n,0<=n||t<2*f)&&(c.bInA=!1)}r&&c&&Math.abs(t)<Math.abs(c.overlap)&&(c.overlap=t,c.overlapN.c(r))}c&&(c.a=b,c.b=k,c.overlapV.c(c.overlapN).scale(c.overlap));d.push(a);d.push(s);d.push(p);return!0}function C(b,a,c){for(var d=b.calcPoints,f=d.length,h=a.calcPoints,l=h.length,g=0;g<f;g++)if(A(b.pos,a.pos,d,h,b.normals[g],c))return!1;for(g=0;g<
l;g++)if(A(b.pos,a.pos,d,h,a.normals[g],c))return!1;c&&(c.a=b,c.b=a,c.overlapV.c(c.overlapN).scale(c.overlap));return!0}var m={};m.Vector=a;m.V=a;a.prototype.copy=a.prototype.c=function(b){this.x=b.x;this.y=b.y;return this};a.prototype.clone=a.prototype.i=function(){return new a(this.x,this.y)};a.prototype.perp=a.prototype.g=function(){var b=this.x;this.x=this.y;this.y=-b;return this};a.prototype.rotate=a.prototype.rotate=function(b){var a=this.x,c=this.y;this.x=a*Math.cos(b)-c*Math.sin(b);this.y=
a*Math.sin(b)+c*Math.cos(b);return this};a.prototype.reverse=a.prototype.reverse=function(){this.x=-this.x;this.y=-this.y;return this};a.prototype.normalize=a.prototype.normalize=function(){var b=this.f();0<b&&(this.x/=b,this.y/=b);return this};a.prototype.add=a.prototype.add=function(b){this.x+=b.x;this.y+=b.y;return this};a.prototype.sub=a.prototype.sub=function(b){this.x-=b.x;this.y-=b.y;return this};a.prototype.scale=a.prototype.scale=function(b,a){this.x*=b;this.y*=a||b;return this};a.prototype.project=
a.prototype.j=function(b){var a=this.d(b)/b.e();this.x=a*b.x;this.y=a*b.y;return this};a.prototype.projectN=a.prototype.k=function(b){var a=this.d(b);this.x=a*b.x;this.y=a*b.y;return this};a.prototype.reflect=function(b){var a=this.x,c=this.y;this.j(b).scale(2);this.x-=a;this.y-=c;return this};a.prototype.reflectN=function(b){var a=this.x,c=this.y;this.k(b).scale(2);this.x-=a;this.y-=c;return this};a.prototype.dot=a.prototype.d=function(b){return this.x*b.x+this.y*b.y};a.prototype.len2=a.prototype.e=
function(){return this.d(this)};a.prototype.len=a.prototype.f=function(){return Math.sqrt(this.e())};m.Circle=function(b,k){this.pos=b||new a;this.r=k||0};m.Polygon=e;e.prototype.setPoints=function(b){this.points=b;this.recalc();return this};e.prototype.setAngle=function(b){this.angle=b;this.recalc();return this};e.prototype.setOffset=function(b){this.offset=b;this.recalc();return this};e.prototype.rotate=e.prototype.rotate=function(b){for(var a=this.points,c=a.length,d=0;d<c;d++)a[d].rotate(b);this.recalc();
return this};e.prototype.translate=e.prototype.translate=function(b,a){for(var c=this.points,d=c.length,f=0;f<d;f++)c[f].x+=b,c[f].y+=a;this.recalc();return this};e.prototype.recalc=e.prototype.recalc=function(){var b,k=this.calcPoints=[],c=this.edges=[],d=this.normals=[],f=this.points,h=this.offset,l=this.angle,g=f.length;for(b=0;b<g;b++){var e=f[b].i();k.push(e);e.x+=h.x;e.y+=h.y;0!==l&&e.rotate(l)}for(b=0;b<g;b++)f=(new a).c(b<g-1?k[b+1]:k[0]).sub(k[b]),h=(new a).c(f).g().normalize(),c.push(f),
d.push(h);return this};m.Box=u;u.prototype.toPolygon=u.prototype.l=function(){var b=this.pos,k=this.w,c=this.h;return new e(new a(b.x,b.y),[new a,new a(k,0),new a(k,c),new a(0,c)])};m.Response=v;v.prototype.clear=v.prototype.clear=function(){this.bInA=this.aInB=!0;this.overlap=Number.MAX_VALUE;return this};for(var d=[],r=0;10>r;r++)d.push(new a);for(var q=[],r=0;5>r;r++)q.push([]);var y=new v,D=(new u(new a,1,1)).l();m.pointInCircle=function(b,a){var c=d.pop().c(b).sub(a.pos),e=a.r*a.r,f=c.e();d.push(c);
return f<=e};m.pointInPolygon=function(b,a){D.pos.c(b);y.clear();var c=C(D,a,y);c&&(c=y.aInB);return c};m.testCircleCircle=function(b,a,c){var e=d.pop().c(a.pos).sub(b.pos),f=b.r+a.r,h=e.e();if(h>f*f)return d.push(e),!1;c&&(h=Math.sqrt(h),c.a=b,c.b=a,c.overlap=f-h,c.overlapN.c(e.normalize()),c.overlapV.c(e).scale(c.overlap),c.aInB=b.r<=a.r&&h<=a.r-b.r,c.bInA=a.r<=b.r&&h<=b.r-a.r);d.push(e);return!0};m.testPolygonCircle=B;m.testCirclePolygon=function(a,d,c){if((a=B(d,a,c))&&c){d=c.a;var e=c.aInB;c.overlapN.reverse();
c.overlapV.reverse();c.a=c.b;c.b=d;c.aInB=c.bInA;c.bInA=e}return a};m.testPolygonPolygon=C;return m}"function"===typeof define&&define.amd?define(w):"object"===typeof exports?module.exports=w():this.SAT=w();
/* SAT.js - Version 0.5.0 - Copyright 2012 - 2015 - Jim Riecken <jimr@jimr.ca> - 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;h<k;h++){var d=a[h].d(e);d<f&&(f=d);d>c&&(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[0]?(k.aInB=!1,h[1]<d[1]?(b=h[1]-d[0],k.bInA=!1):(b=h[1]-d[0],f=d[1]-h[0],b=b<f?b:-f)):(k.bInA=!1,h[1]>d[1]?(b=h[0]-d[1],k.aInB=!1):(b=h[1]-d[0],f=d[1]-h[0],b=b<f?b:-f)),f=Math.abs(b),f<k.overlap&&(k.overlap=f,k.overlapN.c(c),0>b&&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;n<d;n++){var m=n===d-1?0:n+1,t=0===n?d-1:n-1,r=0,u=null;v.c(a.edges[n]);q.c(c).sub(h[n]);b&&q.e()>k&&(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(0<p&&t>l)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)<Math.abs(b.overlap)&&(b.overlap=r,b.overlapN.c(u))}b&&(b.a=a,b.b=e,b.overlapV.c(b.overlapN).scale(b.overlap));g.push(c);g.push(v);g.push(q);return!0}function E(a,e,b){for(var c=a.calcPoints,l=c.length,k=e.calcPoints,h=k.length,d=0;d<l;d++)if(C(a.pos,e.pos,
c,k,a.normals[d],b))return!1;for(d=0;d<h;d++)if(C(a.pos,e.pos,c,k,e.normals[d],b))return!1;b&&(b.a=a,b.b=e,b.overlapV.c(b.overlapN).scale(b.overlap));return!0}var n={};n.Vector=c;n.V=c;c.prototype.copy=c.prototype.c=function(a){this.x=a.x;this.y=a.y;return this};c.prototype.clone=c.prototype.clone=function(){return new c(this.x,this.y)};c.prototype.perp=c.prototype.j=function(){var a=this.x;this.x=this.y;this.y=-a;return this};c.prototype.rotate=c.prototype.rotate=function(a){var e=this.x,b=this.y;
this.x=e*Math.cos(a)-b*Math.sin(a);this.y=e*Math.sin(a)+b*Math.cos(a);return this};c.prototype.reverse=c.prototype.reverse=function(){this.x=-this.x;this.y=-this.y;return this};c.prototype.normalize=c.prototype.normalize=function(){var a=this.g();0<a&&(this.x/=a,this.y/=a);return this};c.prototype.add=c.prototype.add=function(a){this.x+=a.x;this.y+=a.y;return this};c.prototype.sub=c.prototype.sub=function(a){this.x-=a.x;this.y-=a.y;return this};c.prototype.scale=c.prototype.scale=function(a,e){this.x*=
a;this.y*=e||a;return this};c.prototype.project=c.prototype.k=function(a){var e=this.d(a)/a.e();this.x=e*a.x;this.y=e*a.y;return this};c.prototype.projectN=c.prototype.l=function(a){var e=this.d(a);this.x=e*a.x;this.y=e*a.y;return this};c.prototype.reflect=function(a){var e=this.x,b=this.y;this.k(a).scale(2);this.x-=e;this.y-=b;return this};c.prototype.reflectN=function(a){var e=this.x,b=this.y;this.l(a).scale(2);this.x-=e;this.y-=b;return this};c.prototype.dot=c.prototype.d=function(a){return this.x*
a.x+this.y*a.y};c.prototype.len2=c.prototype.e=function(){return this.d(this)};c.prototype.len=c.prototype.g=function(){return Math.sqrt(this.e())};n.Circle=A;A.prototype.getAABB=function(){var a=this.r,e=this.pos.clone().sub(new c(a,a));return(new r(e,2*a,2*a)).i()};n.Polygon=m;m.prototype.setPoints=m.prototype.m=function(a){if(!this.points||this.points.length!==a.length){var e,b=this.calcPoints=[],f=this.edges=[],l=this.normals=[];for(e=0;e<a.length;e++)b.push(new c),f.push(new c),l.push(new c)}this.points=
a;this.f();return this};m.prototype.setAngle=function(a){this.angle=a;this.f();return this};m.prototype.setOffset=function(a){this.offset=a;this.f();return this};m.prototype.rotate=m.prototype.rotate=function(a){for(var e=this.points,b=e.length,c=0;c<b;c++)e[c].rotate(a);this.f();return this};m.prototype.translate=m.prototype.translate=function(a,c){for(var b=this.points,f=b.length,l=0;l<f;l++)b[l].x+=a,b[l].y+=c;this.f();return this};m.prototype.f=function(){var a=this.calcPoints,c=this.edges,b=
this.normals,f=this.points,l=this.offset,k=this.angle,h=f.length,d;for(d=0;d<h;d++){var g=a[d].c(f[d]);g.x+=l.x;g.y+=l.y;0!==k&&g.rotate(k)}for(d=0;d<h;d++)f=a[d],f=c[d].c(d<h-1?a[d+1]:a[0]).sub(f),b[d].c(f).j().normalize()};m.prototype.getAABB=function(){for(var a=this.calcPoints,e=a.length,b=a[0].x,f=a[0].y,g=a[0].x,k=a[0].y,h=1;h<e;h++){var d=a[h];d.x<b?b=d.x:d.x>g&&(g=d.x);d.y<f?f=d.y:d.y>k&&(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();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc