001 // License: GPL. See LICENSE file for details.
002 package org.openstreetmap.josm.data.validation.tests;
003
004 import static org.openstreetmap.josm.tools.I18n.tr;
005
006 import java.util.Collections;
007
008 import org.openstreetmap.josm.data.osm.Way;
009 import org.openstreetmap.josm.data.validation.Severity;
010 import org.openstreetmap.josm.data.validation.Test;
011 import org.openstreetmap.josm.data.validation.TestError;
012 import org.openstreetmap.josm.tools.Geometry;
013
014 /**
015 * Check cyclic ways for errors
016 *
017 * @author jrreid
018 */
019 public class WronglyOrderedWays extends Test {
020
021 protected static final int WRONGLY_ORDERED_COAST = 1001;
022 //protected static int WRONGLY_ORDERED_WATER = 1002;
023 protected static final int WRONGLY_ORDERED_LAND = 1003;
024
025 /**
026 * Constructor
027 */
028 public WronglyOrderedWays() {
029 super(tr("Wrongly Ordered Ways"),
030 tr("This test checks the direction of water, land and coastline ways."));
031 }
032
033 @Override
034 public void visit(Way w) {
035
036 if (!w.isUsable() || !w.isClosed())
037 return;
038
039 String natural = w.get("natural");
040 if (natural == null)
041 return;
042 else if ("coastline".equals(natural) && Geometry.isClockwise(w)) {
043 reportError(w, tr("Reversed coastline: land not on left side"), WRONGLY_ORDERED_COAST);
044 /*} else if ("water".equals(natural) && !Geometry.isClockwise(w)) {
045 reportError(w, tr("Reversed water: land not on left side"), WRONGLY_ORDERED_WATER);*/
046 } else if ("land".equals(natural) && Geometry.isClockwise(w)) {
047 reportError(w, tr("Reversed land: land not on left side"), WRONGLY_ORDERED_LAND);
048 } else
049 return;
050
051 }
052
053 private void reportError(Way w, String msg, int type) {
054 errors.add(new TestError(this, Severity.WARNING, msg, type, Collections.singletonList(w)));
055 }
056 }