diff --git a/js/id/geo.js b/js/id/geo.js index e44b182a6..08df659b0 100644 --- a/js/id/geo.js +++ b/js/id/geo.js @@ -74,30 +74,6 @@ iD.geo.polygonIntersectsPolygon = function(outer, inner) { }); }; -// May have issues with self interesecting polygons -iD.geo.polygonCentroid = function(polygon) { - var x = 0, - y = 0, - area = iD.geo.area(polygon); - for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) { - var xi = polygon[i][0], yi = polygon[i][1]; - var xj = polygon[j][0], yj = polygon[j][1]; - x += (xi + xj) * (xj * yi - xi * yj); - y += (yi + yj) * (xj * yi - xi * yj); - } - return [x / 6 / area, y / 6 / area]; -}; - -iD.geo.area = function(polygon) { - var area = 0; - for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) { - var xi = polygon[i][0], yi = polygon[i][1]; - var xj = polygon[j][0], yj = polygon[j][1]; - area += xj * yi - xi * yj; - } - return area/2; -}; - iD.geo.pathLength = function(path) { var length = 0, dx, dy; diff --git a/js/id/svg/labels.js b/js/id/svg/labels.js index d50ecfc97..0db2c59e2 100644 --- a/js/id/svg/labels.js +++ b/js/id/svg/labels.js @@ -284,7 +284,7 @@ iD.svg.Labels = function(projection) { function getAreaLabel(entity, width, height) { var nodes = _.pluck(entity.nodes, 'loc') .map(iD.svg.RoundProjection(projection)), - centroid = iD.geo.polygonCentroid(nodes), + centroid = d3.geom.polygon(nodes).centroid(), extent = entity.extent(graph), entitywidth = projection(extent[1])[0] - projection(extent[0])[0]; diff --git a/test/spec/util.js b/test/spec/util.js index 24f7e6ca7..9d5cf082b 100644 --- a/test/spec/util.js +++ b/test/spec/util.js @@ -113,20 +113,6 @@ describe('iD.Util', function() { }); }); - describe("#area", function() { - it('calculates the area of a trapezoid', function() { - var polygon = [[0, 0], [3, 0], [2, 2], [1, 2]]; - expect(iD.geo.area(polygon)).to.eql(4); - }); - }); - - describe('#polygonCentroid', function() { - it('calculates the centroid of a square', function() { - var square = [[0, 0], [0, 2], [2, 2], [2, 0]]; - expect(iD.geo.polygonCentroid(square)).to.eql([1, 1]); - }); - }); - describe('#pathLength', function() { it('calculates a simple path length', function() { var path = [[0, 0], [0, 1], [3, 5]];