From 29b6f344037bee683154dc8abf31b1178eabc772 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 18 Mar 2013 15:44:15 -0400 Subject: [PATCH] Prevent orthogonalization of <3 node ways. Fixes #776 --- js/id/actions/orthogonalize.js | 7 ++++--- js/id/operations/orthogonalize.js | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/js/id/actions/orthogonalize.js b/js/id/actions/orthogonalize.js index 8b8244e9d..41fca79e3 100644 --- a/js/id/actions/orthogonalize.js +++ b/js/id/actions/orthogonalize.js @@ -27,7 +27,8 @@ iD.actions.Orthogonalize = function(wayId, projection) { points = best; for (i = 0; i < points.length - 1; i++) { - graph = graph.replace(graph.entity(nodes[i].id).move(projection.invert(points[i]))); + graph = graph.replace(graph.entity(nodes[i].id) + .move(projection.invert(points[i]))); } return graph; @@ -42,7 +43,7 @@ iD.actions.Orthogonalize = function(wayId, projection) { p = normalizePoint(p, 1.0); q = normalizePoint(q, 1.0); - var dotp = p[0] *q[0] + p[1] *q[1]; + var dotp = p[0] * q[0] + p[1] * q[1]; // nasty hack to deal with almost-straight segments (angle is closer to 180 than to 90/270). if (dotp < -0.707106781186547) { dotp += 1.0; @@ -87,7 +88,7 @@ iD.actions.Orthogonalize = function(wayId, projection) { function normalizePoint(point, thickness) { var vector = [0, 0]; - var length = Math.sqrt(point[0] * point[0] + point[1] * point[1]); + var length = Math.sqrt(point[0] * point[0] + point[1] * point[1]); if (length !== 0) { vector[0] = point[0] / length; vector[1] = point[1] / length; diff --git a/js/id/operations/orthogonalize.js b/js/id/operations/orthogonalize.js index 0426f936c..482c4ba5b 100644 --- a/js/id/operations/orthogonalize.js +++ b/js/id/operations/orthogonalize.js @@ -9,7 +9,8 @@ iD.operations.Orthogonalize = function(selection, context) { operation.available = function() { return selection.length === 1 && - context.entity(entityId).type === 'way'; + context.entity(entityId).type === 'way' && + _.uniq(context.entity(entityId).nodes).length > 3; }; operation.enabled = function() {