From a3a15a470ed6118a42d75ab71b4ee99c66eaeb3a Mon Sep 17 00:00:00 2001 From: w8r Date: Wed, 12 Nov 2014 14:04:34 +0100 Subject: [PATCH] input/output formats --- dist/greiner-hormann.es5.js | 35 ++++++++++++++++------------- dist/greiner-hormann.es5.min.js | 12 +++++----- dist/greiner-hormann.js | 35 ++++++++++++++++------------- dist/greiner-hormann.leaflet.js | 35 ++++++++++++++++------------- dist/greiner-hormann.leaflet.min.js | 14 ++++++------ dist/greiner-hormann.min.js | 13 ++++++----- src/driver.js | 4 ++-- src/driver.leaflet.js | 4 ++-- src/end.js | 22 +++++++++--------- src/polygon.js | 9 +++++--- test/suite.js | 4 ++-- 11 files changed, 104 insertions(+), 83 deletions(-) diff --git a/dist/greiner-hormann.es5.js b/dist/greiner-hormann.es5.js index 7d11b58..48d60b7 100644 --- a/dist/greiner-hormann.es5.js +++ b/dist/greiner-hormann.es5.js @@ -473,15 +473,18 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) { current = current._corresponding; } while (!current._visited); - list.push(clipped); + list.push(clipped.getPoints()); } if (list.length === 0) { if (sourceInClip) { - list.push(this); + list.push(this.getPoints()); } if (clipInSource) { - list.push(clip); + list.push(clip.getPoints()); + } + if (list.length === 0) { + list = null; } } @@ -494,8 +497,8 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) { * @api * @param {Array.>} polygonA * @param {Array.>} polygonB - * @param {Boolean} sourceForwards - * @param {Boolean} clipForwards + * @param {Boolean} sourceForwards + * @param {Boolean} clipForwards * @return {Array.>} */ function clip(polygonA, polygonB, eA, eB) { @@ -508,9 +511,9 @@ function clip(polygonA, polygonB, eA, eB) { return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.|Null} */ union: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, false); @@ -518,9 +521,9 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ intersection: function(polygonA, polygonB) { return clip(polygonA, polygonB, true, true); @@ -528,13 +531,15 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ diff: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, true); - } + }, + + clip: clip }; })); diff --git a/dist/greiner-hormann.es5.min.js b/dist/greiner-hormann.es5.min.js index 8de227e..6622b16 100644 --- a/dist/greiner-hormann.es5.min.js +++ b/dist/greiner-hormann.es5.min.js @@ -1,9 +1,9 @@ /* Licensed under MIT License */ -function l(){function k(a,c){this.k=this.first=null;this.p="undefined"===typeof c?Array.isArray(a[0]):c;for(var b=0,d=a.length;b=g||d.y=g)&&(b.x<=e||d.x<=e)&&(c^= -b.x+(g-b.y)/(d.y-b.y)*(d.x-b.x)this.toSource&&0this.i};k.prototype.g=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}};k.prototype.m=function(a,c,b){for(;!c.b(b)&&c.j=g||d.y=g)&&(c.x<=e||d.x<=e)&&(b^= +c.x+(g-c.y)/(d.y-c.y)*(d.x-c.x)this.toSource&&0this.i};k.prototype.g=function(a){if(null==this.first)this.first=a,this.first.next=a,this.first.c=a;else{var b=this.first,c=b.c;b.c=a;a.next=b;a.c=c;c.next=a}};k.prototype.o=function(a,b,c){for(;!b.b(c)&&b.j>} polygonA * @param {Array.>} polygonB - * @param {Boolean} sourceForwards - * @param {Boolean} clipForwards + * @param {Boolean} sourceForwards + * @param {Boolean} clipForwards * @return {Array.>} */ function clip(polygonA, polygonB, eA, eB) { @@ -513,9 +516,9 @@ function clip(polygonA, polygonB, eA, eB) { return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.|Null} */ union: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, false); @@ -523,9 +526,9 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ intersection: function(polygonA, polygonB) { return clip(polygonA, polygonB, true, true); @@ -533,13 +536,15 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ diff: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, true); - } + }, + + clip: clip }; })); diff --git a/dist/greiner-hormann.leaflet.js b/dist/greiner-hormann.leaflet.js index 4dca465..0fedd11 100644 --- a/dist/greiner-hormann.leaflet.js +++ b/dist/greiner-hormann.leaflet.js @@ -478,15 +478,18 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) { current = current._corresponding; } while (!current._visited); - list.push(clipped); + list.push(clipped.getPoints()); } if (list.length === 0) { if (sourceInClip) { - list.push(this); + list.push(this.getPoints()); } if (clipInSource) { - list.push(clip); + list.push(clip.getPoints()); + } + if (list.length === 0) { + list = null; } } @@ -518,7 +521,7 @@ function clip(polygonA, polygonB, sourceForwards, clipForwards) { } source = new Polygon(source), - clip = new Polygon(clip); + clip = new Polygon(clip); result = source.clip(clip, sourceForwards, clipForwards); if (result.length > 0) { @@ -541,7 +544,7 @@ function clip(polygonA, polygonB, sourceForwards, clipForwards) { } function toLatLngs(poly) { - var result = poly.getPoints(); + var result = poly; if (result) { if (result[0][0] === result[result.length - 1][0] && @@ -560,9 +563,9 @@ function toLatLngs(poly) { return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.|Null} */ union: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, false); @@ -570,9 +573,9 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ intersection: function(polygonA, polygonB) { return clip(polygonA, polygonB, true, true); @@ -580,13 +583,15 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ diff: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, true); - } + }, + + clip: clip }; })); diff --git a/dist/greiner-hormann.leaflet.min.js b/dist/greiner-hormann.leaflet.min.js index 57be634..b191dbc 100644 --- a/dist/greiner-hormann.leaflet.min.js +++ b/dist/greiner-hormann.leaflet.min.js @@ -1,10 +1,10 @@ /* Licensed under MIT License */ -function l(){function k(a,b){this.k=this.first=null;this.l="undefined"===typeof b?Array.isArray(a[0]):b;for(var c=0,e=a.length;c=f||e.y= -f)&&(c.x<=d||e.x<=d)&&(b^=c.x+(f-c.y)/(e.y-c.y)*(e.x-c.x)this.toSource&&0this.i};k.prototype.g=function(a){if(null==this.first)this.first=a,this.first.next=a,this.first.c=a;else{var b=this.first,c=b.c;b.c=a;a.next=b;a.c=c;c.next=a}};k.prototype.n=function(a,b,c){for(;!b.b(c)&&b.j=f||e.y= +f)&&(c.x<=d||e.x<=d)&&(b^=c.x+(f-c.y)/(e.y-c.y)*(e.x-c.x)this.toSource&&0this.i};k.prototype.g=function(a){if(null==this.first)this.first=a,this.first.next=a,this.first.c=a;else{var b=this.first,c=b.c;b.c=a;a.next=b;a.c=c;c.next=a}};k.prototype.o=function(a,b,c){for(;!b.b(c)&&b.j=g||d.y=g)&&(b.x<=e||d.x<=e)&&(c^=b.x+(g-b.y)/(d.y-b.y)*(d.x-b.x)this.toSource&&0this.i};k.prototype.g=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}};k.prototype.m=function(a,c,b){for(;!c.b(b)&&c.j=g||d.y=g)&&(c.x<=e||d.x<=e)&&(b^=c.x+(g-c.y)/(d.y-c.y)*(d.x-c.x)this.toSource&&0this.i};k.prototype.g=function(a){if(null==this.first)this.first=a,this.first.next=a,this.first.c=a;else{var b=this.first,c=b.c;b.c=a;a.next=b;a.c=c;c.next=a}};k.prototype.o=function(a,b,c){for(;!b.b(c)&&b.j>} polygonA * @param {Array.>} polygonB - * @param {Boolean} sourceForwards - * @param {Boolean} clipForwards + * @param {Boolean} sourceForwards + * @param {Boolean} clipForwards * @return {Array.>} */ function clip(polygonA, polygonB, eA, eB) { diff --git a/src/driver.leaflet.js b/src/driver.leaflet.js index c73ea35..0827efd 100644 --- a/src/driver.leaflet.js +++ b/src/driver.leaflet.js @@ -24,7 +24,7 @@ function clip(polygonA, polygonB, sourceForwards, clipForwards) { } source = new Polygon(source), - clip = new Polygon(clip); + clip = new Polygon(clip); result = source.clip(clip, sourceForwards, clipForwards); if (result.length > 0) { @@ -47,7 +47,7 @@ function clip(polygonA, polygonB, sourceForwards, clipForwards) { } function toLatLngs(poly) { - var result = poly.getPoints(); + var result = poly; if (result) { if (result[0][0] === result[result.length - 1][0] && diff --git a/src/end.js b/src/end.js index 45a0f7b..ef3ba98 100644 --- a/src/end.js +++ b/src/end.js @@ -1,9 +1,9 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.|Null} */ union: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, false); @@ -11,9 +11,9 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ intersection: function(polygonA, polygonB) { return clip(polygonA, polygonB, true, true); @@ -21,13 +21,15 @@ return { /** * @api - * @param {Array.} polygonA - * @param {Array.} polygonB - * @return {Array.>|Null} + * @param {Array.|Array.} polygonA + * @param {Array.|Array.} polygonB + * @return {Array.>|Array.>|Null} */ diff: function(polygonA, polygonB) { return clip(polygonA, polygonB, false, true); - } + }, + + clip: clip }; })); diff --git a/src/polygon.js b/src/polygon.js index 689f3ba..31a1e31 100644 --- a/src/polygon.js +++ b/src/polygon.js @@ -264,15 +264,18 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) { current = current._corresponding; } while (!current._visited); - list.push(clipped); + list.push(clipped.getPoints()); } if (list.length === 0) { if (sourceInClip) { - list.push(this); + list.push(this.getPoints()); } if (clipInSource) { - list.push(clip); + list.push(clip.getPoints()); + } + if (list.length === 0) { + list = null; } } diff --git a/test/suite.js b/test/suite.js index f220a11..49d1a39 100644 --- a/test/suite.js +++ b/test/suite.js @@ -31,7 +31,7 @@ console.log( }, { x: 10, y: 40 - }])[0].getPoints() + }]) ); console.log( @@ -47,5 +47,5 @@ console.log( [110, 140], [10, 140], [10, 40] - ])[0].getPoints() + ]) );