Changeset 15448 in josm
- Timestamp:
- 2019-10-10T16:57:43+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java
r15427 r15448 6 6 import java.util.Arrays; 7 7 import java.util.Collection; 8 import java.util.LinkedHashMap;9 import java.util.Map;10 import java.util.Map.Entry;11 8 import java.util.Objects; 12 9 import java.util.TreeSet; … … 17 14 import org.openstreetmap.josm.data.osm.Way; 18 15 import org.openstreetmap.josm.data.osm.WaySegment; 16 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper; 19 17 import org.openstreetmap.josm.data.validation.Severity; 20 18 import org.openstreetmap.josm.data.validation.Test; … … 36 34 /** The length that at least one way segment must be shorter than */ 37 35 private double maxLength = 10.0; // meters 38 /** The stepping points for severity */39 private Map<Double, Severity> severityBreakPoints = new LinkedHashMap<>();40 36 /** Specific highway types to ignore */ 41 37 private Collection<String> ignoreHighways = new TreeSet<>( … … 47 43 public SharpAngles() { 48 44 super(tr("Sharp angles"), tr("Check for sharp angles on roads")); 49 setBreakPoints();50 45 } 51 46 … … 53 48 public void visit(Way way) { 54 49 if (!way.isUsable()) return; 55 if (way.hasKey("highway") && !way.hasTag("area", "yes") && 56 !ignoreHighways.contains(way.get("highway"))) { 50 if (shouldBeTestedForSharpAngles(way)) { 57 51 try { 58 52 checkWayForSharpAngles(way); … … 61 55 } 62 56 } 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"))); 63 67 } 64 68 … … 109 113 110 114 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 } 116 124 } 117 125 118 126 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; 126 128 } 127 129 … … 148 150 public void setMaxAngle(double angle) { 149 151 maxAngle = angle; 150 setBreakPoints();151 }152 153 /**154 * Set the breakpoints for the test155 */156 private void setBreakPoints() {157 severityBreakPoints.clear();158 severityBreakPoints.put(maxAngle, Severity.OTHER);159 severityBreakPoints.put(maxAngle * 2 / 3, Severity.WARNING);160 152 } 161 153
Note:
See TracChangeset
for help on using the changeset viewer.