Changeset 11441 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWay.java
r11149 r11441 31 31 @Override 32 32 public void visit(Way w) { 33 int last = w.getNodesCount(); 34 if (last < 2) 35 return; 33 36 Set<Node> nodes = new HashSet<>(); 34 for (int i = 1; i < w.getNodesCount() - 1; i++) { 37 nodes.add(w.firstNode()); 38 int countFirst = 0; 39 int countLast = 0; 40 for (int i = 1; i < last; i++) { 35 41 Node n = w.getNode(i); 36 42 if (nodes.contains(n)) { 37 errors.add(TestError.builder(this, Severity.WARNING, SELF_INTERSECT) 38 .message(tr("Self-intersecting ways")) 39 .primitives(w) 40 .highlight(n) 41 .build()); 42 break; 43 boolean ok = false; 44 if (n == w.firstNode()) { 45 if (countFirst++ == 0) 46 ok = true; 47 } else if (i + 1 == last) { 48 if (countLast++ == 0) 49 ok = true; 50 } 51 if (!ok || countFirst + countLast > 1) { 52 errors.add(TestError.builder(this, Severity.WARNING, SELF_INTERSECT) 53 .message(tr("Self-intersecting ways")) 54 .primitives(w) 55 .highlight(n) 56 .build()); 57 break; 58 } 43 59 } else { 44 60 nodes.add(n); -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWayTest.java
r11201 r11441 25 25 @BeforeClass 26 26 public static void setUp() throws Exception { 27 JOSMFixture.createUnitTestFixture().init( true);27 JOSMFixture.createUnitTestFixture().init(false); 28 28 } 29 29 30 30 private static List<Node> createNodes() { 31 31 List<Node> nodes = new ArrayList<>(); 32 for (int i = 0; i < 5; i++) {32 for (int i = 0; i < 6; i++) { 33 33 nodes.add(new Node(i+1)); 34 34 } 35 nodes.get(0).setCoor(new LatLon(34.2680878298, 133.56336369008)); 36 nodes.get(1).setCoor(new LatLon(34.25096598132, 133.54891792012)); 37 nodes.get(2).setCoor(new LatLon(34.24466741332, 133.56693544639)); 38 nodes.get(3).setCoor(new LatLon(34.26815342405, 133.56066502976)); 39 nodes.get(4).setCoor(new LatLon(34.26567411471, 133.56132705125)); 35 nodes.get(0).setCoor(new LatLon(34.2680, 133.563)); 36 nodes.get(1).setCoor(new LatLon(34.2509, 133.548)); 37 nodes.get(2).setCoor(new LatLon(34.2446, 133.566)); 38 nodes.get(3).setCoor(new LatLon(34.2681, 133.560)); 39 nodes.get(4).setCoor(new LatLon(34.2656, 133.561)); 40 nodes.get(5).setCoor(new LatLon(34.2655, 133.562)); 40 41 return nodes; 41 42 } … … 86 87 87 88 /** 89 * First node is identical to an inner node ("P"-Shape). 90 * This is considered okay. 91 */ 92 @Test 93 public void testUnclosedWayFirstRepeated() { 94 List<Node> nodes = createNodes(); 95 96 Way w = (Way) OsmUtils.createPrimitive("way "); 97 List<Node> wayNodes = new ArrayList<>(); 98 wayNodes.add(nodes.get(0)); 99 wayNodes.add(nodes.get(1)); 100 wayNodes.add(nodes.get(2)); 101 wayNodes.add(nodes.get(0)); 102 wayNodes.add(nodes.get(3)); 103 wayNodes.add(nodes.get(4)); 104 w.setNodes(wayNodes); 105 SelfIntersectingWay test = new SelfIntersectingWay(); 106 test.visit(w); 107 Assert.assertEquals(0, test.getErrors().size()); 108 } 109 110 /** 88 111 * Last node is identical to an inner node ("b"-Shape). 89 112 * This is considered okay. … … 109 132 /** 110 133 * Both endpoints join at one inner node ("8"-shape). 111 * This is considered okay.134 * This is considered to be an error. 112 135 */ 113 136 @Test … … 127 150 SelfIntersectingWay test = new SelfIntersectingWay(); 128 151 test.visit(w); 129 Assert.assertEquals(0, test.getErrors().size()); 152 Assert.assertEquals(1, test.getErrors().size()); 153 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(0))); 154 } 155 156 /** 157 * Closed way contains a spike. 158 * This is considered to be an error. 159 */ 160 @Test 161 public void testSpikeWithStartInClosedWay() { 162 List<Node> nodes = createNodes(); 163 164 Way w = (Way) OsmUtils.createPrimitive("way "); 165 List<Node> wayNodes = new ArrayList<>(); 166 wayNodes.add(nodes.get(0)); 167 wayNodes.add(nodes.get(1)); 168 wayNodes.add(nodes.get(0)); // problem 169 wayNodes.add(nodes.get(3)); 170 wayNodes.add(nodes.get(4)); 171 wayNodes.add(nodes.get(0)); 172 w.setNodes(wayNodes); 173 SelfIntersectingWay test = new SelfIntersectingWay(); 174 test.visit(w); 175 Assert.assertEquals(1, test.getErrors().size()); 176 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(0))); 177 } 178 179 /** 180 * Closed way contains a spike. 181 * This is considered to be an error. 182 */ 183 @Test 184 public void testSpikeWithEndInClosedWay() { 185 List<Node> nodes = createNodes(); 186 187 Way w = (Way) OsmUtils.createPrimitive("way "); 188 List<Node> wayNodes = new ArrayList<>(); 189 wayNodes.add(nodes.get(0)); 190 wayNodes.add(nodes.get(1)); 191 wayNodes.add(nodes.get(2)); 192 wayNodes.add(nodes.get(0)); // problem 193 wayNodes.add(nodes.get(3)); 194 wayNodes.add(nodes.get(0)); 195 w.setNodes(wayNodes); 196 SelfIntersectingWay test = new SelfIntersectingWay(); 197 test.visit(w); 198 Assert.assertEquals(1, test.getErrors().size()); 199 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(0))); 200 } 201 202 /** 203 * Closed way contains a spike. 204 * This is considered to be an error. 205 */ 206 @Test 207 public void testSpikeInClosedWay() { 208 List<Node> nodes = createNodes(); 209 210 Way w = (Way) OsmUtils.createPrimitive("way "); 211 List<Node> wayNodes = new ArrayList<>(); 212 wayNodes.add(nodes.get(0)); 213 wayNodes.add(nodes.get(1)); 214 wayNodes.add(nodes.get(2)); 215 wayNodes.add(nodes.get(3)); 216 wayNodes.add(nodes.get(2)); 217 wayNodes.add(nodes.get(0)); 218 w.setNodes(wayNodes); 219 SelfIntersectingWay test = new SelfIntersectingWay(); 220 test.visit(w); 221 Assert.assertEquals(1, test.getErrors().size()); 222 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(2))); 223 } 224 225 /** 226 * Closed way with barbell shape (a-b-c-a-d-e-f-d). 227 * This is considered to be an error. 228 */ 229 @Test 230 public void testClosedWayBarbell() { 231 List<Node> nodes = createNodes(); 232 233 Way w = (Way) OsmUtils.createPrimitive("way "); 234 List<Node> wayNodes = new ArrayList<>(); 235 wayNodes.add(nodes.get(0)); 236 wayNodes.add(nodes.get(1)); 237 wayNodes.add(nodes.get(2)); 238 wayNodes.add(nodes.get(0)); 239 wayNodes.add(nodes.get(3)); 240 wayNodes.add(nodes.get(4)); 241 wayNodes.add(nodes.get(5)); 242 wayNodes.add(nodes.get(3)); 243 w.setNodes(wayNodes); 244 SelfIntersectingWay test = new SelfIntersectingWay(); 245 test.visit(w); 246 Assert.assertEquals(1, test.getErrors().size()); 247 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(3))); 130 248 } 131 249
Note:
See TracChangeset
for help on using the changeset viewer.