@2gis/general
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -1,2 +0,2 @@ | ||
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.General=e():r.General=e()}(this,function(){return function(r){function e(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=r,e.c=n,e.d=function(r,n,t){e.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:t})},e.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(n,"a",n),n},e.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},e.p="/dist/",e(e.s=1)}([function(r,e,n){"use strict";n.d(e,"a",function(){return t}),n.d(e,"b",function(){return o});var t={pixelPositionX:0,pixelPositionY:1,groupIndex:2,iconIndex:3,prevGroupIndex:4},o=Object.keys(t).length},function(r,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t=n(2);n.d(e,"General",function(){return t.a})},function(r,e,n){"use strict";n.d(e,"a",function(){return a});var t=n(0),o=n(3),i=n.n(o),a=function(){function r(){var r=this;this.worker=i()(4),this.queue=[],this.currentJob=void 0,this.markerArray=new Float32Array(1e3*t.b),this.worker.onmessage=function(e){if(void 0!==r.currentJob){var n=r.currentJob,t=n.markers,o=n.resolve;r.recordResult(t,e.data),r.markerArray=e.data,r.currentJob=void 0,r.dequeue(),o()}}}return r.prototype.generalize=function(r,e,n,t,o){var i=this,a={bounds:r,pixelRatio:e,priorityGroups:n,sprites:t.sprites};return new Promise(function(r){i.queue.push({message:a,markers:o,resolve:r}),i.dequeue()})},r.prototype.clear=function(){this.queue=[]},r.prototype.pack=function(r){r.length*t.b>this.markerArray.length&&(this.markerArray=new Float32Array(r.length*t.b));for(var e=this.markerArray,n=0,o=0;n<r.length;n++,o+=t.b){var i=r[n],a=i.iconIndex,u=i.prevGroupIndex;this.markerArray[o+t.a.pixelPositionX]=i.pixelPosition[0],this.markerArray[o+t.a.pixelPositionY]=i.pixelPosition[1],e[o+t.a.groupIndex]=i.groupIndex,e[o+t.a.iconIndex]=void 0!==a?a:NaN,e[o+t.a.prevGroupIndex]=void 0!==u?u:NaN}},r.prototype.dequeue=function(){if(void 0===this.currentJob){var r=this.queue.shift();if(void 0!==r){this.pack(r.markers);var e=r.message;e.markers=this.markerArray,e.markerCount=r.markers.length,this.worker.postMessage(e,[e.markers.buffer]),this.currentJob=r}}},r.prototype.recordResult=function(r,e){for(var n=0,o=0;n<r.length;n++,o+=t.b){var i=e[o+t.a.iconIndex],a=e[o+t.a.prevGroupIndex];r[n].iconIndex=i!==i?void 0:i,r[n].prevGroupIndex=a!==a?void 0:a}},r}()},function(r,e,n){function t(r){function e(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};e.m=r,e.c=n,e.i=function(r){return r},e.d=function(r,n,t){e.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:t})},e.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(n,"a",n),n},e.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},e.p="/",e.oe=function(r){throw console.error(r),r};var t=e(e.s=ENTRY_MODULE);return t.default||t}function o(r){return(r+"").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&")}function i(r){var e=[],n=r.toString(),t=n.match(/^function\s?\(\w+,\s*\w+,\s*(\w+)\)/);if(!t)return e;for(var i,a=t[1],u=new RegExp("(\\\\n|\\W)"+o(a)+"\\((/\\*.*?\\*/)?s?.*?([\\.|\\-|\\w|/|@]+).*?\\)","g");i=u.exec(n);)e.push(i[3]);return e}function a(r,e){for(var n=[e],t=[],o={};n.length;){var a=n.pop();if(!o[a]&&r[a]){o[a]=!0,t.push(a);var u=i(r[a]);n=n.concat(u)}}return t}r.exports=function(r,e){e=e||{};var o=n.m,i=e.all?Object.keys(o):a(o,r),u="("+t.toString().replace("ENTRY_MODULE",JSON.stringify(r))+")({"+i.map(function(r){return JSON.stringify(r)+": "+o[r].toString()}).join(",")+"})(self);",s=new window.Blob([u],{type:"text/javascript"});if(e.bare)return s;var c=window.URL||window.webkitURL||window.mozURL||window.msURL,f=c.createObjectURL(s),p=new window.Worker(f);return p.objectURL=f,p}},function(r,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t=n(5);e.default=function(r){r.onmessage=function(e){var n=e.data;Object(t.a)(n),r.postMessage(n.markers)}}},function(r,e,n){"use strict";function t(r){for(var e=r.bounds,n=r.pixelRatio,t=r.priorityGroups,l=r.sprites,m=r.markers,x=r.markerCount,v=1+(e.maxX-e.minX>>3)<<3,b=e.maxY-e.minY,h=v*b+8>>3,y=new Uint8Array(h),g=new Uint8Array(h),w=new Uint8Array(h),k=0;k<x;k++){var Y=m[k*c.b+c.a.prevGroupIndex],I=m[k*c.b+c.a.pixelPositionX],X=m[k*c.b+c.a.pixelPositionY];if(!a(Y)){var P=t[Y],j=P.iconIndex,O=P.margin,A=P.degradation,G=l[j];if(!G)continue;var R=G.size,U=G.anchor,_=G.pixelDensity;s(p,v,b,n,R,U,_,I,X,O),u(p)||i(y,v,p),s(d,v,b,n,R,U,_,I,X,A),u(d)||i(w,v,d)}}for(var k=0;k<t.length;k++){var J=t[k],L=J.safeZone,j=J.iconIndex,O=J.margin,A=J.degradation,G=l[j];if(G){var R=G.size,U=G.anchor,_=G.pixelDensity;g.set(w);for(var M=0;M<x;M++){var N=M*c.b,q=m[N+c.a.groupIndex],Y=m[N+c.a.prevGroupIndex],I=m[N+c.a.pixelPositionX],X=m[N+c.a.pixelPositionY];q>k||!a(Y)||(s(p,v,b,n,R,U,_,I,X,O),u(p)||q===k&&o(g,v,p)||(s(f,v,b,n,R,U,_,I,X,L),u(f)||o(y,v,f)||(s(d,v,b,n,R,U,_,I,X,A),i(y,v,p),i(w,v,d),m[N+c.a.iconIndex]=j,m[N+c.a.prevGroupIndex]=k)))}}}}function o(r,e,n){for(var t=n.minX,o=n.minY,i=n.maxX,a=n.maxY,u=o;u<a;u++){var s=u*e+t>>3,c=u*e+i>>3,f=0;if(s===c)f=r[s]&255>>(7&t)&255<<8-(7&i);else{f=r[s]&255>>(7&t);for(var p=s+1;p<c;p++)f=r[p]|f;f=r[c]&255<<8-(7&i)|f}if(0!==f)return!0}return!1}function i(r,e,n){for(var t=n.minX,o=n.minY,i=n.maxX,a=n.maxY,u=o;u<a;u++){var s=u*e+t>>3,c=u*e+i>>3;if(s===c)r[s]=r[s]|255>>(7&t)&255<<8-(7&i);else{r[s]=r[s]|255>>(7&t);for(var f=s+1;f<c;f++)r[f]=255;r[c]=r[c]|255<<8-(7&i)}}}function a(r){return r!==r}function u(r){return r.minX===r.maxX||r.minY===r.maxY}function s(r,e,n,t,o,i,a,u,s,c){var f=t/a,p=u*t-o[0]*f*i[0]-c|0,d=s*t-o[1]*f*i[1]-c|0,l=u*t+o[0]*f*(1-i[0])+c|0,m=s*t+o[1]*f*(1-i[1])+c|0;r.minX=p>0?p<e?p:e:0,r.minY=d>0?d<n?d:n:0,r.maxX=l>0?l<e?l:e:0,r.maxY=m>0?m<n?m:n:0}e.a=t;var c=n(0),f={minX:0,minY:0,maxX:0,maxY:0},p={minX:0,minY:0,maxX:0,maxY:0},d={minX:0,minY:0,maxX:0,maxY:0}}])}); | ||
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.General=e():r.General=e()}(this,function(){return function(r){function e(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=r,e.c=n,e.d=function(r,n,t){e.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:t})},e.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(n,"a",n),n},e.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},e.p="/dist/",e(e.s=1)}([function(r,e,n){"use strict";n.d(e,"a",function(){return t}),n.d(e,"b",function(){return o});var t={pixelPositionX:0,pixelPositionY:1,groupIndex:2,iconIndex:3,prevGroupIndex:4},o=Object.keys(t).length},function(r,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t=n(2);n.d(e,"General",function(){return t.a})},function(r,e,n){"use strict";n.d(e,"a",function(){return a});var t=n(0),o=n(3),i=n.n(o),a=function(){function r(){var r=this;this.worker=i()(4),this.queue=[],this.currentJob=void 0,this.markerArray=new Float32Array(1e3*t.b),this.worker.onmessage=function(e){if(void 0!==r.currentJob){var n=r.currentJob,t=n.markers,o=n.resolve;r.recordResult(t,e.data),r.markerArray=e.data,r.currentJob=void 0,r.dequeue(),o()}}}return r.prototype.generalize=function(r,e,n,t,o){var i=this,a={bounds:r,pixelRatio:e,priorityGroups:n,sprites:t};return new Promise(function(r){i.queue.push({message:a,markers:o,resolve:r}),i.dequeue()})},r.prototype.clear=function(){this.queue=[]},r.prototype.pack=function(r){r.length*t.b>this.markerArray.length&&(this.markerArray=new Float32Array(r.length*t.b));for(var e=this.markerArray,n=0,o=0;n<r.length;n++,o+=t.b){var i=r[n],a=i.iconIndex,u=i.prevGroupIndex;this.markerArray[o+t.a.pixelPositionX]=i.pixelPosition[0],this.markerArray[o+t.a.pixelPositionY]=i.pixelPosition[1],e[o+t.a.groupIndex]=i.groupIndex,e[o+t.a.iconIndex]=void 0!==a?a:NaN,e[o+t.a.prevGroupIndex]=void 0!==u?u:NaN}},r.prototype.dequeue=function(){if(void 0===this.currentJob){var r=this.queue.shift();if(void 0!==r){this.pack(r.markers);var e=r.message;e.markers=this.markerArray,e.markerCount=r.markers.length,this.worker.postMessage(e,[e.markers.buffer]),this.currentJob=r}}},r.prototype.recordResult=function(r,e){for(var n=0,o=0;n<r.length;n++,o+=t.b){var i=e[o+t.a.iconIndex],a=e[o+t.a.prevGroupIndex];r[n].iconIndex=i!==i?void 0:i,r[n].prevGroupIndex=a!==a?void 0:a}},r}()},function(r,e,n){function t(r){function e(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};e.m=r,e.c=n,e.i=function(r){return r},e.d=function(r,n,t){e.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:t})},e.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(n,"a",n),n},e.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},e.p="/",e.oe=function(r){throw console.error(r),r};var t=e(e.s=ENTRY_MODULE);return t.default||t}function o(r){return(r+"").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&")}function i(r){var e=[],n=r.toString(),t=n.match(/^function\s?\(\w+,\s*\w+,\s*(\w+)\)/);if(!t)return e;for(var i,a=t[1],u=new RegExp("(\\\\n|\\W)"+o(a)+"\\((/\\*.*?\\*/)?s?.*?([\\.|\\-|\\w|/|@]+).*?\\)","g");i=u.exec(n);)e.push(i[3]);return e}function a(r,e){for(var n=[e],t=[],o={};n.length;){var a=n.pop();if(!o[a]&&r[a]){o[a]=!0,t.push(a);var u=i(r[a]);n=n.concat(u)}}return t}r.exports=function(r,e){e=e||{};var o=n.m,i=e.all?Object.keys(o):a(o,r),u="("+t.toString().replace("ENTRY_MODULE",JSON.stringify(r))+")({"+i.map(function(r){return JSON.stringify(r)+": "+o[r].toString()}).join(",")+"})(self);",s=new window.Blob([u],{type:"text/javascript"});if(e.bare)return s;var c=window.URL||window.webkitURL||window.mozURL||window.msURL,f=c.createObjectURL(s),p=new window.Worker(f);return p.objectURL=f,p}},function(r,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t=n(5);e.default=function(r){r.onmessage=function(e){var n=e.data;Object(t.a)(n),r.postMessage(n.markers)}}},function(r,e,n){"use strict";function t(r){for(var e=r.bounds,n=r.pixelRatio,t=r.priorityGroups,l=r.sprites,m=r.markers,x=r.markerCount,v=1+(e.maxX-e.minX>>3)<<3,b=e.maxY-e.minY,h=v*b+8>>3,y=new Uint8Array(h),g=new Uint8Array(h),w=new Uint8Array(h),k=0;k<x;k++){var Y=m[k*c.b+c.a.prevGroupIndex],I=m[k*c.b+c.a.pixelPositionX],X=m[k*c.b+c.a.pixelPositionY];if(!a(Y)){var P=t[Y],j=P.iconIndex,O=P.margin,A=P.degradation,G=l[j];if(!G)continue;var R=G.size,U=G.anchor,_=G.pixelDensity;s(p,v,b,n,R,U,_,I,X,O),u(p)||i(y,v,p),s(d,v,b,n,R,U,_,I,X,A),u(d)||i(w,v,d)}}for(var k=0;k<t.length;k++){var J=t[k],L=J.safeZone,j=J.iconIndex,O=J.margin,A=J.degradation,G=l[j];if(G){var R=G.size,U=G.anchor,_=G.pixelDensity;g.set(w);for(var M=0;M<x;M++){var N=M*c.b,q=m[N+c.a.groupIndex],Y=m[N+c.a.prevGroupIndex],I=m[N+c.a.pixelPositionX],X=m[N+c.a.pixelPositionY];q>k||!a(Y)||(s(p,v,b,n,R,U,_,I,X,O),u(p)||q===k&&o(g,v,p)||(s(f,v,b,n,R,U,_,I,X,L),u(f)||o(y,v,f)||(s(d,v,b,n,R,U,_,I,X,A),i(y,v,p),i(w,v,d),m[N+c.a.iconIndex]=j,m[N+c.a.prevGroupIndex]=k)))}}}}function o(r,e,n){for(var t=n.minX,o=n.minY,i=n.maxX,a=n.maxY,u=o;u<a;u++){var s=u*e+t>>3,c=u*e+i>>3,f=0;if(s===c)f=r[s]&255>>(7&t)&255<<8-(7&i);else{f=r[s]&255>>(7&t);for(var p=s+1;p<c;p++)f=r[p]|f;f=r[c]&255<<8-(7&i)|f}if(0!==f)return!0}return!1}function i(r,e,n){for(var t=n.minX,o=n.minY,i=n.maxX,a=n.maxY,u=o;u<a;u++){var s=u*e+t>>3,c=u*e+i>>3;if(s===c)r[s]=r[s]|255>>(7&t)&255<<8-(7&i);else{r[s]=r[s]|255>>(7&t);for(var f=s+1;f<c;f++)r[f]=255;r[c]=r[c]|255<<8-(7&i)}}}function a(r){return r!==r}function u(r){return r.minX===r.maxX||r.minY===r.maxY}function s(r,e,n,t,o,i,a,u,s,c){var f=t/a,p=u*t-o[0]*f*i[0]-c|0,d=s*t-o[1]*f*i[1]-c|0,l=u*t+o[0]*f*(1-i[0])+c|0,m=s*t+o[1]*f*(1-i[1])+c|0;r.minX=p>0?p<e?p:e:0,r.minY=d>0?d<n?d:n:0,r.maxX=l>0?l<e?l:e:0,r.maxY=m>0?m<n?m:n:0}e.a=t;var c=n(0),f={minX:0,minY:0,maxX:0,maxY:0},p={minX:0,minY:0,maxX:0,maxY:0},d={minX:0,minY:0,maxX:0,maxY:0}}])}); | ||
//# sourceMappingURL=general.js.map |
@@ -1,2 +0,2 @@ | ||
import { BBox, PriorityGroup, Atlas, Marker } from './types'; | ||
import { BBox, PriorityGroup, Sprite, Marker } from './types'; | ||
export declare class General { | ||
@@ -8,3 +8,3 @@ private worker; | ||
constructor(); | ||
generalize(bounds: BBox, pixelRatio: number, priorityGroups: PriorityGroup[], atlas: Atlas, markers: Marker[]): Promise<{}>; | ||
generalize(bounds: BBox, pixelRatio: number, priorityGroups: PriorityGroup[], sprites: Sprite[], markers: Marker[]): Promise<{}>; | ||
clear(): void; | ||
@@ -11,0 +11,0 @@ /** |
@@ -7,5 +7,2 @@ export declare type Vec2 = [number, number] | Float64Array | number[]; | ||
} | ||
export interface Atlas { | ||
sprites: Sprite[]; | ||
} | ||
export interface Marker { | ||
@@ -12,0 +9,0 @@ pixelPosition: Vec2; |
{ | ||
"name": "@2gis/general", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Fast marker generalization algorithm", | ||
@@ -19,3 +19,3 @@ "contributors": [ | ||
"type": "git", | ||
"url": "git@github.com:2gis/general.git" | ||
"url": "git://github.com/2gis/general.git" | ||
}, | ||
@@ -39,5 +39,3 @@ "main": "dist/general.js", | ||
"@types/node": "^8.0.14", | ||
"@types/rbush": "^2.0.2", | ||
"mocha": "^3.4.2", | ||
"rbush": "^2.0.1", | ||
"ts-loader": "^2.3.1", | ||
@@ -51,4 +49,5 @@ "ts-node": "^3.2.1", | ||
"webpack-dev-server": "^2.5.1", | ||
"webworkify-webpack": "^2.0.5" | ||
"webworkify-webpack": "^2.0.5", | ||
"whatwg-fetch": "^2.0.3" | ||
} | ||
} |
@@ -94,3 +94,3 @@ # General [![Build Status](https://travis-ci.org/2gis/general.svg?branch=master)](https://travis-ci.org/2gis/general) | ||
- `groups: PriorityGroup[]` – массив групп маркеров с настройками для генерализации | ||
- `atlas: Sprite[]` – массив объектов описывающих размеры иконов, которые могут использоваться маркерами | ||
- `atlas: Sprite[]` – массив объектов описывающих размеры иконок, которые могут использоваться маркерами | ||
- `markers: Marker[]` – массив маркеров | ||
@@ -97,0 +97,0 @@ |
@@ -5,3 +5,3 @@ import { stride, offsets } from './markerArray'; | ||
PriorityGroup, | ||
Atlas, | ||
Sprite, | ||
Marker, | ||
@@ -45,3 +45,3 @@ WorkerMessage, | ||
priorityGroups: PriorityGroup[], | ||
atlas: Atlas, | ||
sprites: Sprite[], | ||
markers: Marker[], | ||
@@ -53,3 +53,3 @@ ): Promise<{}> { | ||
priorityGroups, | ||
sprites: atlas.sprites, | ||
sprites, | ||
}; | ||
@@ -56,0 +56,0 @@ |
@@ -9,6 +9,2 @@ export type Vec2 = [number, number] | Float64Array | number[]; | ||
export interface Atlas { | ||
sprites: Sprite[]; | ||
} | ||
export interface Marker { | ||
@@ -15,0 +11,0 @@ pixelPosition: Vec2; // позиция маркера в пикселях |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16
209789
23
665