Skip to content

Commit

Permalink
input/output formats
Browse files Browse the repository at this point in the history
  • Loading branch information
w8r committed Nov 12, 2014
1 parent 8852820 commit a3a15a4
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 83 deletions.
35 changes: 20 additions & 15 deletions dist/greiner-hormann.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -494,8 +497,8 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
* @api
* @param {Array.<Array.<Number>>} polygonA
* @param {Array.<Array.<Number>>} polygonB
* @param {Boolean} sourceForwards
* @param {Boolean} clipForwards
* @param {Boolean} sourceForwards
* @param {Boolean} clipForwards
* @return {Array.<Array.<Number>>}
*/
function clip(polygonA, polygonB, eA, eB) {
Expand All @@ -508,33 +511,35 @@ function clip(polygonA, polygonB, eA, eB) {
return {
/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>|Null}
*/
union: function(polygonA, polygonB) {
return clip(polygonA, polygonB, false, false);
},

/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>>|Null}
*/
intersection: function(polygonA, polygonB) {
return clip(polygonA, polygonB, true, true);
},

/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>>|Null}
*/
diff: function(polygonA, polygonB) {
return clip(polygonA, polygonB, false, true);
}
},

clip: clip
};

}));
12 changes: 6 additions & 6 deletions dist/greiner-hormann.es5.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 20 additions & 15 deletions dist/greiner-hormann.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -499,8 +502,8 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
* @api
* @param {Array.<Array.<Number>>} polygonA
* @param {Array.<Array.<Number>>} polygonB
* @param {Boolean} sourceForwards
* @param {Boolean} clipForwards
* @param {Boolean} sourceForwards
* @param {Boolean} clipForwards
* @return {Array.<Array.<Number>>}
*/
function clip(polygonA, polygonB, eA, eB) {
Expand All @@ -513,33 +516,35 @@ function clip(polygonA, polygonB, eA, eB) {
return {
/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>|Null}
*/
union: function(polygonA, polygonB) {
return clip(polygonA, polygonB, false, false);
},

/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>>|Null}
*/
intersection: function(polygonA, polygonB) {
return clip(polygonA, polygonB, true, true);
},

/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>>|Null}
*/
diff: function(polygonA, polygonB) {
return clip(polygonA, polygonB, false, true);
}
},

clip: clip
};

}));
35 changes: 20 additions & 15 deletions dist/greiner-hormann.leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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] &&
Expand All @@ -560,33 +563,35 @@ function toLatLngs(poly) {
return {
/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>|Null}
*/
union: function(polygonA, polygonB) {
return clip(polygonA, polygonB, false, false);
},

/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>>|Null}
*/
intersection: function(polygonA, polygonB) {
return clip(polygonA, polygonB, true, true);
},

/**
* @api
* @param {Array.<Array.<Number>} polygonA
* @param {Array.<Array.<Number>} polygonB
* @return {Array.<Array.<Number>>|Null}
* @param {Array.<Array.<Number>|Array.<Object>} polygonA
* @param {Array.<Array.<Number>|Array.<Object>} polygonB
* @return {Array.<Array.<Number>>|Array.<Array.<Object>>|Null}
*/
diff: function(polygonA, polygonB) {
return clip(polygonA, polygonB, false, true);
}
},

clip: clip
};

}));
Loading

2 comments on commit a3a15a4

@sonnygauran
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Just wanted you to know that I would love to have this project of yours on bower too. ❤️

@w8r
Copy link
Owner Author

@w8r w8r commented on a3a15a4 Oct 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @sonnygauran

$ bower info greiner-hormann
bower greiner-hormann#*     not-cached git://github.com/w8r/GreinerHormann.git#*
bower greiner-hormann#*        resolve git://github.com/w8r/GreinerHormann.git#*
bower greiner-hormann#*       download https://github.com/w8r/GreinerHormann/archive/1.3.0.tar.gz
bower greiner-hormann#*        extract archive.tar.gz
bower greiner-hormann#*       resolved git://github.com/w8r/GreinerHormann.git#1.3.0

{
  name: 'GreinerHormann',
  version: '1.3.0',
  homepage: 'https://github.com/w8r/GreinerHormann',
  authors: [
    'Alexander Milevski <info@w8r.name>'
  ],
  description: 'Greiner-Hormann clipping algorithm',
  main: 'dist/greiner-hormann.leaflet.min.js',
  moduleType: [
    'globals',
    'node'
  ],
  keywords: [
    'polygon',
    'clipping',
    'geometry',
    'greiner',
    'hormann',
    'intersection',
    'union',
    'difference',
    'xor'
  ],
  license: 'MIT',
  ignore: [
    '**/.*',
    'node_modules',
    'bower_components',
    'test',
    'tests'
  ]
}

Available versions:
  - 1.3.0

Please sign in to comment.