From 59bd6194e0f162c36d33644c15c521043dfaf56c Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Fri, 26 Apr 2019 14:56:39 -0700 Subject: [PATCH] Add "autofix" for the unsquare building validation --- modules/actions/orthogonalize.js | 6 ++--- modules/validations/disconnected_way.js | 2 +- modules/validations/unsquare_way.js | 31 +++++++++++++++++-------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/modules/actions/orthogonalize.js b/modules/actions/orthogonalize.js index 11ba1131d..5abccafee 100644 --- a/modules/actions/orthogonalize.js +++ b/modules/actions/orthogonalize.js @@ -6,9 +6,9 @@ import { } from '../geo'; -export function actionOrthogonalize(wayID, projection, vertexID) { - var epsilon = 1e-4; - var threshold = 13; // degrees within right or straight to alter +export function actionOrthogonalize(wayID, projection, vertexID, ep, degThresh) { + var epsilon = ep || 1e-4; + var threshold = degThresh || 13; // degrees within right or straight to alter // We test normalized dot products so we can compare as cos(angle) var lowerThreshold = Math.cos((90 - threshold) * Math.PI / 180); diff --git a/modules/validations/disconnected_way.js b/modules/validations/disconnected_way.js index a17772b96..3f4e147ee 100644 --- a/modules/validations/disconnected_way.js +++ b/modules/validations/disconnected_way.js @@ -1,6 +1,6 @@ import { t } from '../util/locale'; import { modeDrawLine } from '../modes/draw_line'; -import { operationDelete } from '../operations/index'; +import { operationDelete } from '../operations/delete'; import { utilDisplayLabel } from '../util'; import { validationIssue, validationIssueFix } from '../core/validation'; diff --git a/modules/validations/unsquare_way.js b/modules/validations/unsquare_way.js index a8c9dff8b..324f4f216 100644 --- a/modules/validations/unsquare_way.js +++ b/modules/validations/unsquare_way.js @@ -1,5 +1,5 @@ import { t } from '../util/locale'; -import { operationOrthogonalize } from '../operations'; +import { actionOrthogonalize } from '../actions/orthogonalize'; import { geoOrthoCanOrthogonalize } from '../geo'; import { utilDisplayLabel } from '../util'; import { validationIssue, validationIssueFix } from '../core/validation'; @@ -8,6 +8,10 @@ import { validationIssue, validationIssueFix } from '../core/validation'; export function validationUnsquareWay() { var type = 'unsquare_way'; + // use looser constraints for detection than those for completing the action + var epsilon = 0.01; + var degreeThreshold = 6; + function isBuilding(entity, graph) { if (entity.type !== 'way' || entity.geometry(graph) !== 'area') return false; @@ -27,22 +31,32 @@ export function validationUnsquareWay() { // don't flag ways with lots of nodes since they are likely detail-mapped if (nodes.length > 6) return []; + var osm = context.connection(); + var connectedToUnloadedTile = nodes.some(function(node) { + return !osm.isDataLoaded(node.loc); + }); + // ignore if not all conncted tiles are downloaded + if (connectedToUnloadedTile) return []; + var hasConnectedSquarableWays = nodes.some(function(node) { return graph.parentWays(node).some(function(way) { if (way.id === entity.id) return false; return isBuilding(way, graph); }); }); - // don't flag connected ways to avoid unresolvable unsquare loops if (hasConnectedSquarableWays) return []; - var locs = nodes.map(function(node) { + var projectedLocs = nodes.map(function(node) { return context.projection(node.loc); }); - // use loose constraints compared to actionOrthogonalize - if (!geoOrthoCanOrthogonalize(locs, isClosed, 0.015, 7, true)) return []; + if (!geoOrthoCanOrthogonalize(projectedLocs, isClosed, epsilon, degreeThreshold, true)) return []; + + var action = actionOrthogonalize(entity.id, context.projection, undefined, epsilon, degreeThreshold); + action.onCompletion = function() { + context.validator().validate(); + }; return new validationIssue({ type: type, @@ -56,12 +70,9 @@ export function validationUnsquareWay() { new validationIssueFix({ icon: 'iD-operation-orthogonalize', title: t('issues.fix.square_feature.title'), + autoArgs: [action, t('operations.orthogonalize.annotation.area')], onClick: function() { - var id = this.issue.entities[0].id; - var operation = operationOrthogonalize([id], context); - if (!operation.disabled()) { - operation(); - } + context.perform(action, t('operations.orthogonalize.annotation.area')); } }) ]