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.7.0 to 0.7.1

4

CHANGELOG.md
# Changelog
## 0.7.1 (May 23, 2018)
- Check explicitly for `undefined` `y` param when scaling vectors. (Fixes #52)
## O.7.0 (Feb 17, 2018)

@@ -4,0 +8,0 @@

2

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

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

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

SAT.js
======
# SAT.js

@@ -8,4 +7,3 @@ - [Classes](#classes)

About
-----
## About

@@ -22,3 +20,3 @@ SAT.js is a simple JavaScript library for performing collision detection (and projection-based collision response) of simple 2D shapes. It uses the [Separating Axis Theorem](http://en.wikipedia.org/wiki/Hyperplane_separation_theorem) (hence the name)

Current version: `0.7.0`. [Annotated source code](http://jriecken.github.io/sat-js/docs/SAT.html) is available.
Current version: `0.7.1`. [Annotated source code](http://jriecken.github.io/sat-js/docs/SAT.html) is available.

@@ -29,5 +27,3 @@ Nicely compresses with the [Google Closure Compiler](https://developers.google.com/closure/compiler/) in **Advanced** mode to about 6KB (2KB gzipped)

<a name="classes"></a>
Classes
--------
## Classes

@@ -81,3 +77,2 @@ SAT.js contains the following JavaScript classes:

### SAT.Polygon

@@ -118,2 +113,4 @@

- `translate(x, y)` - Translate the original points of this polygon (relative to the local coordinate system) by the specified amounts. The `offset` translation will be applied on top of this translation.
- `getAABB()` - Compute the axis-aligned bounding box. Returns a new Polygon every time it is called. Is performed based on the `calcPoints`.
- `getCentroid()` - Compute the [Centroid](https://en.wikipedia.org/wiki/Centroid#Centroid_of_a_polygon) of the polygon. Is performed based on the `calcPoints`.

@@ -156,7 +153,4 @@ ### SAT.Box

## Collision Tests
<a name="tests"></a>
Collision Tests
---------------
SAT.js contains the following collision tests:

@@ -200,5 +194,3 @@

<a name="examples"></a>
Examples
--------
## Examples

@@ -205,0 +197,0 @@ Test two circles

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

// Version 0.7.0 - Copyright 2012 - 2018 - Jim Riecken <jimr@jimr.ca>
// Version 0.7.1 - Copyright 2012 - 2018 - 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.7.0 - Copyright 2012 - 2018 - Jim Riecken <jimr@jimr.ca> - released under the MIT License. https://github.com/jriecken/sat-js */
/** @preserve SAT.js - Version 0.7.1 - Copyright 2012 - 2018 - Jim Riecken <jimr@jimr.ca> - released under the MIT License. https://github.com/jriecken/sat-js */

@@ -163,3 +163,3 @@ /*global define: false, module: false*/

this['x'] *= x;
this['y'] *= y || x;
this['y'] *= typeof y != 'undefined' ? y : x;
return this;

@@ -472,5 +472,11 @@ };

// Compute the centroid (geometric center) of the polygon
// Compute the centroid (geometric center) of the polygon. Any current state
// (translations/rotations) will be applied before computing the centroid.
//
// See https://en.wikipedia.org/wiki/Centroid#Centroid_of_a_polygon
//
// Note: Returns a _new_ `Vector` each time you call this.
/**
* @return {Vector} A Vector that contains the coordinates of the Centroid.
*/
Polygon.prototype["getCentroid"] = Polygon.prototype.getCentroid = function() {

@@ -490,3 +496,3 @@ var points = this["calcPoints"];

}
ar = ar * 3; // we want 1 / 6 the area and we currently hae 2*area
ar = ar * 3; // we want 1 / 6 the area and we currently have 2*area
cx = cx / ar;

@@ -493,0 +499,0 @@ cy = cy / ar;

/*
SAT.js - Version 0.7.0 - Copyright 2012 - 2018 - Jim Riecken <jimr@jimr.ca> - 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;v<l;v++){var e=a[v].f(d);e<g&&(g=e);e>c&&(c=e)}b[0]=g;b[1]=c}function y(a,d,b,g,c,l){var k=q.pop(),
SAT.js - Version 0.7.1 - Copyright 2012 - 2018 - Jim Riecken <jimr@jimr.ca> - 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;v<l;v++){var e=a[v].f(d);e<g&&(g=e);e>c&&(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[0]?(l.aInB=!1,k[1]<e[1]?(b=k[1]-e[0],l.bInA=!1):(b=k[1]-e[0],g=e[1]-k[0],b=b<g?b:-g)):(l.bInA=!1,k[1]>e[1]?(b=k[0]-e[1],l.aInB=!1):(b=k[1]-e[0],g=e[1]-k[0],b=b<g?b:-g)),g=Math.abs(b),g<l.overlap&&(l.overlap=g,l.overlapN.c(c),0>b&&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}

@@ -9,8 +9,8 @@ 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;m<e;m++){var u=m===e-1?0:m+1,q=0===m?e-1:m-1,p=0,r=null;t.c(a.edges[m]);f.c(g).sub(v[m]);b&&f.g()>l&&(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();

this.x=d*Math.cos(a)-b*Math.sin(a);this.y=d*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.j();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,d){this.x*=
a;this.y*=d||a;return this};c.prototype.project=c.prototype.o=function(a){var d=this.f(a)/a.g();this.x=d*a.x;this.y=d*a.y;return this};c.prototype.projectN=c.prototype.s=function(a){var d=this.f(a);this.x=d*a.x;this.y=d*a.y;return this};c.prototype.reflect=function(a){var d=this.x,b=this.y;this.o(a).scale(2);this.x-=d;this.y-=b;return this};c.prototype.reflectN=function(a){var d=this.x,b=this.y;this.s(a).scale(2);this.x-=d;this.y-=b;return this};c.prototype.dot=c.prototype.f=function(a){return this.x*
a.x+this.y*a.y};c.prototype.len2=c.prototype.g=function(){return this.f(this)};c.prototype.len=c.prototype.j=function(){return Math.sqrt(this.g())};f.Circle=B;B.prototype.getAABB=function(){var a=this.r,d=this.pos.clone().sub(new c(a,a));return(new p(d,2*a,2*a)).l()};f.Polygon=m;m.prototype.setPoints=m.prototype.u=function(a){if(!this.points||this.points.length!==a.length){var d,b=this.calcPoints=[],g=this.edges=[],k=this.normals=[];for(d=0;d<a.length;d++)b.push(new c),g.push(new c),k.push(new c)}this.points=
a;this.i()};m.prototype.setAngle=function(a){this.angle=a;this.i();return this};m.prototype.setOffset=function(a){this.offset=a;this.i();return this};m.prototype.rotate=m.prototype.rotate=function(a){for(var d=this.points,b=d.length,c=0;c<b;c++)d[c].rotate(a);this.i();return this};m.prototype.translate=m.prototype.translate=function(a,d){for(var b=this.points,c=b.length,k=0;k<c;k++)b[k].x+=a,b[k].y+=d;this.i();return this};m.prototype.i=function(){var a=this.calcPoints,c=this.edges,b=this.normals,
g=this.points,k=this.offset,l=this.angle,f=g.length,e;for(e=0;e<f;e++){var h=a[e].c(g[e]);h.x+=k.x;h.y+=k.y;0!==l&&h.rotate(l)}for(e=0;e<f;e++)g=a[e],g=c[e].c(e<f-1?a[e+1]:a[0]).sub(g),b[e].c(g).m().normalize()};m.prototype.getAABB=function(){for(var a=this.calcPoints,d=a.length,b=a[0].x,g=a[0].y,k=a[0].x,l=a[0].y,f=1;f<d;f++){var e=a[f];e.x<b?b=e.x:e.x>k&&(k=e.x);e.y<g?g=e.y:e.y>l&&(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;f<d;f++){var h=a[f],e=f===d-1?a[0]:a[f+1],m=h.x*e.y-e.x*h.y;b+=(h.x+e.x)*m;g+=(h.y+e.y)*m;k+=m}k*=3;return new c(b/k,g/k)};f.Box=p;p.prototype.toPolygon=p.prototype.l=function(){var a=this.pos,d=this.w,b=this.h;return new m(new c(a.x,a.y),[new c,new c(d,0),new c(d,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 h=[],r=0;10>r;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();
a;this.y*="undefined"!=typeof d?d:a;return this};c.prototype.project=c.prototype.o=function(a){var d=this.f(a)/a.g();this.x=d*a.x;this.y=d*a.y;return this};c.prototype.projectN=c.prototype.s=function(a){var d=this.f(a);this.x=d*a.x;this.y=d*a.y;return this};c.prototype.reflect=function(a){var d=this.x,b=this.y;this.o(a).scale(2);this.x-=d;this.y-=b;return this};c.prototype.reflectN=function(a){var d=this.x,b=this.y;this.s(a).scale(2);this.x-=d;this.y-=b;return this};c.prototype.dot=c.prototype.f=
function(a){return this.x*a.x+this.y*a.y};c.prototype.len2=c.prototype.g=function(){return this.f(this)};c.prototype.len=c.prototype.j=function(){return Math.sqrt(this.g())};f.Circle=B;B.prototype.getAABB=function(){var a=this.r,d=this.pos.clone().sub(new c(a,a));return(new p(d,2*a,2*a)).l()};f.Polygon=m;m.prototype.setPoints=m.prototype.u=function(a){if(!this.points||this.points.length!==a.length){var d,b=this.calcPoints=[],g=this.edges=[],k=this.normals=[];for(d=0;d<a.length;d++)b.push(new c),g.push(new c),
k.push(new c)}this.points=a;this.i()};m.prototype.setAngle=function(a){this.angle=a;this.i();return this};m.prototype.setOffset=function(a){this.offset=a;this.i();return this};m.prototype.rotate=m.prototype.rotate=function(a){for(var d=this.points,b=d.length,c=0;c<b;c++)d[c].rotate(a);this.i();return this};m.prototype.translate=m.prototype.translate=function(a,d){for(var b=this.points,c=b.length,k=0;k<c;k++)b[k].x+=a,b[k].y+=d;this.i();return this};m.prototype.i=function(){var a=this.calcPoints,c=
this.edges,b=this.normals,g=this.points,k=this.offset,l=this.angle,f=g.length,e;for(e=0;e<f;e++){var h=a[e].c(g[e]);h.x+=k.x;h.y+=k.y;0!==l&&h.rotate(l)}for(e=0;e<f;e++)g=a[e],g=c[e].c(e<f-1?a[e+1]:a[0]).sub(g),b[e].c(g).m().normalize()};m.prototype.getAABB=function(){for(var a=this.calcPoints,d=a.length,b=a[0].x,g=a[0].y,k=a[0].x,l=a[0].y,f=1;f<d;f++){var e=a[f];e.x<b?b=e.x:e.x>k&&(k=e.x);e.y<g?g=e.y:e.y>l&&(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;f<d;f++){var h=a[f],e=f===d-1?a[0]:a[f+1],m=h.x*e.y-e.x*h.y;b+=(h.x+e.x)*m;g+=(h.y+e.y)*m;k+=m}k*=3;return new c(b/k,g/k)};f.Box=p;p.prototype.toPolygon=p.prototype.l=function(){var a=this.pos,d=this.w,b=this.h;return new m(new c(a.x,a.y),[new c,new c(d,0),new c(d,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 h=[],r=0;10>r;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();
var SAT = require('..');
var assert = require('assert');
describe('Vector.scale', function() {
it('should scale by zero properly', function() {
var V = SAT.Vector;
var v1 = new V(5, 5);
v1.scale(10, 10);
assert(v1.x === 50);
assert(v1.y === 50);
v1.scale(0, 1);
assert(v1.x === 0);
assert(v1.y === 50);
v1.scale(1, 0);
assert(v1.x === 0);
assert(v1.y === 0);
});
});
describe("Polygon.getCentroid", function() {

@@ -5,0 +23,0 @@ it("should calculate the correct value for a square", function() {

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