forked from davidson16807/fast-multipole-method
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast-multipole-method.min.js
1 lines (1 loc) · 4.85 KB
/
fast-multipole-method.min.js
1
"use strict";var FMM=function(){var r={};return r.Field2=function(r,n,t,o,e){function u(r,n,t){return{level:r,x:n,y:t}}function i(r,n,t){return{x:r,y:n}}function f(r){return r.level+","+r.x+","+r.y}function a(r){return void 0!==r.x&&void 0!==r.y?r:i(r[0],r[1])}function c(r,n){return i(n.x-r.x,n.y-r.y)}function l(r){return u(r.level+1,Math.floor(r.x/2),Math.floor(r.y/2))}function v(r){for(var n={},t=0,o=r.length;o>t;t++){var e=l(r[t]);n[f(e)]=e}var u=[];for(var e in n)u.push(n[e]);return u}function d(r){for(var n=[],t=0;1>=t;t++)for(var o=0;1>=o;o++)n.push(u(r.level-1,2*r.x+t,2*r.y+o));return n}function h(r){return i((r.x+.5)*Math.pow(2,r.level),(r.y+.5)*Math.pow(2,r.level))}function M(r,n){return u(n,Math.floor(r.x/Math.pow(2,n)),Math.floor(r.y/Math.pow(2,n)))}function g(r){for(var n=[],t=s;F>t;t++)n.push(M(r,t));return n}function x(r,n){for(var t=M(r,n),o=[],e=-1;1>=e;e++)for(var i=-1;1>=i;i++)o.push(u(n,t.x+e,t.y+i));return o}function y(r){for(var n=[],t=s;F>t;t++)n.push(x(r,t));return n}function _(r,n,t,o,e){var u=M(n,s),i=y(n),l={};l[f(u)]=u;for(var g=0,x=i.length;x>g;g++)for(var _=i[g],p=v(_),E=0,F=p.length;F>E;E++){var z=p[E];l[f(z)]=z;for(var w=d(z),V=0,H=w.length;H>V;V++){var R=w[V],T=f(R);if(void 0===l[T]){var m=a(o(c(h(R),n),t)),b=r[T];void 0!==b?r[T]=e(b,m):r[T]=m}}}}function p(r,n,t){for(var o in n)void 0!==r[o]?r[o]=t(r[o],n[o]):r[o]=n[o]}function E(r,n){for(var t=void 0,e=g(n),u=0,i=e.length;i>u;u++){var a=e[u];void 0!==r[f(a)]&&(t=void 0!==t?o(r[f(a)],t):r[f(a)])}return t}var s=r?Math.floor(Math.log(r)/Math.log(2)):0,F=n?Math.floor(Math.log(n)/Math.log(2)):0,z={};return z._grid={},z.value=function(r){var n=E(z._grid,a(r));return n},z.clear=function(){z._grid={}},z.add_field=function(r){p(z._grid,r._grid,o)},z.remove_field=function(r){p(z._grid,r._grid,e)},z.add_particle=function(r,n){n=n||{},_(z._grid,a(r),n,t,o)},z.remove_particle=function(r,n){n=n||{},_(z._grid,a(r),n,t,e)},z},r.ScalarField2=function(n,t,o){return r.Field2(n,t,o,function(r,n){return r+n},function(r,n){return r-n})},r.VectorField2=function(n,t,o){return r.Field2(n,t,o,function(r,n){return{x:r.x+n.x,y:r.y+n.y}},function(r,n){return{x:r.x-n.x,y:r.y-n.y}})},r.Field3=function(r,n,t,o,e){function u(r,n,t,o){return{level:r,x:n,y:t,z:o}}function i(r,n,t){return{x:r,y:n,z:t}}function f(r){return r.level+","+r.x+","+r.y+","+r.z}function a(r){return void 0!==r.x&&void 0!==r.y&&void 0!==r.z?r:i(r[0],r[1],r[2])}function c(r,n){return i(n.x-r.x,n.y-r.y,n.z-r.z)}function l(r){return u(r.level+1,Math.floor(r.x/2),Math.floor(r.y/2),Math.floor(r.z/2))}function v(r){for(var n={},t=0,o=r.length;o>t;t++){var e=l(r[t]);n[f(e)]=e}var u=[];for(var e in n)u.push(n[e]);return u}function d(r){for(var n=[],t=0;1>=t;t++)for(var o=0;1>=o;o++)for(var e=0;1>=e;e++)n.push(u(r.level-1,2*r.x+t,2*r.y+o,2*r.z+e));return n}function h(r){return i((r.x+.5)*Math.pow(2,r.level),(r.y+.5)*Math.pow(2,r.level),(r.z+.5)*Math.pow(2,r.level))}function M(r,n){return u(n,Math.floor(r.x/Math.pow(2,n)),Math.floor(r.y/Math.pow(2,n)),Math.floor(r.z/Math.pow(2,n)))}function g(r){for(var n=[],t=s;F>t;t++)n.push(M(r,t));return n}function x(r,n){for(var t=M(r,n),o=[],e=-1;1>=e;e++)for(var i=-1;1>=i;i++)for(var f=-1;1>=f;f++)o.push(u(n,t.x+e,t.y+i,t.z+f));return o}function y(r){for(var n=[],t=s;F>t;t++)n.push(x(r,t));return n}function _(r,n,t,o,e){var u=M(n,s),i=y(n),l={};l[f(u)]=u;for(var g=0,x=i.length;x>g;g++)for(var _=i[g],p=v(_),E=0,F=p.length;F>E;E++){var z=p[E];l[f(z)]=z;for(var w=d(z),V=0,H=w.length;H>V;V++){var R=w[V],T=f(R);if(void 0===l[T]){var m=a(o(c(h(R),n),t)),b=r[T];void 0!==b?r[T]=e(b,m):r[T]=m}}}}function p(r,n,t){for(var o in n)void 0!==r[o]?r[o]=t(r[o],n[o]):r[o]=n[o]}function E(r,n){for(var t=void 0,e=g(n),u=0,i=e.length;i>u;u++){var a=e[u];void 0!==r[f(a)]&&(t=void 0!==t?o(r[f(a)],t):r[f(a)])}return t}var s=r?Math.floor(Math.log(r)/Math.log(2)):0,F=n?Math.floor(Math.log(n)/Math.log(2)):0,z={};return z._grid={},z.value=function(r){var n=E(z._grid,a(r));return n},z.clear=function(){z._grid={}},z.add_field=function(r){p(z._grid,r._grid,o)},z.remove_field=function(r){p(z._grid,r._grid,e)},z.add_particle=function(r,n){n=n||{},_(z._grid,a(r),n,t,o)},z.remove_particle=function(r,n){n=n||{},_(z._grid,a(r),n,t,e)},z},r.ScalarField3=function(n,t,o){return r.Field3(n,t,o,function(r,n){return r+n},function(r,n){return r-n})},r.VectorField3=function(n,t,o){return r.Field3(n,t,o,function(r,n){return Point(r.x+n.x,r.y+n.y,r.z+n.z)},function(r,n){return Point(r.x-n.x,r.y-n.y,r.z-n.z)})},r}(),THREE=THREE||{};THREE.VectorField2=function(r,n,t){return FMM.Field2(r,n,function(r,n){return t(new THREE.Vector2(r.x,r.y),n)},function(r,n){return THREE.Vector2.addVectors(r,n)},function(r,n){return THREE.Vector2.subVectors(r,n)})},THREE.VectorField3=function(r,n,t){return FMM.Field3(r,n,function(r,n){return t(new THREE.Vector3(r.x,r.y,r.z),n)},function(r,n){return(new THREE.Vector3).addVectors(r,n)},function(r,n){return(new THREE.Vector3).subVectors(r,n)})};