polygon-offset
Advanced tools
@@ -5,13 +5,13 @@ /* | ||
| function s(){return function q(k,d,h){function f(a,c){if(!d[a]){if(!k[a]){var b="function"==typeof require&&require;if(!c&&b)return b(a,!0);if(g)return g(a,!0);b=Error("Cannot find module '"+a+"'");throw b.code="MODULE_NOT_FOUND",b;}b=d[a]={exports:{}};k[a][0].call(b.exports,function(b){var c=k[a][1][b];return f(c?c:b)},b,b.exports,q,k,d,h)}return d[a].exports}for(var g="function"==typeof require&&require,m=0;m<h.length;m++)f(h[m]);return f}({1:[function(q,k,d){(function(h,f){"object"===typeof d? | ||
| k.exports=f():window.greinerHormann=f()})(this,function(){function h(a,c){this.first=null;this.g=0;this.m=null;this.p="undefined"===typeof c?Array.isArray(a[0]):c;for(var b=0,e=a.length;b<e;b++)this.i(new g(a[b]))}function d(a,c,b,e){this.k=this.toSource=this.y=this.x=0;var l=(e.y-b.y)*(c.x-a.x)-(e.x-b.x)*(c.y-a.y);0!==l&&(this.toSource=((e.x-b.x)*(a.y-b.y)-(e.y-b.y)*(a.x-b.x))/l,this.k=((c.x-a.x)*(a.y-b.y)-(c.y-a.y)*(a.x-b.x))/l,this.valid()&&(this.x=a.x+this.toSource*(c.x-a.x),this.y=a.y+this.toSource* | ||
| (c.y-a.y)))}function g(a,c){1===arguments.length&&(Array.isArray(a)?(c=a[1],a=a[0]):(c=a.y,a=a.x));this.x=a;this.y=c;this.e=this.c=this.next=null;this.l=0;this.h=!0;this.f=this.a=!1}function m(a,c,b,e){a=new h(a);c=new h(c);return a.clip(c,b,e)}Array.isArray=Array.isArray||function(a){return Boolean(a&&"[object Array]"===Object.prototype.toString.call(Object(a)))};g.u=function(a,c,b){a=new g(a,c);a.l=b;a.a=!0;a.h=!1;return a};g.prototype.C=function(){this.f=!0;null===this.e||this.e.f||this.e.C()}; | ||
| k.exports=f():window.greinerHormann=f()})(this,function(){function h(a,c){this.first=null;this.g=0;this.n=null;this.p="undefined"===typeof c?Array.isArray(a[0]):c;for(var b=0,e=a.length;b<e;b++)this.i(new g(a[b]))}function d(a,c,b,e){this.k=this.toSource=this.y=this.x=0;var l=(e.y-b.y)*(c.x-a.x)-(e.x-b.x)*(c.y-a.y);0!==l&&(this.toSource=((e.x-b.x)*(a.y-b.y)-(e.y-b.y)*(a.x-b.x))/l,this.k=((c.x-a.x)*(a.y-b.y)-(c.y-a.y)*(a.x-b.x))/l,this.valid()&&(this.x=a.x+this.toSource*(c.x-a.x),this.y=a.y+this.toSource* | ||
| (c.y-a.y)))}function g(a,c){1===arguments.length&&(Array.isArray(a)?(c=a[1],a=a[0]):(c=a.y,a=a.x));this.x=a;this.y=c;this.e=this.c=this.next=null;this.m=0;this.h=!0;this.f=this.a=!1}function m(a,c,b,e){a=new h(a);c=new h(c);return a.clip(c,b,e)}Array.isArray=Array.isArray||function(a){return Boolean(a&&"[object Array]"===Object.prototype.toString.call(Object(a)))};g.u=function(a,c,b){a=new g(a,c);a.m=b;a.a=!0;a.h=!1;return a};g.prototype.C=function(){this.f=!0;null===this.e||this.e.f||this.e.C()}; | ||
| g.prototype.b=function(a){return this.x===a.x&&this.y===a.y};g.prototype.B=function(a){var c=!1,b=a.first,e=b.next,l=this.x,d=this.y;do(b.y<d&&e.y>=d||e.y<d&&b.y>=d)&&(b.x<=l||e.x<=l)&&(c^=b.x+(d-b.y)/(e.y-b.y)*(e.x-b.x)<l),b=b.next,e=b.next||a.first;while(!b.b(a.first));return c};d.prototype.valid=function(){return 0<this.toSource&&1>this.toSource&&0<this.k&&1>this.k};h.prototype.i=function(a){if(null==this.first)this.first=a,this.first.next=a,this.first.c=a;else{var c=this.first,b=c.c;c.c=a;a.next= | ||
| c;a.c=b;b.next=a}this.g++};h.prototype.w=function(a,c,b){for(;!c.b(b)&&c.l<a.l;)c=c.next;a.next=c;b=c.c;a.c=b;b.next=a;c.c=a;this.g++};h.prototype.j=function(a){for(;a.a;)a=a.next;return a};h.prototype.F=function(){var a=this.D||this.first;do{if(a.a&&!a.f)break;a=a.next}while(!a.b(this.first));return this.D=a};h.prototype.G=function(){var a=this.m||this.first;do{if(a.a&&!a.f)return this.m=a,!0;a=a.next}while(!a.b(this.first));this.m=null;return!1};h.prototype.n=function(){var a=[],c=this.first;if(this.p){do a.push([c.x, | ||
| c;a.c=b;b.next=a}this.g++};h.prototype.w=function(a,c,b){for(;!c.b(b)&&c.m<a.m;)c=c.next;a.next=c;b=c.c;a.c=b;b.next=a;c.c=a;this.g++};h.prototype.j=function(a){for(;a.a;)a=a.next;return a};h.prototype.F=function(){var a=this.D||this.first;do{if(a.a&&!a.f)break;a=a.next}while(!a.b(this.first));return this.D=a};h.prototype.G=function(){var a=this.n||this.first;do{if(a.a&&!a.f)return this.n=a,!0;a=a.next}while(!a.b(this.first));this.n=null;return!1};h.prototype.o=function(){var a=[],c=this.first;if(this.p){do a.push([c.x, | ||
| c.y]),c=c.next;while(c!==this.first)}else{do a.push({x:c.x,y:c.y}),c=c.next;while(c!==this.first)}return a};h.prototype.clip=function(a,c,b){var e=this.first,l=a.first,r,n;do{if(!e.a){do l.a||(n=new d(e,this.j(e.next),l,a.j(l.next)),n.valid()&&(r=g.u(n.x,n.y,n.toSource),n=g.u(n.x,n.y,n.k),r.e=n,n.e=r,this.w(r,e,this.j(e.next)),a.w(n,l,a.j(l.next)))),l=l.next;while(!l.b(a.first))}e=e.next}while(!e.b(this.first));e=this.first;l=a.first;r=e.B(a);n=l.B(this);c^=r;b^=n;do e.a&&(e.h=c,c=!c),e=e.next;while(!e.b(this.first)); | ||
| do l.a&&(l.h=b,b=!b),l=l.next;while(!l.b(a.first));for(c=[];this.G();){b=this.F();e=new h([],this.p);e.i(new g(b.x,b.y));do{b.C();if(b.h){do b=b.next,e.i(new g(b.x,b.y));while(!b.a)}else{do b=b.c,e.i(new g(b.x,b.y));while(!b.a)}b=b.e}while(!b.f);c.push(e.n())}0===c.length&&(r&&c.push(this.n()),n&&c.push(a.n()),0===c.length&&(c=null));return c};return{union:function(a,c){return m(a,c,!1,!1)},intersection:function(a,c){return m(a,c,!0,!0)},diff:function(a,c){return m(a,c,!1,!0)},clip:m}})},{}],2:[function(q, | ||
| do l.a&&(l.h=b,b=!b),l=l.next;while(!l.b(a.first));for(c=[];this.G();){b=this.F();e=new h([],this.p);e.i(new g(b.x,b.y));do{b.C();if(b.h){do b=b.next,e.i(new g(b.x,b.y));while(!b.a)}else{do b=b.c,e.i(new g(b.x,b.y));while(!b.a)}b=b.e}while(!b.f);c.push(e.o())}0===c.length&&(r&&c.push(this.o()),n&&c.push(a.o()),0===c.length&&(c=null));return c};return{union:function(a,c){return m(a,c,!1,!1)},intersection:function(a,c){return m(a,c,!0,!0)},diff:function(a,c){return m(a,c,!1,!0)},clip:m}})},{}],2:[function(q, | ||
| k){function d(d,f){this.current=d;this.next=f;this.r=this.A();this.s=this.H()}d.prototype.H=function(){var d=this.A();return{x:-d.x,y:-d.y}};d.prototype.A=function(){var d=this.next.x-this.current.x,f=this.next.y-this.current.y,g=Math.sqrt(d*d+f*f);return{x:-f/g,y:d/g}};d.prototype.offset=function(h,f){var g=this.current,m=this.next;return new d({x:g.x+h,y:g.y+f},{x:m.x+h,y:m.y+f})};k.exports=d},{}],3:[function(q,k){k.exports=function(d,h,f,g){var m=(g.y-f.y)*(h.x-d.x)-(g.x-f.x)*(h.y-d.y);if(0==m)return null; | ||
| g=((g.x-f.x)*(d.y-f.y)-(g.y-f.y)*(d.x-f.x))/m;f=((h.x-d.x)*(d.y-f.y)-(h.y-d.y)*(d.x-f.x))/m;return 0>g||0>f||1<g||1<f?null:{x:d.x+g*(h.x-d.x),y:d.y+g*(h.y-d.y)}}},{}],4:[function(q,k){function d(a,c){this.d=this.g=null;this.q=!1;a&&this.data(a);this.o=c||5}var h=q("greiner-hormann"),f=q("./edge"),g=q("./intersection");"use strict";var m=Math.atan2;d.prototype.data=function(a){a=this.I(a);for(var c=[],b=0,e=a.length;b<e;b++)c.push(new f(a[b],a[(b+1)%e]));this.g=a;this.d=c;return this};d.prototype.I= | ||
| function(a){var c=a.length;a[0].x===a[c-1].x&&a[0].y===a[c-1].y&&(a=a.slice(0,c-1),this.q=!0);return a};d.prototype.t=function(a,c,b,e,d,g,f){var h=2*Math.PI,k=m(e.y-c.y,e.x-c.x),p=m(d.y-c.y,d.x-c.x);0===g%2&&--g;0>k&&(k+=h);0>p&&(p+=h);p=k>p?k-p:k+h-p;f=(f?-p:h-p)/g;a.push(e);for(e=1;e<g;++e)p=k+f*e,a.push({x:c.x+Math.cos(p)*b,y:c.y+Math.sin(p)*b});a.push(d)};d.prototype.padding=function(a){var c=[],b=[],e,d;e=0;for(d=this.d.length;e<d;e++){var f=this.d[e];c.push(f.offset(f.s.x*a,f.s.y*a))}e=0;for(d= | ||
| c.length;e<d;e++){var f=c[e],n=c[(e+d-1)%d],k=g(n.current,n.next,f.current,f.next);k?b.push(k):this.t(b,this.d[e].current,a,n.next,f.current,this.o,!1)}b=(a=h.union(b,b))?a[0]:b;return b=this.v(b)};d.prototype.margin=function(a){var c=[],b=[],e,d;e=0;for(d=this.d.length;e<d;e++){var f=this.d[e];c.push(f.offset(f.r.x*a,f.r.y*a))}e=0;for(d=c.length;e<d;e++){var f=c[e],k=c[(e+d-1)%d],m=g(k.current,k.next,f.current,f.next);m?b.push(m):this.t(b,this.d[e].current,a,k.next,f.current,this.o,!0)}if(a=h.union(b, | ||
| b))a=a[0],b=a.slice(0,a.length/2);return b=this.v(b)};d.prototype.v=function(a){this.q&&a.push({x:a[0].x,y:a[0].y});return a};d.prototype.offset=function(a){return 0===a?this.g:0<a?this.margin(a):this.padding(-a)};k.exports=d},{"./edge":2,"./intersection":3,"greiner-hormann":1}]},{},[4])(4)} | ||
| g=((g.x-f.x)*(d.y-f.y)-(g.y-f.y)*(d.x-f.x))/m;f=((h.x-d.x)*(d.y-f.y)-(h.y-d.y)*(d.x-f.x))/m;return 0>g||0>f||1<g||1<f?null:{x:d.x+g*(h.x-d.x),y:d.y+g*(h.y-d.y)}}},{}],4:[function(q,k){function d(a,c){this.d=this.g=null;this.q=!1;a&&this.data(a);this.l=c||5}var h=q("greiner-hormann"),f=q("./edge"),g=q("./intersection");"use strict";var m=Math.atan2;d.prototype.data=function(a){a=this.I(a);for(var c=[],b=0,e=a.length;b<e;b++)c.push(new f(a[b],a[(b+1)%e]));this.g=a;this.d=c;return this};d.prototype.arcSegments= | ||
| function(a){this.l=a;return this};d.prototype.I=function(a){var c=a.length;a[0].x===a[c-1].x&&a[0].y===a[c-1].y&&(a=a.slice(0,c-1),this.q=!0);return a};d.prototype.t=function(a,c,b,e,d,g,f){var h=2*Math.PI,k=m(e.y-c.y,e.x-c.x),p=m(d.y-c.y,d.x-c.x);0===g%2&&--g;0>k&&(k+=h);0>p&&(p+=h);p=k>p?k-p:k+h-p;f=(f?-p:h-p)/g;a.push(e);for(e=1;e<g;++e)p=k+f*e,a.push({x:c.x+Math.cos(p)*b,y:c.y+Math.sin(p)*b});a.push(d)};d.prototype.padding=function(a){var c=[],b=[],e,d;e=0;for(d=this.d.length;e<d;e++){var f=this.d[e]; | ||
| c.push(f.offset(f.s.x*a,f.s.y*a))}e=0;for(d=c.length;e<d;e++){var f=c[e],n=c[(e+d-1)%d],k=g(n.current,n.next,f.current,f.next);k?b.push(k):this.t(b,this.d[e].current,a,n.next,f.current,this.l,!1)}b=(a=h.union(b,b))?a[0]:b;return b=this.v(b)};d.prototype.margin=function(a){var c=[],b=[],e,d;e=0;for(d=this.d.length;e<d;e++){var f=this.d[e];c.push(f.offset(f.r.x*a,f.r.y*a))}e=0;for(d=c.length;e<d;e++){var f=c[e],k=c[(e+d-1)%d],m=g(k.current,k.next,f.current,f.next);m?b.push(m):this.t(b,this.d[e].current, | ||
| a,k.next,f.current,this.l,!0)}if(a=h.union(b,b))a=a[0],b=a.slice(0,a.length/2);return b=this.v(b)};d.prototype.v=function(a){this.q&&a.push({x:a[0].x,y:a[0].y});return a};d.prototype.offset=function(a){return 0===a?this.g:0<a?this.margin(a):this.padding(-a)};k.exports=d},{"./edge":2,"./intersection":3,"greiner-hormann":1}]},{},[4])(4)} | ||
| if("object"==typeof exports&&"undefined"!=typeof module)module.exports=s();else if("function"==typeof define&&define.J)define([],s);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self);t.Offset=s()}!0; |
+1
-1
| { | ||
| "name": "polygon-offset", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "description": "Polygon offsetting algorithm, aimed for use with leaflet", | ||
@@ -5,0 +5,0 @@ "main": "src/offset.js", |
+36
-0
@@ -28,2 +28,38 @@ /** | ||
| /** | ||
| * Change data set | ||
| * @param {Array.<Array>} vertices | ||
| * @return {Offset} | ||
| */ | ||
| Offset.prototype.data = function(vertices) {}; | ||
| /** | ||
| * @param {Number} arcSegments | ||
| * @return {Offset} | ||
| */ | ||
| Offset.prototype.arcSegments = function(arcSegments) {}; | ||
| /** | ||
| * Create padding polygon | ||
| * | ||
| * @param {Number} distance | ||
| * @return {Array.<Number>} | ||
| */ | ||
| Offset.prototype.padding = function(dist) {}; | ||
| /** | ||
| * Creates margin polygon | ||
| * @param {Number} dist | ||
| * @return {Array.<Object>} | ||
| */ | ||
| Offset.prototype.margin = function(dist) {}; | ||
| /** | ||
| * Decides by the sign if it's a padding or a margin | ||
| * | ||
| * @param {Number} dist | ||
| * @return {Array.<Object>} | ||
| */ | ||
| Offset.prototype.offset = function(dist) {}; | ||
| // this is for clipper | ||
@@ -30,0 +66,0 @@ |
698006
0.11%10754
0.29%