Fix a couple of rotate bugs

This commit is contained in:
Ansis Brammanis
2013-02-27 21:38:40 -05:00
parent aeb5ab5b21
commit 404488c54a
3 changed files with 26 additions and 32 deletions
+14 -27
View File
@@ -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;
}
});
};
};
+11 -4
View File
@@ -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() {
+1 -1
View File
@@ -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() {