mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Update to only flip around the vertical axis. Start renaming to 'reflect'
This commit is contained in:
+5
-8
@@ -106,14 +106,6 @@ en:
|
||||
not_connected: There aren't enough lines/areas here to disconnect.
|
||||
connected_to_hidden: This can't be disconnected because it is connected to a hidden feature.
|
||||
relation: This can't be disconnected because it connects members of a relation.
|
||||
flipHorizontal:
|
||||
title: Flip Horizontal
|
||||
description: Flip this area horizontally.
|
||||
annotation: Flipped an area horizontally.
|
||||
flipVertical:
|
||||
title: Flip Vertical
|
||||
description: Flip this area vertically.
|
||||
annotation: Flipped an area vertically.
|
||||
merge:
|
||||
title: Merge
|
||||
description: Merge these features.
|
||||
@@ -137,6 +129,11 @@ en:
|
||||
incomplete_relation: This feature can't be moved because it hasn't been fully downloaded.
|
||||
too_large: This can't be moved because not enough of it is currently visible.
|
||||
connected_to_hidden: This can't be moved because it is connected to a hidden feature.
|
||||
reflect:
|
||||
title: reflect
|
||||
description: Reflect this area on the vertical axis.
|
||||
key: T
|
||||
annotation: Reflected an area.
|
||||
rotate:
|
||||
title: Rotate
|
||||
description: Rotate this object around its center point.
|
||||
|
||||
Vendored
-10
@@ -137,16 +137,6 @@
|
||||
"connected_to_hidden": "This can't be disconnected because it is connected to a hidden feature.",
|
||||
"relation": "This can't be disconnected because it connects members of a relation."
|
||||
},
|
||||
"flipHorizontal": {
|
||||
"title": "Flip Horizontal",
|
||||
"description": "Flip this area horizontally.",
|
||||
"annotation": "Flipped an area horizontally."
|
||||
},
|
||||
"flipVertical": {
|
||||
"title": "Flip Vertical",
|
||||
"description": "Flip this area vertically.",
|
||||
"annotation": "Flipped an area vertically."
|
||||
},
|
||||
"merge": {
|
||||
"title": "Merge",
|
||||
"description": "Merge these features.",
|
||||
|
||||
+8
-12
@@ -1,9 +1,9 @@
|
||||
import _ from 'lodash';
|
||||
/* Flip the provided way horizontally or vertically
|
||||
/* Flip the provided way horizontally
|
||||
Only operates on "area" ways
|
||||
*/
|
||||
|
||||
export function actionFlip(wayId, isVertical) {
|
||||
export function actionFlip(wayId) {
|
||||
|
||||
return function (graph) {
|
||||
const targetWay = graph.entity(wayId);
|
||||
@@ -16,11 +16,11 @@ export function actionFlip(wayId, isVertical) {
|
||||
// Get the bounding rectangle of the area
|
||||
const boundingRect = targetWay.extent(graph).rectangle();
|
||||
// rectangle returned as [ lon (x) top left, lat (y) top left, lon (x) bottom right, lat (y) bottom right]
|
||||
// Obtain the left/top lonlat and the right/bottom
|
||||
const leftOrTop = isVertical ? boundingRect[1] : boundingRect[0];
|
||||
const rightOrBottom = isVertical ? boundingRect[3] : boundingRect[2];
|
||||
// Obtain the left and right lonlat's
|
||||
const left = boundingRect[0];
|
||||
const right = boundingRect[2];
|
||||
// Determine the mid-point that we will flip on
|
||||
const midPoint = leftOrTop + ((rightOrBottom - leftOrTop) / 2);
|
||||
const midPoint = left + ((right - left) / 2);
|
||||
|
||||
// Obtain all of the nodes on the way, iterate over them to translate then aggreate up
|
||||
return _(targetWay.nodes)
|
||||
@@ -31,12 +31,8 @@ export function actionFlip(wayId, isVertical) {
|
||||
.uniqBy(function (node) { return node.id; })
|
||||
// Get distance from midPoint and produce a translated node
|
||||
.map(function (node) {
|
||||
const delta = isVertical ?
|
||||
node.loc[1] - midPoint :
|
||||
node.loc[0] - midPoint;
|
||||
return isVertical ?
|
||||
node.move([node.loc[0], node.loc[1]-(2*delta)]) :
|
||||
node.move([node.loc[0]-(2*delta), node.loc[1]]);
|
||||
const delta = node.loc[0] - midPoint;
|
||||
return node.move([node.loc[0]-(2*delta), node.loc[1]]);
|
||||
})
|
||||
// Chain together consecutive updates to the graph for each updated node and return
|
||||
.reduce(function (accGraph, value) {
|
||||
|
||||
@@ -31,4 +31,4 @@ export { actionRotateWay } from './rotate_way';
|
||||
export { actionSplit } from './split';
|
||||
export { actionStraighten } from './straighten';
|
||||
export { actionUnrestrictTurn } from './unrestrict_turn';
|
||||
export { actionFlip } from './flip';
|
||||
export { actionReflect } from './flip';
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import { t } from '../util/locale';
|
||||
import { actionFlip } from '../actions/index';
|
||||
import { uiCmd } from '../ui/index';
|
||||
|
||||
export function operationFlipVertical(selectedIDs, context) {
|
||||
var entityId = selectedIDs[0];
|
||||
|
||||
var operation = function() {
|
||||
context.perform(
|
||||
actionFlip(entityId, true),
|
||||
t('operations.flipVertical.annotation')
|
||||
);
|
||||
};
|
||||
|
||||
operation.available = function() {
|
||||
return selectedIDs.length === 1 &&
|
||||
context.geometry(entityId) === 'area';
|
||||
};
|
||||
|
||||
operation.disabled = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
operation.tooltip = function() {
|
||||
return t('operations.flipVertical.description');
|
||||
};
|
||||
|
||||
operation.id = 'flipVertical';
|
||||
operation.keys = [uiCmd('⌥V')]; // Alt-V
|
||||
operation.title = t('operations.flipVertical.title');
|
||||
|
||||
return operation;
|
||||
}
|
||||
@@ -9,5 +9,3 @@ export { operationReverse } from './reverse';
|
||||
export { operationRotate } from './rotate';
|
||||
export { operationSplit } from './split';
|
||||
export { operationStraighten } from './straighten';
|
||||
export { operationFlipHorizontal } from './flipHorizontal';
|
||||
export { operationFlipVertical } from './flipVertical';
|
||||
@@ -1,14 +1,13 @@
|
||||
import { t } from '../util/locale';
|
||||
import { actionFlip } from '../actions/index';
|
||||
import { uiCmd } from '../ui/index';
|
||||
import { actionReflect } from '../actions/index';
|
||||
|
||||
export function operationFlipHorizontal(selectedIDs, context) {
|
||||
export function operationReflect(selectedIDs, context) {
|
||||
var entityId = selectedIDs[0];
|
||||
|
||||
var operation = function() {
|
||||
context.perform(
|
||||
actionFlip(entityId, false),
|
||||
t('operations.flipHorizontal.annotation')
|
||||
actionReflect(entityId, false),
|
||||
t('operations.reflect.annotation')
|
||||
);
|
||||
};
|
||||
|
||||
@@ -22,12 +21,12 @@ export function operationFlipHorizontal(selectedIDs, context) {
|
||||
};
|
||||
|
||||
operation.tooltip = function() {
|
||||
return t('operations.flipHorizontal.description');
|
||||
return t('operations.reflect.description');
|
||||
};
|
||||
|
||||
operation.id = 'flipHorizontal';
|
||||
operation.keys = [uiCmd('⌥H')]; // Alt-H
|
||||
operation.title = t('operations.flipHorizontal.title');
|
||||
operation.keys = [t('operations.reflect.key')];
|
||||
operation.title = t('operations.reflect.title');
|
||||
|
||||
return operation;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ describe('iD.actionFlip', function() {
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
|
||||
]);
|
||||
|
||||
graph = iD.actionFlip('-', false)(graph);
|
||||
graph = iD.actionFlip('-')(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.have.length(5);
|
||||
});
|
||||
@@ -22,7 +22,7 @@ describe('iD.actionFlip', function() {
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
|
||||
]);
|
||||
graph = iD.actionFlip('-', false)(graph);
|
||||
graph = iD.actionFlip('-')(graph);
|
||||
expect(graph.entity('a').loc[0]).to.equal(2); // A should be 2,0 now
|
||||
expect(graph.entity('b').loc[0]).to.equal(0); // B should be 0,0 now
|
||||
expect(graph.entity('c').loc[0]).to.equal(0); // C should be 0,2 now
|
||||
@@ -37,43 +37,13 @@ describe('iD.actionFlip', function() {
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
|
||||
]);
|
||||
graph = iD.actionFlip('-', false)(graph);
|
||||
graph = iD.actionFlip('-')(graph);
|
||||
expect(graph.entity('a').loc[1]).to.equal(0); // A should be 2,0 now
|
||||
expect(graph.entity('b').loc[1]).to.equal(0); // B should be 0,0 now
|
||||
expect(graph.entity('c').loc[1]).to.equal(2); // C should be 0,2 now
|
||||
expect(graph.entity('d').loc[1]).to.equal(2); // D should be 2,2 now
|
||||
});
|
||||
|
||||
it('flips vertically - alters y value', function () {
|
||||
var graph = iD.Graph([
|
||||
iD.Node({id: 'a', loc: [0, 0]}),
|
||||
iD.Node({id: 'b', loc: [2, 0]}),
|
||||
iD.Node({id: 'c', loc: [2, 2]}),
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
|
||||
]);
|
||||
graph = iD.actionFlip('-', true)(graph);
|
||||
expect(graph.entity('a').loc[1]).to.equal(2); // A should be 0,2 now
|
||||
expect(graph.entity('b').loc[1]).to.equal(2); // B should be 2,2 now
|
||||
expect(graph.entity('c').loc[1]).to.equal(0); // C should be 2,0 now
|
||||
expect(graph.entity('d').loc[1]).to.equal(0); // D should be 0,0 now
|
||||
});
|
||||
|
||||
it('flips vertically - does not alter x value', function () {
|
||||
var graph = iD.Graph([
|
||||
iD.Node({id: 'a', loc: [0, 0]}),
|
||||
iD.Node({id: 'b', loc: [2, 0]}),
|
||||
iD.Node({id: 'c', loc: [2, 2]}),
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}})
|
||||
]);
|
||||
graph = iD.actionFlip('-', true)(graph);
|
||||
expect(graph.entity('a').loc[0]).to.equal(0); // A should be 0,2 now
|
||||
expect(graph.entity('b').loc[0]).to.equal(2); // B should be 2,2 now
|
||||
expect(graph.entity('c').loc[0]).to.equal(2); // C should be 2,0 now
|
||||
expect(graph.entity('d').loc[0]).to.equal(0); // D should be 0,0 now
|
||||
});
|
||||
|
||||
it('does not flip horizontally if not an area - does not alter x value', function () {
|
||||
var graph = iD.Graph([
|
||||
iD.Node({id: 'a', loc: [0, 0]}),
|
||||
@@ -82,7 +52,7 @@ describe('iD.actionFlip', function() {
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
|
||||
]);
|
||||
graph = iD.actionFlip('-', false)(graph);
|
||||
graph = iD.actionFlip('-')(graph);
|
||||
// should be no change
|
||||
expect(graph.entity('a').loc[0]).to.equal(0);
|
||||
expect(graph.entity('b').loc[0]).to.equal(2);
|
||||
@@ -98,39 +68,7 @@ describe('iD.actionFlip', function() {
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
|
||||
]);
|
||||
graph = iD.actionFlip('-', false)(graph);
|
||||
// should be no change
|
||||
expect(graph.entity('a').loc[1]).to.equal(0);
|
||||
expect(graph.entity('b').loc[1]).to.equal(0);
|
||||
expect(graph.entity('c').loc[1]).to.equal(2);
|
||||
expect(graph.entity('d').loc[1]).to.equal(2);
|
||||
});
|
||||
|
||||
it('does not flip vertically if not an area - does not alter x value', function () {
|
||||
var graph = iD.Graph([
|
||||
iD.Node({id: 'a', loc: [0, 0]}),
|
||||
iD.Node({id: 'b', loc: [2, 0]}),
|
||||
iD.Node({id: 'c', loc: [2, 2]}),
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
|
||||
]);
|
||||
graph = iD.actionFlip('-', true)(graph);
|
||||
// should be no change
|
||||
expect(graph.entity('a').loc[0]).to.equal(0);
|
||||
expect(graph.entity('b').loc[0]).to.equal(2);
|
||||
expect(graph.entity('c').loc[0]).to.equal(2);
|
||||
expect(graph.entity('d').loc[0]).to.equal(0);
|
||||
});
|
||||
|
||||
it('does not flip vertically if not an area - does not alter y value', function () {
|
||||
var graph = iD.Graph([
|
||||
iD.Node({id: 'a', loc: [0, 0]}),
|
||||
iD.Node({id: 'b', loc: [2, 0]}),
|
||||
iD.Node({id: 'c', loc: [2, 2]}),
|
||||
iD.Node({id: 'd', loc: [0, 2]}),
|
||||
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
|
||||
]);
|
||||
graph = iD.actionFlip('-', true)(graph);
|
||||
graph = iD.actionFlip('-')(graph);
|
||||
// should be no change
|
||||
expect(graph.entity('a').loc[1]).to.equal(0);
|
||||
expect(graph.entity('b').loc[1]).to.equal(0);
|
||||
|
||||
Reference in New Issue
Block a user