Changeset 3260 in osm for applications/editors
- Timestamp:
- 2007-06-18T21:53:37+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/CrossingSegments.java
r3038 r3260 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Point;6 5 import java.awt.geom.Line2D; 7 6 import java.awt.geom.Point2D; 8 7 import java.util.*; 9 8 10 import org.openstreetmap.josm.data.coor.EastNorth;11 import org.openstreetmap.josm.data.coor.LatLon;12 9 import org.openstreetmap.josm.data.osm.*; 13 import org.openstreetmap.josm.plugins.validator.Severity; 14 import org.openstreetmap.josm.plugins.validator.Test; 15 import org.openstreetmap.josm.plugins.validator.TestError; 10 import org.openstreetmap.josm.plugins.validator.*; 11 import org.openstreetmap.josm.plugins.validator.util.Bag; 16 12 17 13 /** … … 24 20 /** All segments, grouped by cells */ 25 21 Map<Point2D,List<ExtendedSegment>> cellSegments; 22 /** The already detected errors */ 23 Bag<Segment, Segment> errorSegments; 26 24 27 25 /** … … 31 29 { 32 30 super(tr("Crossing roads."), 33 tr("This test checks if two roads crosses in the same layer, but are not connected by a node."));31 tr("This test checks if two roads,railways or waterways crosses in the same layer, but are not connected by a node.")); 34 32 } 35 33 … … 39 37 { 40 38 cellSegments = new HashMap<Point2D,List<ExtendedSegment>>(1000); 39 errorSegments = new Bag<Segment, Segment>(); 41 40 } 42 41 … … 45 44 { 46 45 cellSegments = null; 46 errorSegments = null; 47 47 } 48 48 … … 50 50 public void visit(Way w) 51 51 { 52 53 if( w.deleted || w.get("highway") == null) 52 if( w.deleted ) 54 53 return; 55 54 55 if( w.get("highway") == null && w.get("waterway") == null && w.get("railway") == null ) 56 return; 57 56 58 String layer1 = w.get("layer"); 59 String railway1 = w.get("railway"); 57 60 for(Segment s : w.segments) 58 61 { … … 60 63 continue; 61 64 62 ExtendedSegment es1 = new ExtendedSegment(s, layer1 );65 ExtendedSegment es1 = new ExtendedSegment(s, layer1, railway1); 63 66 List<List<ExtendedSegment>> cellSegments = getSegments(s); 64 67 for( List<ExtendedSegment> segments : cellSegments) … … 66 69 for( ExtendedSegment es2 : segments) 67 70 { 71 if( errorSegments.contains(s, es2.s) || errorSegments.contains(es2.s, s)) 72 continue; 73 68 74 String layer2 = es2.layer; 75 String railway2 = es2.railway; 69 76 if( (layer1 == null && layer2 == null || layer1 != null && layer1.equals(layer2)) && 77 !("subway".equals(railway1) && "subway".equals(railway2)) && 70 78 es1.intersects(es2)) 71 79 { … … 82 90 83 91 /** 84 * Returns all the cells this segment crosses . Each cell contains the list 85 * of segments already processed 86 * 87 * @param s 88 * The segment 89 * @return A list with all the cells the segment crosses. 90 */ 92 * Returns all the cells this segment crosses . Each cell contains the list 93 * of segments already processed 94 * <p> 95 * This method uses the Bresenham algorithm to follow all cells this segment 96 * crosses, so, in very few cases (when the segment is very long, and 97 * crosses a cell very close to the corner), it can miss a cell. 98 * 99 * @param s The segment 100 * @return A list with all the cells the segment crosses. 101 */ 91 102 public List<List<ExtendedSegment>> getSegments(Segment s) 92 103 { 93 104 List<List<ExtendedSegment>> cells = new ArrayList<List<ExtendedSegment>>(); 94 long x0 = Math.round(s.from.eastNorth.east()*100); 95 long x1 = Math.round(s.to.eastNorth.east()*100); 96 for( ; x0<=x1; x0++) 97 { 98 long y0 = Math.round(s.from.eastNorth.north()*100); 99 long y1 = Math.round(s.to.eastNorth.north()*100); 100 for( ; y0<=y1; y0++) 101 { 102 Point2D p = new Point2D.Double(x0, y0); 103 List<ExtendedSegment> segments = cellSegments.get( p ); 104 if( segments == null ) 105 { 106 segments = new ArrayList<ExtendedSegment>(); 107 cellSegments.put(p, segments); 108 } 109 110 cells.add(segments); 111 } 112 } 113 105 long x0 = Math.round(s.from.eastNorth.east() * 1000); 106 long x1 = Math.round(s.to.eastNorth.east() * 1000); 107 long y0 = Math.round(s.from.eastNorth.north()* 1000); 108 long y1 = Math.round(s.to.eastNorth.north() * 1000); 109 110 boolean steep = Math.abs(y1 - y0) > Math.abs(x1 - x0); 111 long aux; 112 if( steep ) 113 { 114 aux = x0; x0 = x1; x1 = aux; 115 aux = y0; y0 = y1; y1 = aux; 116 } 117 if( x0 > x1 ) 118 { 119 aux = x0; x0 = x1; x1 = aux; 120 aux = y0; y0 = y1; y1 = aux; 121 } 122 long dx = x1 - x0, 123 dy = Math.abs(y1 - y0), 124 y = y0, 125 error = -dx/2, 126 ystep = y0 < y1 ? 1 : -1; 127 128 for( long x = x0; x <= x1; x++ ) 129 { 130 Point2D p = steep ? new Point2D.Double(y, x) : new Point2D.Double(x, y); 131 List<ExtendedSegment> segments = cellSegments.get( p ); 132 if( segments == null ) 133 { 134 segments = new ArrayList<ExtendedSegment>(); 135 cellSegments.put(p, segments); 136 } 137 cells.add(segments); 138 139 error += dy; 140 if( error > 0 ) 141 { 142 error -= dx; 143 y += ystep; 144 } 145 } 146 114 147 return cells; 115 148 } … … 127 160 String layer; 128 161 162 /** The railway type */ 163 private String railway; 164 129 165 /** 130 166 * Constructor 131 167 * @param s The segment 132 168 * @param layer The layer of the way this segment is in 169 * @param railway The railway type of the way this segment is in 133 170 */ 134 public ExtendedSegment(Segment s, String layer )171 public ExtendedSegment(Segment s, String layer, String railway) 135 172 { 136 173 this.s = s; 137 174 this.layer = layer; 175 this.railway = railway; 138 176 } 139 177
Note:
See TracChangeset
for help on using the changeset viewer.