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