|
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.GridPartition=e()}})(function(){var e,t,r;return function e(t,r,n){function i(u,a){if(!r[u]){if(!t[u]){var l=typeof require=="function"&&require;if(!a&&l)return l(u,!0);if(o)return o(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var s=r[u]={exports:{}};t[u][0].call(s.exports,function(e){var r=t[u][1][e];return i(r?r:e)},s,s.exports,e,t,r,n)}return r[u].exports}var o=typeof require=="function"&&require;for(var u=0;u<n.length;u++)i(n[u]);return i}({1:[function(e,t,r){(function e(){"use strict";if(typeof ses!=="undefined"&&ses.ok&&!ses.ok()){return}function r(e){if(e.permitHostObjects___){e.permitHostObjects___(r)}}if(typeof ses!=="undefined"){ses.weakMapPermitHostObjects=r}var n=false;if(typeof WeakMap==="function"){var i=WeakMap;if(typeof navigator!=="undefined"&&/Firefox/.test(navigator.userAgent)){}else{var o=new i;var u=Object.freeze({});o.set(u,1);if(o.get(u)!==1){n=true}else{t.exports=WeakMap;return}}}var a=Object.prototype.hasOwnProperty;var l=Object.getOwnPropertyNames;var f=Object.defineProperty;var s=Object.isExtensible;var c="weakmap:";var p=c+"ident:"+Math.random()+"___";if(typeof crypto!=="undefined"&&typeof crypto.getRandomValues==="function"&&typeof ArrayBuffer==="function"&&typeof Uint8Array==="function"){var h=new ArrayBuffer(25);var d=new Uint8Array(h);crypto.getRandomValues(d);p=c+"rand:"+Array.prototype.map.call(d,function(e){return(e%36).toString(36)}).join("")+"___"}function v(e){return!(e.substr(0,c.length)==c&&e.substr(e.length-3)==="___")}f(Object,"getOwnPropertyNames",{value:function e(t){return l(t).filter(v)}});if("getPropertyNames"in Object){var _=Object.getPropertyNames;f(Object,"getPropertyNames",{value:function e(t){return _(t).filter(v)}})}function y(e){if(e!==Object(e)){throw new TypeError("Not an object: "+e)}var t=e[p];if(t&&t.key===e){return t}if(!s(e)){return void 0}t={key:e};try{f(e,p,{value:t,writable:false,enumerable:false,configurable:false});return t}catch(e){return void 0}}(function(){var e=Object.freeze;f(Object,"freeze",{value:function t(r){y(r);return e(r)}});var t=Object.seal;f(Object,"seal",{value:function e(r){y(r);return t(r)}});var r=Object.preventExtensions;f(Object,"preventExtensions",{value:function e(t){y(t);return r(t)}})})();function b(e){e.prototype=null;return Object.freeze(e)}var g=false;function w(){if(!g&&typeof console!=="undefined"){g=true;console.warn("WeakMap should be invoked as new WeakMap(), not "+"WeakMap(). This will be an error in the future.")}}var m=0;var O=function(){if(!(this instanceof O)){w()}var e=[];var t=[];var r=m++;function n(n,i){var o;var u=y(n);if(u){return r in u?u[r]:i}else{o=e.indexOf(n);return o>=0?t[o]:i}}function i(t){var n=y(t);if(n){return r in n}else{return e.indexOf(t)>=0}}function o(n,i){var o;var u=y(n);if(u){u[r]=i}else{o=e.indexOf(n);if(o>=0){t[o]=i}else{o=e.length;t[o]=i;e[o]=n}}return this}function u(n){var i=y(n);var o,u;if(i){return r in i&&delete i[r]}else{o=e.indexOf(n);if(o<0){return false}u=e.length-1;e[o]=void 0;t[o]=t[u];e[o]=e[u];e.length=u;t.length=u;return true}}return Object.create(O.prototype,{get___:{value:b(n)},has___:{value:b(i)},set___:{value:b(o)},delete___:{value:b(u)}})};O.prototype=Object.create(Object.prototype,{get:{value:function e(t,r){return this.get___(t,r)},writable:true,configurable:true},has:{value:function e(t){return this.has___(t)},writable:true,configurable:true},set:{value:function e(t,r){return this.set___(t,r)},writable:true,configurable:true},delete:{value:function e(t){return this.delete___(t)},writable:true,configurable:true}});if(typeof i==="function"){(function(){if(n&&typeof Proxy!=="undefined"){Proxy=undefined}function e(){if(!(this instanceof O)){w()}var e=new i;var t=undefined;var o=false;function u(r,n){if(t){return e.has(r)?e.get(r):t.get___(r,n)}else{return e.get(r,n)}}function a(r){return e.has(r)||(t?t.has___(r):false)}var l;if(n){l=function(r,n){e.set(r,n);if(!e.has(r)){if(!t){t=new O}t.set(r,n)}return this}}else{l=function(r,n){if(o){try{e.set(r,n)}catch(e){if(!t){t=new O}t.set___(r,n)}}else{e.set(r,n)}return this}}function f(r){var n=!!e["delete"](r);if(t){return t.delete___(r)||n}return n}return Object.create(O.prototype,{get___:{value:b(u)},has___:{value:b(a)},set___:{value:b(l)},delete___:{value:b(f)},permitHostObjects___:{value:b(function(e){if(e===r){o=true}else{throw new Error("bogus call to permitHostObjects___")}})}})}e.prototype=O.prototype;t.exports=e;Object.defineProperty(WeakMap.prototype,"constructor",{value:WeakMap,enumerable:false,configurable:true,writable:true})})()}else{if(typeof Proxy!=="undefined"){Proxy=undefined}t.exports=O}})()},{}],2:[function(e,t,r){(function(r){t.exports=r.WeakMap!==void 0?r.WeakMap:e("weak-map")}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"weak-map":1}],3:[function(e,t,r){"use strict";var n=e("collections/weak-map");var i=e("./util").isNullOrUndefined;var o=e("./util").mod;function u(e,t,r,n){this.width=i(e)?100:e;this.height=i(t)?100:t;this.numberCellsX=i(r)?10:r;this.numberCellsY=i(n)?10:n;this.cellWidth=this.width/this.numberCellsX;this.cellHeight=this.height/this.numberCellsY;this._x=function(e){return e.x};this._y=function(e){return e.y};this.clear()}u.prototype.add=function(e){var t=Math.floor(this._x.call(null,e));var r=Math.floor(this._y.call(null,e));var n=Math.floor(t/this.cellWidth);var i=Math.floor(r/this.cellHeight);this._cells[i][n].push(e);this._entityMap.set(e,[n,i])};u.prototype.addAll=function(e){e.forEach(function(e){this.add(e)}.bind(this))};u.prototype.clear=function(){this._cells=new Array(this.numberCellsX);for(var e=0;e<this.numberCellsY;e++){this._cells[e]=new Array(this.numberCellsX);for(var t=0;t<this.numberCellsX;t++){this._cells[e][t]=[]}}this._entityMap=new n};u.prototype.getCell=function(e,t){if(!this._isCellValid(e,t))return null;return this._cells[t][e]};u.prototype.getCellByWorldCoord=function(e,t){var r=Math.floor(e/this.cellWidth);var n=Math.floor(t/this.cellHeight);return this.getCell(r,n)};u.prototype.getNeighbourhood=function(e,t,r,n){if(i(r)){r=1}if(r<0){r=0}if(i(n)){n=false}var u=[];var a,l,f,s,c;for(a=e-r;a<=e+r;a++){for(l=t-r;l<=t+r;l++){f=o(a,this.numberCellsX);s=o(l,this.numberCellsY);if(!n&&(f!==a||s!==l)){continue}c=this.getCell(f,s);u=u.concat(c)}}return u};u.prototype.getNeighbourhoodByWorldCoord=function(e,t,r,n){var i=Math.floor(Math.floor(e)/this.cellWidth);var o=Math.floor(Math.floor(t)/this.cellHeight);return this.getNeighbourhood(i,o,r,n)};u.prototype.update=function(e){if(!this.remove(e))return false;this.add(e);return true};u.prototype.updateAll=function(e){this.clear();this.addAll(e)};u.prototype.remove=function(e){var t=this._entityMap.get(e);if(i(t))return false;var r=this.getCell(t[0],t[1]);var n=r.indexOf(e);r.splice(n,1);delete this._entityMap[e];return true};u.prototype.x=function(e){if(!i(e)){this._x=e;return this}return this._x};u.prototype.y=function(e){if(!i(e)){this._y=e;return this}return this._y};u.prototype._isCellValid=function(e,t){return e>=0&&t>=0&&e<this.numberCellsX&&t<this.numberCellsY};t.exports=u},{"./util":4,"collections/weak-map":2}],4:[function(e,t,r){"use strict";t.exports={isNullOrUndefined:function(e){return e===null||e===undefined},mod:function(e,t){return(e%t+t)%t}}},{}]},{},[3])(3)}); |