From 33782a39585af96863ac33abef5f5ec281572728 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 21 Apr 2014 23:29:25 -0400 Subject: [PATCH] Require 2 uniq points for circularize. Handle 2 point case, where D3 centroid() fails. --- js/id/actions/circularize.js | 2 +- js/id/operations/circularize.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/js/id/actions/circularize.js b/js/id/actions/circularize.js index e8ef8b9f9..6e9f44b0a 100644 --- a/js/id/actions/circularize.js +++ b/js/id/actions/circularize.js @@ -12,7 +12,7 @@ iD.actions.Circularize = function(wayId, projection, maxAngle) { keyNodes = nodes.filter(function(n) { return graph.parentWays(n).length !== 1; }), points = nodes.map(function(n) { return projection(n.loc); }), keyPoints = keyNodes.map(function(n) { return projection(n.loc); }), - centroid = d3.geom.polygon(points).centroid(), + centroid = (points.length === 2) ? iD.geo.interp(points[0], points[1], 0.5) : d3.geom.polygon(points).centroid(), radius = d3.median(points, function(p) { return iD.geo.euclideanDistance(centroid, p); }), sign = d3.geom.polygon(points).area() > 0 ? 1 : -1, ids; diff --git a/js/id/operations/circularize.js b/js/id/operations/circularize.js index 2e59b90e7..39926aff1 100644 --- a/js/id/operations/circularize.js +++ b/js/id/operations/circularize.js @@ -9,8 +9,10 @@ iD.operations.Circularize = function(selectedIDs, context) { }; operation.available = function() { + var entity = context.entity(entityId); return selectedIDs.length === 1 && - context.entity(entityId).type === 'way'; + entity.type === 'way' && + _.uniq(entity.nodes).length > 1; }; operation.disabled = function() {