Ticket #21333: 21333.patch

File 21333.patch, 3.3 KB (added by taylor.smock, 3 years ago)

Fairly basic (non-tested) patch to add railways to SharpAngles test.

  • 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..1c6353ff35 100644
    a b import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;  
    1616import org.openstreetmap.josm.data.validation.Severity;
    1717import org.openstreetmap.josm.data.validation.Test;
    1818import org.openstreetmap.josm.data.validation.TestError;
     19import org.openstreetmap.josm.spi.preferences.Config;
    1920import org.openstreetmap.josm.tools.Geometry;
    2021import org.openstreetmap.josm.tools.bugreport.BugReport;
    2122
    public class SharpAngles extends Test {  
    2829    private static final int SHARPANGLESCODE = 3800;
    2930    /** The code for a sharp angle */
    3031    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
     32    /** The maximum angle for sharp angles (degrees) */
     33    private double maxAngle;
     34    /** The length that at least one way segment must be shorter than (meters) */
     35    private double maxLength;
    3536    /** Specific highway types to ignore */
    3637    private final Collection<String> ignoreHighways = new TreeSet<>(
    3738            Arrays.asList("platform", "rest_area", "services", "via_ferrata"));
     39    /** Specific railway types to ignore */
     40    private final Collection<String> ignoreRailway = new TreeSet<>();
    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
    4449    }
    4550
    4651    @Override
    public class SharpAngles extends Test {  
    6166     * @return {@code true} if the way should be checked.
    6267     */
    6368    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")));
     69        return !way.hasTag("area", "yes") &&
     70                ((way.hasKey("highway") && !way.hasKey("via_ferrata_scale") && !ignoreHighways.contains(way.get("highway")))
     71                    || (way.hasKey("railway") && !ignoreRailway.contains(way.get("railway"))));
    6672    }
    6773
    6874    /**
    public class SharpAngles extends Test {  
    144150        ignoreHighways.add(highway);
    145151    }
    146152
     153    /**
     154     * Add a railway to ignore
     155     * @param railway The highway type to ignore (e.g., if you want to ignore miniature railways, use "miniature")
     156     * @since xxx
     157     */
     158    public void addIgnoredRailway(String railway) {
     159        ignoreRailway.add(railway);
     160    }
     161
    147162    /**
    148163     * Set the maximum angle
    149164     * @param angle The maximum angle in degrees.