From 404488c54a1cd4d738d3fad27ff51d15cf733835 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 27 Feb 2013 21:38:40 -0500 Subject: [PATCH] Fix a couple of rotate bugs --- js/id/actions/rotate_way.js | 41 +++++++++++++------------------------ js/id/modes/rotate_way.js | 15 ++++++++++---- js/id/operations/rotate.js | 2 +- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/js/id/actions/rotate_way.js b/js/id/actions/rotate_way.js index 9de319780..46e030c50 100644 --- a/js/id/actions/rotate_way.js +++ b/js/id/actions/rotate_way.js @@ -1,39 +1,26 @@ -iD.actions.RotateWay = function(wayId, ref_points, pivot, mousePoint, projection) { +iD.actions.RotateWay = function(wayId, pivot, angle, projection) { return function(graph) { return graph.update(function(graph) { - var way = graph.entity(wayId), - nodes = _.uniq(graph.childNodes(way)), - angle, i, points; + var way = graph.entity(wayId); - points = deepCopy(ref_points); + _.unique(way.nodes).forEach(function(id) { - angle = Math.atan2(mousePoint[1] - pivot[1], mousePoint[0] - pivot[0]); + var node = graph.entity(id), + point = projection(node.loc), + radial = [0,0]; - for (i = 0; i < points.length; i++) { - var radial = [0,0]; + radial[0] = point[0] - pivot[0]; + radial[1] = point[1] - pivot[1]; - radial[0] = points[i][0] - pivot[0]; - radial[1] = points[i][1] - pivot[1]; + point = [ + radial[0] * Math.cos(angle) - radial[1] * Math.sin(angle) + pivot[0], + radial[0] * Math.sin(angle) + radial[1] * Math.cos(angle) + pivot[1] + ]; - points[i][0] = radial[0] * Math.cos(angle) - radial[1] * Math.sin(angle) + pivot[0]; - points[i][1] = radial[0] * Math.sin(angle) + radial[1] * Math.cos(angle) + pivot[1]; + graph = graph.replace(node.move(projection.invert(point))); - } + }); - for (i = 0; i < points.length; i++) { - graph = graph.replace(graph.entity(nodes[i].id).move(projection.invert(points[i]))); - } - - function deepCopy(o) { - var copy = o,k; - if (o && typeof o === 'object') { - copy = Object.prototype.toString.call(o) === '[object Array]' ? [] : {}; - for (k in o) { - copy[k] = deepCopy(o[k]); - } - } - return copy; - } }); }; }; diff --git a/js/id/modes/rotate_way.js b/js/id/modes/rotate_way.js index c7b0e4a83..b5d9fa80b 100644 --- a/js/id/modes/rotate_way.js +++ b/js/id/modes/rotate_way.js @@ -11,8 +11,9 @@ iD.modes.RotateWay = function(context, wayId) { var annotation = t('operations.rotate.annotation.' + context.geometry(wayId)), way = context.graph().entity(wayId), nodes = _.uniq(context.graph().childNodes(way)), - ref_points = nodes.map(function(n) { return context.projection(n.loc); }), - pivot = d3.geom.polygon(ref_points).centroid(); + points = nodes.map(function(n) { return context.projection(n.loc); }), + pivot = d3.geom.polygon(points).centroid(), + angle; context.perform( iD.actions.Noop(), @@ -23,11 +24,17 @@ iD.modes.RotateWay = function(context, wayId) { } function rotate() { - var mousePoint = point(); + + var mousePoint = point(), + newAngle = Math.atan2(mousePoint[1] - pivot[1], mousePoint[0] - pivot[0]); + + if (typeof angle === 'undefined') angle = newAngle; context.replace( - iD.actions.RotateWay(wayId, ref_points, pivot, mousePoint, context.projection), + iD.actions.RotateWay(wayId, pivot, newAngle - angle, context.projection), annotation); + + angle = newAngle; } function finish() { diff --git a/js/id/operations/rotate.js b/js/id/operations/rotate.js index 75a18770a..1c9804aaa 100644 --- a/js/id/operations/rotate.js +++ b/js/id/operations/rotate.js @@ -8,7 +8,7 @@ iD.operations.Rotate = function(selection, context) { operation.available = function() { return selection.length === 1 && context.entity(entityId).type === 'way' && - context.entity(entityId).isClosed(); + context.entity(entityId).geometry() === 'area'; }; operation.enabled = function() {