Skip to content

Commit

Permalink
Relax the availability rules for rotation and reflection operations
Browse files Browse the repository at this point in the history
(closes #4237)

New rules:
- Rotation available if at least 2 unique nodes in selectedIDs
- Reflection available if at least 3 unique nodes in selectedIDs
  • Loading branch information
bhousel committed Aug 17, 2017
1 parent 0ea043b commit 5ffa8f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
17 changes: 11 additions & 6 deletions modules/modes/rotate.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,7 +16,7 @@ import {
operationOrthogonalize,
operationReflectLong,
operationReflectShort
} from '../operations/index';
} from '../operations';

import {
polygonHull as d3polygonHull,
Expand Down Expand Up @@ -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;
}

Expand Down
16 changes: 6 additions & 10 deletions modules/operations/reflect.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
};


Expand Down
16 changes: 6 additions & 10 deletions modules/operations/rotate.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
};


Expand Down

0 comments on commit 5ffa8f5

Please sign in to comment.