Ticket #21333: 21333.3.patch

File 21333.3.patch, 4.2 KB (added by taylor.smock, 3 years ago)

Set ignoreRailway/Highway from config values

  • src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java b/src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java
    index 676eb47f10..48c152a7fc 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr;  
    55
    66import java.util.Arrays;
    77import java.util.Collection;
     8import java.util.Collections;
    89import java.util.TreeSet;
    910
    1011import org.openstreetmap.josm.data.coor.EastNorth;
    import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;  
    1617import org.openstreetmap.josm.data.validation.Severity;
    1718import org.openstreetmap.josm.data.validation.Test;
    1819import org.openstreetmap.josm.data.validation.TestError;
     20import org.openstreetmap.josm.spi.preferences.Config;
    1921import org.openstreetmap.josm.tools.Geometry;
    2022import org.openstreetmap.josm.tools.bugreport.BugReport;
    2123
    public class SharpAngles extends Test {  
    2830    private static final int SHARPANGLESCODE = 3800;
    2931    /** The code for a sharp angle */
    3032    private static final int SHARP_ANGLES = SHARPANGLESCODE + 0;
    31     /** The maximum angle for sharp angles */
    32     private double maxAngle = 45.0; // degrees
    33     /** The length that at least one way segment must be shorter than */
    34     private double maxLength = 10.0; // meters
     33    /** The maximum angle for sharp angles (degrees) */
     34    private double maxAngle;
     35    /** The length that at least one way segment must be shorter than (meters) */
     36    private double maxLength;
    3537    /** Specific highway types to ignore */
    36     private final Collection<String> ignoreHighways = new TreeSet<>(
    37             Arrays.asList("platform", "rest_area", "services", "via_ferrata"));
     38    private final Collection<String> ignoreHighways;
     39    /** Specific railway types to ignore */
     40    private final Collection<String> ignoreRailway;
    3841
    3942    /**
    4043     * Construct a new {@code IntersectionIssues} object
    4144     */
    4245    public SharpAngles() {
    43         super(tr("Sharp angles"), tr("Check for sharp angles on roads"));
     46        super(tr("Sharp angles"), tr("Check for sharp angles on man made transportation ways"));
     47        this.maxLength = Config.getPref().getDouble("validator.sharpangles.maxlength", 10.0); // meters
     48        this.maxAngle = Config.getPref().getDouble("validator.sharpangles.maxlength", 45.0); // degrees
     49        this.ignoreRailway = Collections.unmodifiableCollection(new TreeSet<>(
     50                Config.getPref().getList("validator.sharpangles.ignorerailway",
     51        Arrays.asList("crossing_box", "loading_ramp", "platform", "roundhouse", "signal_box", "station",
     52                "traverser", "wash", "workshop"))));
     53        // TODO make immutable when addIgnoredHighway is removed
     54        this.ignoreHighways = new TreeSet<>(
     55                Config.getPref().getList("validator.sharpangles.ignorehighway",
     56                        Arrays.asList("platform", "rest_area", "services", "via_ferrata"))
     57        );
    4458    }
    4559
    4660    @Override
    public class SharpAngles extends Test {  
    6175     * @return {@code true} if the way should be checked.
    6276     */
    6377    public boolean shouldBeTestedForSharpAngles(Way way) {
    64         return (way.hasKey("highway") && !way.hasTag("area", "yes") && !way.hasKey("via_ferrata_scale") &&
    65                 !ignoreHighways.contains(way.get("highway")));
     78        return !way.hasTag("area", "yes") &&
     79                ((way.hasKey("highway") && !way.hasKey("via_ferrata_scale") && !ignoreHighways.contains(way.get("highway")))
     80                    || (way.hasKey("railway") && !ignoreRailway.contains(way.get("railway"))));
    6681    }
    6782
    6883    /**
    public class SharpAngles extends Test {  
    139154    /**
    140155     * Add a highway to ignore
    141156     * @param highway The highway type to ignore (e.g., if you want to ignore residential roads, use "residential")
     157     * @since xxx (deprecated)
     158     * @deprecated Not known to be used. Please use config preference "validator.sharpangles.ignorehighway" instead.
    142159     */
     160    @Deprecated
    143161    public void addIgnoredHighway(String highway) {
     162        // Don't forget to make ignoreHighways immutable when this method is removed
    144163        ignoreHighways.add(highway);
    145164    }
    146165