Changeset 15448 in josm


Ignore:
Timestamp:
2019-10-10T16:57:43+02:00 (5 years ago)
Author:
GerdP
Message:

fix #18127: 18127.14.patch with some simplifications

  • ignore ways with tag via_ferrata_scale=*
  • only create errors with Severity.OTHER if needed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java

    r15427 r15448  
    66import java.util.Arrays;
    77import java.util.Collection;
    8 import java.util.LinkedHashMap;
    9 import java.util.Map;
    10 import java.util.Map.Entry;
    118import java.util.Objects;
    129import java.util.TreeSet;
     
    1714import org.openstreetmap.josm.data.osm.Way;
    1815import org.openstreetmap.josm.data.osm.WaySegment;
     16import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
    1917import org.openstreetmap.josm.data.validation.Severity;
    2018import org.openstreetmap.josm.data.validation.Test;
     
    3634    /** The length that at least one way segment must be shorter than */
    3735    private double maxLength = 10.0; // meters
    38     /** The stepping points for severity */
    39     private Map<Double, Severity> severityBreakPoints = new LinkedHashMap<>();
    4036    /** Specific highway types to ignore */
    4137    private Collection<String> ignoreHighways = new TreeSet<>(
     
    4743    public SharpAngles() {
    4844        super(tr("Sharp angles"), tr("Check for sharp angles on roads"));
    49         setBreakPoints();
    5045    }
    5146
     
    5348    public void visit(Way way) {
    5449        if (!way.isUsable()) return;
    55         if (way.hasKey("highway") && !way.hasTag("area", "yes") &&
    56                     !ignoreHighways.contains(way.get("highway"))) {
     50        if (shouldBeTestedForSharpAngles(way)) {
    5751            try {
    5852                checkWayForSharpAngles(way);
     
    6155            }
    6256        }
     57    }
     58
     59    /**
     60     * Check whether or not a way should be checked for sharp angles
     61     * @param way The way that needs to be checked
     62     * @return {@code true} if the way should be checked.
     63     */
     64    public boolean shouldBeTestedForSharpAngles(Way way) {
     65        return (way.hasKey("highway") && !way.hasTag("area", "yes") && !way.hasKey("via_ferrata_scale") &&
     66                !ignoreHighways.contains(way.get("highway")));
    6367    }
    6468
     
    109113
    110114    private void createNearlyOverlappingError(double angle, Way way, OsmPrimitive primitive) {
    111         TestError.Builder testError = TestError.builder(this, getSeverity(angle), SHARP_ANGLES)
    112                 .primitives(way)
    113                 .highlight(primitive)
    114                 .message(tr("Sharp angle"));
    115         errors.add(testError.build());
     115        Severity severity = getSeverity(angle);
     116        if (severity != Severity.OTHER || (ValidatorPrefHelper.PREF_OTHER.get() || ValidatorPrefHelper.PREF_OTHER_UPLOAD.get())) {
     117            int addCode = severity == Severity.OTHER ? 1 : 0;
     118            TestError.Builder testError = TestError.builder(this, severity, SHARP_ANGLES + addCode)
     119                    .primitives(way)
     120                    .highlight(primitive)
     121                    .message(tr("Sharp angle"));
     122            errors.add(testError.build());
     123        }
    116124    }
    117125
    118126    private Severity getSeverity(double angle) {
    119         Severity rSeverity = Severity.OTHER;
    120         for (Entry<Double, Severity> entry : severityBreakPoints.entrySet()) {
    121             if (angle < entry.getKey()) {
    122                 rSeverity = entry.getValue();
    123             }
    124         }
    125         return rSeverity;
     127        return angle < maxAngle * 2 / 3 ? Severity.WARNING : Severity.OTHER;
    126128    }
    127129
     
    148150    public void setMaxAngle(double angle) {
    149151        maxAngle = angle;
    150         setBreakPoints();
    151     }
    152 
    153     /**
    154      * Set the breakpoints for the test
    155      */
    156     private void setBreakPoints() {
    157         severityBreakPoints.clear();
    158         severityBreakPoints.put(maxAngle, Severity.OTHER);
    159         severityBreakPoints.put(maxAngle * 2 / 3, Severity.WARNING);
    160152    }
    161153
Note: See TracChangeset for help on using the changeset viewer.