Relax the availability rules for rotation and reflection operations

(closes #4237)

New rules:
- Rotation available if at least 2 unique nodes in selectedIDs
- Reflection available if at least 3 unique nodes in selectedIDs
This commit is contained in:
Bryan Housel
2017-08-17 14:32:32 -04:00
parent 0ea043b311
commit 5ffa8f535e
3 changed files with 23 additions and 26 deletions
+11 -6
View File
@@ -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;
}
+6 -10
View File
@@ -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;
};
+6 -10
View File
@@ -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;
};