From 23990214be19cc0f363ce15468ca97edb4c11b78 Mon Sep 17 00:00:00 2001 From: Jon D Date: Sun, 6 Nov 2016 10:48:48 +0000 Subject: [PATCH] Update to only flip around the vertical axis. Start renaming to 'reflect' --- data/core.yaml | 13 ++-- dist/locales/en.json | 10 --- modules/actions/flip.js | 20 +++--- modules/actions/index.js | 2 +- modules/operations/flipVertical.js | 33 --------- modules/operations/index.js | 2 - .../{flipHorizontal.js => reflect.js} | 15 ++-- test/spec/actions/flip.js | 72 ++----------------- 8 files changed, 26 insertions(+), 141 deletions(-) delete mode 100644 modules/operations/flipVertical.js rename modules/operations/{flipHorizontal.js => reflect.js} (53%) diff --git a/data/core.yaml b/data/core.yaml index 549015ff9..407cf7317 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -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. diff --git a/dist/locales/en.json b/dist/locales/en.json index 8fdca99ec..bdd861383 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -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.", diff --git a/modules/actions/flip.js b/modules/actions/flip.js index d2043b101..8464b3265 100644 --- a/modules/actions/flip.js +++ b/modules/actions/flip.js @@ -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) { diff --git a/modules/actions/index.js b/modules/actions/index.js index 16404b358..0ad5fad9a 100644 --- a/modules/actions/index.js +++ b/modules/actions/index.js @@ -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'; diff --git a/modules/operations/flipVertical.js b/modules/operations/flipVertical.js deleted file mode 100644 index aba57d24b..000000000 --- a/modules/operations/flipVertical.js +++ /dev/null @@ -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; -} diff --git a/modules/operations/index.js b/modules/operations/index.js index 6f1f17aac..bd4058f5d 100644 --- a/modules/operations/index.js +++ b/modules/operations/index.js @@ -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'; \ No newline at end of file diff --git a/modules/operations/flipHorizontal.js b/modules/operations/reflect.js similarity index 53% rename from modules/operations/flipHorizontal.js rename to modules/operations/reflect.js index 29bba16cd..ee9d0840c 100644 --- a/modules/operations/flipHorizontal.js +++ b/modules/operations/reflect.js @@ -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; } diff --git a/test/spec/actions/flip.js b/test/spec/actions/flip.js index 3b9add5c2..b683e466e 100644 --- a/test/spec/actions/flip.js +++ b/test/spec/actions/flip.js @@ -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);