Lower default threshold for unsquare building detection to 5 degrees

Use the detection threshold for the action when fixing unsquare buildings
Don't disallow unsquare autofixing based on maximum angle
Disallow unsquare autofixing for features with wikidata tags
Don't toggle rule when selecting degree threshold field in Safari
Apply the change when pressing enter in the degree threshold field
Select the input when clicking the degree threshold field
Use the min or max threshold instead of the default when an input is out of bounds
This commit is contained in:
Quincy Morgan
2019-05-20 15:48:01 -04:00
parent 39784cdd1f
commit 460f136819
3 changed files with 30 additions and 22 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import {
} from '../geo';
export function actionOrthogonalize(wayID, projection, vertexID, ep, degThresh) {
export function actionOrthogonalize(wayID, projection, vertexID, degThresh, ep) {
var epsilon = ep || 1e-4;
var threshold = degThresh || 13; // degrees within right or straight to alter
+17 -2
View File
@@ -18,7 +18,7 @@ export function uiIssues(context) {
var MINSQUARE = 0;
var MAXSQUARE = 20;
var DEFAULTSQUARE = 6.5; // see also unsquare_way.js
var DEFAULTSQUARE = 5; // see also unsquare_way.js
var _errorsSelection = d3_select(null);
var _warningsSelection = d3_select(null);
@@ -610,6 +610,17 @@ export function uiIssues(context) {
.on('input', function() {
this.style.width = (this.value.length + 1) + 'ch'; // resize
})
.on('click', function () {
d3_event.preventDefault();
d3_event.stopPropagation();
this.select();
})
.on('keyup', function () {
if (d3_event.keyCode === 13) { // enter
this.blur();
this.select();
}
})
.on('blur', changeSquare)
.merge(input)
.property('value', degStr)
@@ -622,8 +633,12 @@ export function uiIssues(context) {
var degStr = utilGetSetValue(input).trim();
var degNum = parseFloat(degStr, 10);
if (!isFinite(degNum) || degNum > MAXSQUARE || degNum < MINSQUARE) {
if (!isFinite(degNum)) {
degNum = DEFAULTSQUARE;
} else if (degNum > MAXSQUARE) {
degNum = MAXSQUARE;
} else if (degNum < MINSQUARE) {
degNum = MINSQUARE;
}
degNum = Math.round(degNum * 10 ) / 10; // round to 1 decimal
+12 -19
View File
@@ -1,21 +1,18 @@
import { t } from '../util/locale';
import { actionChangeTags } from '../actions/change_tags';
import { actionOrthogonalize } from '../actions/orthogonalize';
import { geoOrthoCanOrthogonalize, geoOrthoMaxOffsetAngle } from '../geo/ortho';
import { geoOrthoCanOrthogonalize } from '../geo/ortho';
import { utilDisplayLabel } from '../util';
import { validationIssue, validationIssueFix } from '../core/validation';
export function validationUnsquareWay() {
var type = 'unsquare_way';
var DEFAULTSQUARE = 6.5; // see also issues.js
var DEFAULT_DEG_THRESHOLD = 5; // see also issues.js
// use looser epsilon for detection to reduce warnings of buildings that are essentially square already
var epsilon = 0.05;
var nodeThreshold = 10;
// var degreeThreshold = 13;
// var autofixDegreeThreshold = 6.5;
function isBuilding(entity, graph) {
if (entity.type !== 'way' || entity.geometry(graph) !== 'area') return false;
@@ -56,22 +53,18 @@ export function validationUnsquareWay() {
if (hasConnectedSquarableWays) return [];
// testing: user-configurable square threshold
var degreeThreshold = context.storage('validate-square-degrees');
if (degreeThreshold === null) {
degreeThreshold = '' + DEFAULTSQUARE;
}
var autofixDegreeThreshold = degreeThreshold;
// user-configurable square threshold
var storedDegreeThreshold = context.storage('validate-square-degrees');
var degreeThreshold = isNaN(storedDegreeThreshold) ? DEFAULT_DEG_THRESHOLD : parseFloat(storedDegreeThreshold);
var points = nodes.map(function(node) { return context.projection(node.loc); });
if (!geoOrthoCanOrthogonalize(points, isClosed, epsilon, degreeThreshold, true)) return [];
var autoArgs;
// only allow autofixing features that are very close to square already
var maxOffsetAngle = geoOrthoMaxOffsetAngle(points, isClosed, degreeThreshold);
if (maxOffsetAngle && maxOffsetAngle < autofixDegreeThreshold) {
// note: use default params for actionOrthogonalize, not relaxed epsilon
var autoAction = actionOrthogonalize(entity.id, context.projection);
// don't allow autosquaring features linked to wikidata
if (!entity.tags.wikidata) {
// use same degree threshold as for detection
var autoAction = actionOrthogonalize(entity.id, context.projection, undefined, degreeThreshold);
autoAction.transitionable = false; // when autofixing, do it instantly
autoArgs = [autoAction, t('operations.orthogonalize.annotation.area')];
}
@@ -85,7 +78,7 @@ var autofixDegreeThreshold = degreeThreshold;
},
reference: showReference,
entityIds: [entity.id],
hash: JSON.stringify(autoArgs !== undefined),
hash: JSON.stringify(autoArgs !== undefined) + degreeThreshold,
fixes: [
new validationIssueFix({
icon: 'iD-operation-orthogonalize',
@@ -93,9 +86,9 @@ var autofixDegreeThreshold = degreeThreshold;
autoArgs: autoArgs,
onClick: function(completionHandler) {
var entityId = this.issue.entityIds[0];
// note: use default params for actionOrthogonalize, not relaxed epsilon
// use same degree threshold as for detection
context.perform(
actionOrthogonalize(entityId, context.projection),
actionOrthogonalize(entityId, context.projection, undefined, degreeThreshold),
t('operations.orthogonalize.annotation.area')
);
// run after the squaring transition (currently 150ms)