diff --git a/modules/modes/rotate.js b/modules/modes/rotate.js index e1b3d6a4f..d6dd377f4 100644 --- a/modules/modes/rotate.js +++ b/modules/modes/rotate.js @@ -1,10 +1,9 @@ import * as d3 from 'd3'; import { d3keybinding } from '../lib/d3.keybinding.js'; import { t } from '../util/locale'; - -import { actionRotate } from '../actions/index'; -import { behaviorEdit } from '../behavior/index'; - +import { actionRotate } from '../actions'; +import { behaviorEdit } from '../behavior'; +import { geoInterp } from '../geo'; import { modeBrowse, modeSelect @@ -17,7 +16,7 @@ import { operationOrthogonalize, operationReflectLong, operationReflectShort -} from '../operations/index'; +} from '../operations'; import { polygonHull as d3polygonHull, @@ -71,7 +70,13 @@ export function modeRotate(context, entityIDs) { var nodes = utilGetAllNodes(entityIDs, context.graph()), points = nodes.map(function(n) { return projection(n.loc); }); - pivot = d3polygonCentroid(d3polygonHull(points)); + if (points.length === 1) { // degenerate case + pivot = points[0]; + } else if (points.length === 2) { + pivot = geoInterp(points[0], points[1], 0.5); + } else { + pivot = d3polygonCentroid(d3polygonHull(points)); + } prevAngle = undefined; } diff --git a/modules/operations/reflect.js b/modules/operations/reflect.js index 2457e20b3..7f17e2c32 100644 --- a/modules/operations/reflect.js +++ b/modules/operations/reflect.js @@ -1,8 +1,9 @@ import _ from 'lodash'; import { t } from '../util/locale'; -import { actionReflect } from '../actions/index'; -import { behaviorOperation } from '../behavior/index'; -import { geoExtent } from '../geo/index'; +import { actionReflect } from '../actions'; +import { behaviorOperation } from '../behavior'; +import { geoExtent } from '../geo'; +import { utilGetAllNodes } from '../util'; export function operationReflectShort(selectedIDs, context) { @@ -31,13 +32,8 @@ export function operationReflect(selectedIDs, context, axis) { operation.available = function() { - return _.some(selectedIDs, hasArea); - - function hasArea(id) { - var entity = context.entity(id); - return (entity.type === 'way' && entity.isClosed()) || - (entity.type ==='relation' && entity.isMultipolygon()); - } + var nodes = utilGetAllNodes(selectedIDs, context.graph()); + return _.uniqBy(nodes, function(n) { return n.loc; }).length >= 3; }; diff --git a/modules/operations/rotate.js b/modules/operations/rotate.js index b0fe066f4..4824db9a3 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -1,8 +1,9 @@ import _ from 'lodash'; import { t } from '../util/locale'; -import { behaviorOperation } from '../behavior/index'; -import { geoExtent } from '../geo/index'; -import { modeRotate } from '../modes/index'; +import { behaviorOperation } from '../behavior'; +import { geoExtent } from '../geo'; +import { modeRotate } from '../modes'; +import { utilGetAllNodes } from '../util'; export function operationRotate(selectedIDs, context) { @@ -18,13 +19,8 @@ export function operationRotate(selectedIDs, context) { operation.available = function() { - return _.some(selectedIDs, hasArea); - - function hasArea(id) { - var entity = context.entity(id); - return (entity.type === 'way' && entity.isClosed()) || - (entity.type ==='relation' && entity.isMultipolygon()); - } + var nodes = utilGetAllNodes(selectedIDs, context.graph()); + return _.uniqBy(nodes, function(n) { return n.loc; }).length >= 2; };