Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rebound

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rebound - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

example/example.js

2

package.json
{
"name": "rebound",
"version": "0.0.6",
"version": "0.0.7",
"description": "A simple library for modeling spring dynamics",

@@ -5,0 +5,0 @@ "main": "rebound.min.js",

@@ -759,4 +759,5 @@ // Rebound

this.springSystem = null;
var _this = this;
var _run = function() {
this.springSystem.loop(Date.now());
_this.springSystem.loop(Date.now());
};

@@ -763,0 +764,0 @@

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

(function(){var d={};var n=d.SpringSystem=function n(q){this._springRegistry={};this._activeSprings=[];this.listeners=[];this._idleSpringIndices=[];this.looper=q||new o();this.looper.springSystem=this};i(n.prototype,{_springRegistry:null,_isIdle:true,_lastTimeMillis:-1,_activeSprings:null,listeners:null,_idleSpringIndices:null,setLooper:function(q){this.looper=q;q.springSystem=this},createSpring:function(r,t){var q=new c(this);this.registerSpring(q);if(typeof r==="undefined"||typeof t==="undefined"){q.setSpringConfig(p.DEFAULT_ORIGAMI_SPRING_CONFIG)}else{var s=p.fromOrigamiTensionAndFriction(r,t);q.setSpringConfig(s)}return q},getIsIdle:function(){return this._isIdle},getSpringById:function(q){return this._springRegistry[q]},getAllSprings:function(){var q=[];for(var r in this._springRegistry){if(this._springRegistry.hasOwnProperty(r)){q.push(this._springRegistry[r])}}return q},registerSpring:function(q){this._springRegistry[q.getId()]=q},deregisterSpring:function(q){a(this._activeSprings,q);delete this._springRegistry[q.getId()]},advance:function(v,t){while(this._idleSpringIndices.length>0){this._idleSpringIndices.pop()}for(var u=0,r=this._activeSprings.length;u<r;u++){var s=this._activeSprings[u];if(s.systemShouldAdvance()){s.advance(v/1000,t/1000)}else{this._idleSpringIndices.push(this._activeSprings.indexOf(s))}}while(this._idleSpringIndices.length>0){var q=this._idleSpringIndices.pop();q>=0&&this._activeSprings.splice(q,1)}},loop:function(u){var t;if(this._lastTimeMillis===-1){this._lastTimeMillis=u-1}var r=u-this._lastTimeMillis;this._lastTimeMillis=u;var s=0,q=this.listeners.length;for(s=0;s<q;s++){var t=this.listeners[s];t.onBeforeIntegrate&&t.onBeforeIntegrate(this)}this.advance(u,r);if(this._activeSprings.length===0){this._isIdle=true;this._lastTimeMillis=-1}for(s=0;s<q;s++){var t=this.listeners[s];t.onAfterIntegrate&&t.onAfterIntegrate(this)}if(!this._isIdle){this.looper.run()}},activateSpring:function(r){var q=this._springRegistry[r];if(this._activeSprings.indexOf(q)==-1){this._activeSprings.push(q)}if(this.getIsIdle()){this._isIdle=false;this.looper.run()}},addListener:function(q){this.listeners.push(q)},removeListener:function(q){a(this.listeners,q)},removeAllListeners:function(){this.listeners=[]}});var c=d.Spring=function c(q){this._id="s"+c._ID++;this._springSystem=q;this.listeners=[];this._currentState=new b();this._previousState=new b();this._tempState=new b()};i(c,{_ID:0,MAX_DELTA_TIME_SEC:0.064,SOLVER_TIMESTEP_SEC:0.001});i(c.prototype,{_id:0,_springConfig:null,_overshootClampingEnabled:false,_currentState:null,_previousState:null,_tempState:null,_startValue:0,_endValue:0,_wasAtRest:true,_restSpeedThreshold:0.001,_displacementFromRestThreshold:0.001,listeners:null,_timeAccumulator:0,_springSystem:null,destroy:function(){this.listeners=[];this._springSystem.deregisterSpring(this)},getId:function(){return this._id},setSpringConfig:function(q){this._springConfig=q;return this},getSpringConfig:function(){return this._springConfig},setCurrentValue:function(s){this._startValue=s;this._currentState.position=s;for(var r=0,q=this.listeners.length;r<q;r++){var t=this.listeners[r];t.onSpringUpdate&&t.onSpringUpdate(this)}return this},getStartValue:function(){return this._startValue},getCurrentValue:function(){return this._currentState.position},getCurrentDisplacementDistance:function(){return this.getDisplacementDistanceForState(this._currentState)},getDisplacementDistanceForState:function(q){return Math.abs(this._endValue-q.position)},setEndValue:function(r){if(this._endValue==r&&this.isAtRest()){return this}this._startValue=this.getCurrentValue();this._endValue=r;this._springSystem.activateSpring(this.getId());for(var s=0,q=this.listeners.length;s<q;s++){var t=this.listeners[s];t.onSpringEndStateChange&&t.onSpringEndStateChange(this)}return this},getEndValue:function(){return this._endValue},setVelocity:function(q){this._currentState.velocity=q;return this},getVelocity:function(){return this._currentState.velocity},setRestSpeedThreshold:function(q){this._restSpeedThreshold=q;return this},getRestSpeedThreshold:function(){return this._restSpeedThreshold},setRestDisplacementThreshold:function(q){this._displacementFromRestThreshold=q},getRestDisplacementThreshold:function(){return this._displacementFromRestThreshold},setOvershootClampingEnabled:function(q){this._overshootClampingEnabled=q;return this},isOvershootClampingEnabled:function(){return this._overshootClampingEnabled},isOvershooting:function(){return(this._startValue<this._endValue&&this.getCurrentValue()>this._endValue)||(this._startValue>this._endValue&&this.getCurrentValue()<this._endValue)},advance:function(x,z){var F=this.isAtRest();if(F&&this._wasAtRest){return}var u=z;if(z>c.MAX_DELTA_TIME_SEC){u=c.MAX_DELTA_TIME_SEC}this._timeAccumulator+=u;var B=this._springConfig.tension,w=this._springConfig.friction,N=this._currentState.position,C=this._currentState.velocity,K=this._tempState.position,G=this._tempState.velocity,r,L,E,O,q,t,D,y,M,H;while(this._timeAccumulator>=c.SOLVER_TIMESTEP_SEC){this._timeAccumulator-=c.SOLVER_TIMESTEP_SEC;if(this._timeAccumulator<c.SOLVER_TIMESTEP_SEC){this._previousState.position=N;this._previousState.velocity=C}r=C;L=(B*(this._endValue-K))-w*C;K=N+r*c.SOLVER_TIMESTEP_SEC*0.5;G=C+L*c.SOLVER_TIMESTEP_SEC*0.5;E=G;O=(B*(this._endValue-K))-w*G;K=N+E*c.SOLVER_TIMESTEP_SEC*0.5;G=C+O*c.SOLVER_TIMESTEP_SEC*0.5;q=G;t=(B*(this._endValue-K))-w*G;K=N+q*c.SOLVER_TIMESTEP_SEC*0.5;G=C+t*c.SOLVER_TIMESTEP_SEC*0.5;D=G;y=(B*(this._endValue-K))-w*G;M=1/6*(r+2*(E+q)+D);H=1/6*(L+2*(O+t)+y);N+=M*c.SOLVER_TIMESTEP_SEC;C+=H*c.SOLVER_TIMESTEP_SEC}this._tempState.position=K;this._tempState.velocity=G;this._currentState.position=N;this._currentState.velocity=C;if(this._timeAccumulator>0){this.interpolate(this._timeAccumulator/c.SOLVER_TIMESTEP_SEC)}if(this.isAtRest()||this._overshootClampingEnabled&&this.isOvershooting()){this._startValue=this._endValue;this._currentState.position=this._endValue;this.setVelocity(0);F=true}var s=false;if(this._wasAtRest){this._wasAtRest=false;s=true}var A=false;if(F){this._wasAtRest=true;A=true}for(var I=0,J=this.listeners.length;I<J;I++){var v=this.listeners[I];if(s){v.onSpringActivate&&v.onSpringActivate(this)}v.onSpringUpdate&&v.onSpringUpdate(this);if(A){v.onSpringAtRest&&v.onSpringAtRest(this)}}},systemShouldAdvance:function(){return !this.isAtRest()||!this.wasAtRest()},wasAtRest:function(){return this._wasAtRest},isAtRest:function(){return Math.abs(this._currentState.velocity)<this._restSpeedThreshold&&this.getDisplacementDistanceForState(this._currentState)<=this._displacementFromRestThreshold},setAtRest:function(){this._endValue=this._currentState.position;this._tempState.position=this._currentState.position;this._currentState.velocity=0;return this},interpolate:function(q){this._currentState.position=this._currentState.position*q+this._previousState.position*(1-q);this._currentState.velocity=this._currentState.velocity*q+this._previousState.velocity*(1-q)},getListeners:function(){return this.listeners},addListener:function(q){this.listeners.push(q);return this},removeListener:function(q){a(this.listeners,q);return this},removeAllListeners:function(){this.listeners=[];return this},currentValueIsApproximately:function(q){return Math.abs(this.getCurrentValue()-q)<=this.getRestDisplacementThreshold()}});var b=function b(){};i(b.prototype,{position:0,velocity:0});var p=d.SpringConfig=function p(q,r){this.tension=q;this.friction=r};var o=d.AnimationLooper=function o(){this.springSystem=null;var q=function(){this.springSystem.loop(Date.now())};this.run=function(){f(q)}};var h=d.SimulationLooper=function h(q){this.springSystem=null;var s=0;var r=false;q=q||16.667;this.run=function(){if(r){return}r=true;while(!this.springSystem.getIsIdle()){this.springSystem.loop(s+=q)}r=false}};var g=d.SteppingSimulationLooper=function(q){this.springSystem=null;var s=0;var r=false;this.run=function(){};this.step=function(t){this.springSystem.loop(s+=t)}};var k={tensionFromOrigamiValue:function(q){return(q-30)*3.62+194},origamiValueFromTension:function(q){return(q-194)/3.62+30},frictionFromOrigamiValue:function(q){return(q-8)*3+25},origamiFromFriction:function(q){return(q-25)/3+8}};i(p,{fromOrigamiTensionAndFriction:function(q,r){return new p(k.tensionFromOrigamiValue(q),k.frictionFromOrigamiValue(r))}});p.DEFAULT_ORIGAMI_SPRING_CONFIG=p.fromOrigamiTensionAndFriction(40,7);i(p.prototype,{friction:0,tension:0});var e=d.MathUtil={mapValueInRange:function(t,q,u,s,r){fromRangeSize=u-q;toRangeSize=r-s;valueScale=(t-q)/fromRangeSize;return s+(valueScale*toRangeSize)}};function a(s,r){var q=s.indexOf(r);q!=-1&&s.splice(q,1)}function f(r){var q;if(typeof process!="undefined"){q=setImmediate}else{q=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame}return q(r)}var l=Array.prototype.concat;var m=Array.prototype.slice;function j(r,q){args=m.call(arguments,2);return function(){r.apply(q,l.call(args,m.call(arguments)))}}function i(s,r){for(var q in r){if(r.hasOwnProperty(q)){s[q]=r[q]}}}if(typeof exports!="undefined"){i(exports,d)}else{if(typeof window!="undefined"){window.rebound=d}}})();
(function(){var d={};var n=d.SpringSystem=function n(q){this._springRegistry={};this._activeSprings=[];this.listeners=[];this._idleSpringIndices=[];this.looper=q||new o();this.looper.springSystem=this};i(n.prototype,{_springRegistry:null,_isIdle:true,_lastTimeMillis:-1,_activeSprings:null,listeners:null,_idleSpringIndices:null,setLooper:function(q){this.looper=q;q.springSystem=this},createSpring:function(r,t){var q=new c(this);this.registerSpring(q);if(typeof r==="undefined"||typeof t==="undefined"){q.setSpringConfig(p.DEFAULT_ORIGAMI_SPRING_CONFIG)}else{var s=p.fromOrigamiTensionAndFriction(r,t);q.setSpringConfig(s)}return q},getIsIdle:function(){return this._isIdle},getSpringById:function(q){return this._springRegistry[q]},getAllSprings:function(){var q=[];for(var r in this._springRegistry){if(this._springRegistry.hasOwnProperty(r)){q.push(this._springRegistry[r])}}return q},registerSpring:function(q){this._springRegistry[q.getId()]=q},deregisterSpring:function(q){a(this._activeSprings,q);delete this._springRegistry[q.getId()]},advance:function(v,t){while(this._idleSpringIndices.length>0){this._idleSpringIndices.pop()}for(var u=0,r=this._activeSprings.length;u<r;u++){var s=this._activeSprings[u];if(s.systemShouldAdvance()){s.advance(v/1000,t/1000)}else{this._idleSpringIndices.push(this._activeSprings.indexOf(s))}}while(this._idleSpringIndices.length>0){var q=this._idleSpringIndices.pop();q>=0&&this._activeSprings.splice(q,1)}},loop:function(u){var t;if(this._lastTimeMillis===-1){this._lastTimeMillis=u-1}var r=u-this._lastTimeMillis;this._lastTimeMillis=u;var s=0,q=this.listeners.length;for(s=0;s<q;s++){var t=this.listeners[s];t.onBeforeIntegrate&&t.onBeforeIntegrate(this)}this.advance(u,r);if(this._activeSprings.length===0){this._isIdle=true;this._lastTimeMillis=-1}for(s=0;s<q;s++){var t=this.listeners[s];t.onAfterIntegrate&&t.onAfterIntegrate(this)}if(!this._isIdle){this.looper.run()}},activateSpring:function(r){var q=this._springRegistry[r];if(this._activeSprings.indexOf(q)==-1){this._activeSprings.push(q)}if(this.getIsIdle()){this._isIdle=false;this.looper.run()}},addListener:function(q){this.listeners.push(q)},removeListener:function(q){a(this.listeners,q)},removeAllListeners:function(){this.listeners=[]}});var c=d.Spring=function c(q){this._id="s"+c._ID++;this._springSystem=q;this.listeners=[];this._currentState=new b();this._previousState=new b();this._tempState=new b()};i(c,{_ID:0,MAX_DELTA_TIME_SEC:0.064,SOLVER_TIMESTEP_SEC:0.001});i(c.prototype,{_id:0,_springConfig:null,_overshootClampingEnabled:false,_currentState:null,_previousState:null,_tempState:null,_startValue:0,_endValue:0,_wasAtRest:true,_restSpeedThreshold:0.001,_displacementFromRestThreshold:0.001,listeners:null,_timeAccumulator:0,_springSystem:null,destroy:function(){this.listeners=[];this._springSystem.deregisterSpring(this)},getId:function(){return this._id},setSpringConfig:function(q){this._springConfig=q;return this},getSpringConfig:function(){return this._springConfig},setCurrentValue:function(s){this._startValue=s;this._currentState.position=s;for(var r=0,q=this.listeners.length;r<q;r++){var t=this.listeners[r];t.onSpringUpdate&&t.onSpringUpdate(this)}return this},getStartValue:function(){return this._startValue},getCurrentValue:function(){return this._currentState.position},getCurrentDisplacementDistance:function(){return this.getDisplacementDistanceForState(this._currentState)},getDisplacementDistanceForState:function(q){return Math.abs(this._endValue-q.position)},setEndValue:function(r){if(this._endValue==r&&this.isAtRest()){return this}this._startValue=this.getCurrentValue();this._endValue=r;this._springSystem.activateSpring(this.getId());for(var s=0,q=this.listeners.length;s<q;s++){var t=this.listeners[s];t.onSpringEndStateChange&&t.onSpringEndStateChange(this)}return this},getEndValue:function(){return this._endValue},setVelocity:function(q){this._currentState.velocity=q;return this},getVelocity:function(){return this._currentState.velocity},setRestSpeedThreshold:function(q){this._restSpeedThreshold=q;return this},getRestSpeedThreshold:function(){return this._restSpeedThreshold},setRestDisplacementThreshold:function(q){this._displacementFromRestThreshold=q},getRestDisplacementThreshold:function(){return this._displacementFromRestThreshold},setOvershootClampingEnabled:function(q){this._overshootClampingEnabled=q;return this},isOvershootClampingEnabled:function(){return this._overshootClampingEnabled},isOvershooting:function(){return(this._startValue<this._endValue&&this.getCurrentValue()>this._endValue)||(this._startValue>this._endValue&&this.getCurrentValue()<this._endValue)},advance:function(x,z){var F=this.isAtRest();if(F&&this._wasAtRest){return}var u=z;if(z>c.MAX_DELTA_TIME_SEC){u=c.MAX_DELTA_TIME_SEC}this._timeAccumulator+=u;var B=this._springConfig.tension,w=this._springConfig.friction,N=this._currentState.position,C=this._currentState.velocity,K=this._tempState.position,G=this._tempState.velocity,r,L,E,O,q,t,D,y,M,H;while(this._timeAccumulator>=c.SOLVER_TIMESTEP_SEC){this._timeAccumulator-=c.SOLVER_TIMESTEP_SEC;if(this._timeAccumulator<c.SOLVER_TIMESTEP_SEC){this._previousState.position=N;this._previousState.velocity=C}r=C;L=(B*(this._endValue-K))-w*C;K=N+r*c.SOLVER_TIMESTEP_SEC*0.5;G=C+L*c.SOLVER_TIMESTEP_SEC*0.5;E=G;O=(B*(this._endValue-K))-w*G;K=N+E*c.SOLVER_TIMESTEP_SEC*0.5;G=C+O*c.SOLVER_TIMESTEP_SEC*0.5;q=G;t=(B*(this._endValue-K))-w*G;K=N+q*c.SOLVER_TIMESTEP_SEC*0.5;G=C+t*c.SOLVER_TIMESTEP_SEC*0.5;D=G;y=(B*(this._endValue-K))-w*G;M=1/6*(r+2*(E+q)+D);H=1/6*(L+2*(O+t)+y);N+=M*c.SOLVER_TIMESTEP_SEC;C+=H*c.SOLVER_TIMESTEP_SEC}this._tempState.position=K;this._tempState.velocity=G;this._currentState.position=N;this._currentState.velocity=C;if(this._timeAccumulator>0){this.interpolate(this._timeAccumulator/c.SOLVER_TIMESTEP_SEC)}if(this.isAtRest()||this._overshootClampingEnabled&&this.isOvershooting()){this._startValue=this._endValue;this._currentState.position=this._endValue;this.setVelocity(0);F=true}var s=false;if(this._wasAtRest){this._wasAtRest=false;s=true}var A=false;if(F){this._wasAtRest=true;A=true}for(var I=0,J=this.listeners.length;I<J;I++){var v=this.listeners[I];if(s){v.onSpringActivate&&v.onSpringActivate(this)}v.onSpringUpdate&&v.onSpringUpdate(this);if(A){v.onSpringAtRest&&v.onSpringAtRest(this)}}},systemShouldAdvance:function(){return !this.isAtRest()||!this.wasAtRest()},wasAtRest:function(){return this._wasAtRest},isAtRest:function(){return Math.abs(this._currentState.velocity)<this._restSpeedThreshold&&this.getDisplacementDistanceForState(this._currentState)<=this._displacementFromRestThreshold},setAtRest:function(){this._endValue=this._currentState.position;this._tempState.position=this._currentState.position;this._currentState.velocity=0;return this},interpolate:function(q){this._currentState.position=this._currentState.position*q+this._previousState.position*(1-q);this._currentState.velocity=this._currentState.velocity*q+this._previousState.velocity*(1-q)},getListeners:function(){return this.listeners},addListener:function(q){this.listeners.push(q);return this},removeListener:function(q){a(this.listeners,q);return this},removeAllListeners:function(){this.listeners=[];return this},currentValueIsApproximately:function(q){return Math.abs(this.getCurrentValue()-q)<=this.getRestDisplacementThreshold()}});var b=function b(){};i(b.prototype,{position:0,velocity:0});var p=d.SpringConfig=function p(q,r){this.tension=q;this.friction=r};var o=d.AnimationLooper=function o(){this.springSystem=null;var r=this;var q=function(){r.springSystem.loop(Date.now())};this.run=function(){f(q)}};var h=d.SimulationLooper=function h(q){this.springSystem=null;var s=0;var r=false;q=q||16.667;this.run=function(){if(r){return}r=true;while(!this.springSystem.getIsIdle()){this.springSystem.loop(s+=q)}r=false}};var g=d.SteppingSimulationLooper=function(q){this.springSystem=null;var s=0;var r=false;this.run=function(){};this.step=function(t){this.springSystem.loop(s+=t)}};var k={tensionFromOrigamiValue:function(q){return(q-30)*3.62+194},origamiValueFromTension:function(q){return(q-194)/3.62+30},frictionFromOrigamiValue:function(q){return(q-8)*3+25},origamiFromFriction:function(q){return(q-25)/3+8}};i(p,{fromOrigamiTensionAndFriction:function(q,r){return new p(k.tensionFromOrigamiValue(q),k.frictionFromOrigamiValue(r))}});p.DEFAULT_ORIGAMI_SPRING_CONFIG=p.fromOrigamiTensionAndFriction(40,7);i(p.prototype,{friction:0,tension:0});var e=d.MathUtil={mapValueInRange:function(t,q,u,s,r){fromRangeSize=u-q;toRangeSize=r-s;valueScale=(t-q)/fromRangeSize;return s+(valueScale*toRangeSize)}};function a(s,r){var q=s.indexOf(r);q!=-1&&s.splice(q,1)}function f(r){var q;if(typeof process!="undefined"){q=setImmediate}else{q=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame}return q(r)}var l=Array.prototype.concat;var m=Array.prototype.slice;function j(r,q){args=m.call(arguments,2);return function(){r.apply(q,l.call(args,m.call(arguments)))}}function i(s,r){for(var q in r){if(r.hasOwnProperty(q)){s[q]=r[q]}}}if(typeof exports!="undefined"){i(exports,d)}else{if(typeof window!="undefined"){window.rebound=d}}})();
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc