Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWay.java
r11136 r11149 32 32 public void visit(Way w) { 33 33 Set<Node> nodes = new HashSet<>(); 34 int last = w.getNodesCount(); 35 if (last < 2) 36 return; 37 if (w.firstNode() == w.lastNode()) 38 last; // closed way, ignore last node 39 nodes.add(w.firstNode()); 40 for (int i = 1; i < last; i++) { 34 for (int i = 1; i < w.getNodesCount()  1; i++) { 41 35 Node n = w.getNode(i); 42 36 if (nodes.contains(n)) { 
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWayTest.java
r11136 r11149 41 41 } 42 42 43 44 43 /** 45 * SelfIntersection at first (+ last) node of closed way 46 */ 47 @Test 48 public void TestClosedWay() { 49 List<Node> nodes = createNodes(); 50 51 Way w = (Way) OsmUtils.createPrimitive("way "); 52 List<Node> wayNodes = new ArrayList<>(); 53 wayNodes.add(nodes.get(0)); 54 wayNodes.add(nodes.get(1)); 55 wayNodes.add(nodes.get(2)); 56 wayNodes.add(nodes.get(0)); // problem 57 wayNodes.add(nodes.get(3)); 58 wayNodes.add(nodes.get(4)); 59 wayNodes.add(nodes.get(0)); 60 w.setNodes(wayNodes); 61 SelfIntersectingWay test = new SelfIntersectingWay(); 62 test.visit(w); 63 Assert.assertEquals(1, test.getErrors().size()); 64 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(0))); 65 } 66 67 /** 68 * SelfIntersection at first node of unclosed way 69 */ 70 @Test 71 public void TestUnclosedWayFirst() { 72 List<Node> nodes = createNodes(); 73 74 Way w = (Way) OsmUtils.createPrimitive("way "); 75 List<Node> wayNodes = new ArrayList<>(); 76 wayNodes.add(nodes.get(0)); 77 wayNodes.add(nodes.get(1)); 78 wayNodes.add(nodes.get(2)); 79 wayNodes.add(nodes.get(0)); // problem 80 wayNodes.add(nodes.get(3)); 81 wayNodes.add(nodes.get(4)); 82 w.setNodes(wayNodes); 83 SelfIntersectingWay test = new SelfIntersectingWay(); 84 test.visit(w); 85 Assert.assertEquals(1, test.getErrors().size()); 86 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(0))); 87 } 88 89 /** 90 * SelfIntersection at first node of unclosed way 91 */ 92 @Test 93 public void TestUnclosedWayLast() { 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)); // problem 100 wayNodes.add(nodes.get(2)); 101 wayNodes.add(nodes.get(3)); 102 wayNodes.add(nodes.get(4)); 103 wayNodes.add(nodes.get(1)); 104 w.setNodes(wayNodes); 105 SelfIntersectingWay test = new SelfIntersectingWay(); 106 test.visit(w); 107 Assert.assertEquals(1, test.getErrors().size()); 108 Assert.assertTrue(test.getErrors().iterator().next().getHighlighted().contains(nodes.get(1))); 109 } 110 111 /** 112 * SelfIntersection at normal node (not first / last) 44 * SelfIntersection at inner node (not first / last). 113 45 */ 114 46 @Test … … 131 63 } 132 64 65 /** 66 * First node is identical to an inner node ("P"Shape). 67 * This is considered okay. 68 */ 69 @Test 70 public void TestUnclosedWayFirst() { 71 List<Node> nodes = createNodes(); 72 73 Way w = (Way) OsmUtils.createPrimitive("way "); 74 List<Node> wayNodes = new ArrayList<>(); 75 wayNodes.add(nodes.get(0)); 76 wayNodes.add(nodes.get(1)); 77 wayNodes.add(nodes.get(2)); 78 wayNodes.add(nodes.get(0)); // problem 79 wayNodes.add(nodes.get(3)); 80 wayNodes.add(nodes.get(4)); 81 w.setNodes(wayNodes); 82 SelfIntersectingWay test = new SelfIntersectingWay(); 83 test.visit(w); 84 Assert.assertEquals(0, test.getErrors().size()); 85 } 86 87 /** 88 * Last node is identical to an inner node ("b"Shape). 89 * This is considered okay. 90 */ 91 @Test 92 public void TestUnclosedWayLast() { 93 List<Node> nodes = createNodes(); 94 95 Way w = (Way) OsmUtils.createPrimitive("way "); 96 List<Node> wayNodes = new ArrayList<>(); 97 wayNodes.add(nodes.get(0)); 98 wayNodes.add(nodes.get(1)); // problem node 99 wayNodes.add(nodes.get(2)); 100 wayNodes.add(nodes.get(3)); 101 wayNodes.add(nodes.get(4)); 102 wayNodes.add(nodes.get(1)); 103 w.setNodes(wayNodes); 104 SelfIntersectingWay test = new SelfIntersectingWay(); 105 test.visit(w); 106 Assert.assertEquals(0, test.getErrors().size()); 107 } 108 109 /** 110 * Both endpoints join at one inner node ("8"shape). 111 * This is considered okay. 112 */ 113 @Test 114 public void TestClosedWay() { 115 List<Node> nodes = createNodes(); 116 117 Way w = (Way) OsmUtils.createPrimitive("way "); 118 List<Node> wayNodes = new ArrayList<>(); 119 wayNodes.add(nodes.get(0)); 120 wayNodes.add(nodes.get(1)); 121 wayNodes.add(nodes.get(2)); 122 wayNodes.add(nodes.get(0)); // problem 123 wayNodes.add(nodes.get(3)); 124 wayNodes.add(nodes.get(4)); 125 wayNodes.add(nodes.get(0)); 126 w.setNodes(wayNodes); 127 SelfIntersectingWay test = new SelfIntersectingWay(); 128 test.visit(w); 129 Assert.assertEquals(0, test.getErrors().size()); 130 } 131 133 132 }
Note: See TracChangeset
for help on using the changeset viewer.