diff --git a/src/org/openstreetmap/josm/data/osm/Way.java b/src/org/openstreetmap/josm/data/osm/Way.java
index 4826657..b0313ed 100644
a
|
b
|
public final class Way extends OsmPrimitive implements IWay {
|
589 | 589 | } |
590 | 590 | return length; |
591 | 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Tests if this way is a oneway. |
| 595 | * @return {@code 1} if the way is a oneway, {@code -1} if the way is a reversed oneway, |
| 596 | * {@code 0} otherwise. |
| 597 | */ |
| 598 | public int isOneway() { |
| 599 | String oneway = get("oneway"); |
| 600 | if (oneway != null) { |
| 601 | if ("-1".equals(oneway)) { |
| 602 | return -1; |
| 603 | } else { |
| 604 | Boolean isOneway = OsmUtils.getOsmBoolean(oneway); |
| 605 | if (isOneway != null && isOneway) { |
| 606 | return 1; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | public Node firstNode(boolean respectOneway) { |
| 614 | return !respectOneway || isOneway() != -1 ? firstNode() : lastNode(); |
| 615 | } |
| 616 | |
| 617 | public Node lastNode(boolean respectOneway) { |
| 618 | return !respectOneway || isOneway() != -1 ? lastNode() : firstNode(); |
| 619 | } |
592 | 620 | } |
diff --git a/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java b/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
index 13298f1..6846df3 100644
a
|
b
|
import java.util.List;
|
10 | 10 | |
11 | 11 | import org.openstreetmap.josm.data.osm.Node; |
12 | 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
13 | | import org.openstreetmap.josm.data.osm.OsmUtils; |
14 | 13 | import org.openstreetmap.josm.data.osm.Relation; |
15 | 14 | import org.openstreetmap.josm.data.osm.RelationMember; |
16 | 15 | import org.openstreetmap.josm.data.osm.Way; |
… |
… |
public class TurnrestrictionTest extends Test {
|
34 | 33 | protected static final int TO_VIA_WAY = 1812; |
35 | 34 | protected static final int MIX_VIA = 1813; |
36 | 35 | protected static final int UNCONNECTED_VIA = 1814; |
| 36 | protected static final int SUPERFLUOUS = 1815; |
37 | 37 | |
38 | 38 | public TurnrestrictionTest() { |
39 | 39 | super(tr("Turnrestrictions"), tr("This test checks if turnrestrictions are valid")); |
… |
… |
public class TurnrestrictionTest extends Test {
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | | Node viaNode; |
140 | 139 | if (via.get(0) instanceof Node) { |
141 | | viaNode = (Node) via.get(0); |
| 140 | Node viaNode = (Node) via.get(0); |
142 | 141 | Way viaPseudoWay = new Way(); |
143 | 142 | viaPseudoWay.addNode(viaNode); |
144 | 143 | checkIfConnected(fromWay, viaPseudoWay, |
145 | 144 | tr("The \"from\" way does not start or end at a \"via\" node"), FROM_VIA_NODE); |
| 145 | if(toWay.isOneway() != 0 && viaNode.equals(toWay.lastNode(true))) { |
| 146 | errors.add(new TestError(this, Severity.WARNING, tr("Superfluous turnrestriction as \"to\" way is oneway"), SUPERFLUOUS, r)); |
| 147 | return; |
| 148 | } |
146 | 149 | checkIfConnected(viaPseudoWay, toWay, |
147 | 150 | tr("The \"to\" way does not start or end at a \"via\" node"), TO_VIA_NODE); |
148 | 151 | } else { |
… |
… |
public class TurnrestrictionTest extends Test {
|
157 | 160 | tr("The \"via\" ways are not connected."), UNCONNECTED_VIA); |
158 | 161 | } |
159 | 162 | } |
| 163 | if(toWay.isOneway() != 0 && ((Way)via.get(via.size()-1)).isFirstLastNode(toWay.lastNode(true))) { |
| 164 | errors.add(new TestError(this, Severity.WARNING, tr("Superfluous turnrestriction as \"to\" way is oneway"), SUPERFLUOUS, r)); |
| 165 | return; |
| 166 | } |
160 | 167 | checkIfConnected((Way) via.get(via.size() - 1), toWay, |
161 | 168 | tr("The last \"via\" and the \"to\" way are not connected."), TO_VIA_WAY); |
162 | 169 | |
… |
… |
public class TurnrestrictionTest extends Test {
|
164 | 171 | } |
165 | 172 | |
166 | 173 | private void checkIfConnected(Way previous, Way current, String msg, int code) { |
167 | | int onewayPrevious = isOneway(previous); |
168 | | int onewayCurrent = isOneway(current); |
169 | | Node endPrevious = onewayPrevious != -1 ? previous.lastNode() : previous.firstNode(); |
170 | | Node startCurrent = onewayCurrent != -1 ? current.firstNode() : current.lastNode(); |
171 | | //System.out.println(previous.getUniqueId() + " -- " + current.getUniqueId() + ": " + onewayPrevious + "/" + onewayCurrent + " " + endPrevious.getUniqueId() + "/" + startCurrent.getUniqueId()); |
172 | 174 | boolean c; |
173 | | if (onewayPrevious != 0 && onewayCurrent != 0) { |
| 175 | if (previous.isOneway() != 0 && current.isOneway() != 0) { |
174 | 176 | // both oneways: end/start node must be equal |
175 | | c = endPrevious.equals(startCurrent); |
176 | | } else if (onewayPrevious != 0) { |
| 177 | c = previous.lastNode(true).equals(current.firstNode(true)); |
| 178 | } else if (previous.isOneway() != 0) { |
177 | 179 | // previous way is oneway: end of previous must be start/end of current |
178 | | c = current.isFirstLastNode(endPrevious); |
179 | | } else if (onewayCurrent != 0) { |
| 180 | c = current.isFirstLastNode(previous.lastNode(true)); |
| 181 | } else if (current.isOneway() != 0) { |
180 | 182 | // current way is oneway: start of current must be start/end of previous |
181 | | c = previous.isFirstLastNode(startCurrent); |
| 183 | c = previous.isFirstLastNode(current.firstNode(true)); |
182 | 184 | } else { |
183 | 185 | // otherwise: start/end of previous must be start/end of current |
184 | 186 | c = current.isFirstLastNode(previous.firstNode()) || current.isFirstLastNode(previous.lastNode()); |
… |
… |
public class TurnrestrictionTest extends Test {
|
187 | 189 | errors.add(new TestError(this, Severity.ERROR, msg, code, Arrays.asList(previous, current))); |
188 | 190 | } |
189 | 191 | } |
190 | | |
191 | | private static int isOneway(Way w) { |
192 | | String onewayviastr = w.get("oneway"); |
193 | | if (onewayviastr != null) { |
194 | | if ("-1".equals(onewayviastr)) { |
195 | | return -1; |
196 | | } else { |
197 | | Boolean onewayvia = OsmUtils.getOsmBoolean(onewayviastr); |
198 | | if (onewayvia != null && onewayvia) { |
199 | | return 1; |
200 | | } |
201 | | } |
202 | | } |
203 | | return 0; |
204 | | } |
205 | 192 | } |