Changeset 4162 in osm for applications/editors
- Timestamp:
- 2007-08-16T02:39:09+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r4093 r4162 83 83 newFrame.addToggleDialog(validationDialog); 84 84 Main.main.addLayer(new ErrorLayer(tr("Validation errors"))); 85 if( Main.pref.hasKey(PreferenceEditor.PREF_DEBUG + ".grid") ) 86 Main.main.addLayer(new GridLayer(tr("Grid"))); 85 87 Layer.listeners.add(this); 86 88 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/PreferenceEditor.java
r4087 r4162 26 26 /** The preferences prefix */ 27 27 public static final String PREFIX = "validator"; 28 28 29 /** The preferences key for debug preferences */ 30 public static final String PREF_DEBUG = PREFIX + ".debug"; 31 29 32 /** The preferences key for enabled tests */ 30 33 public static final String PREF_TESTS = PREFIX + ".tests"; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/CrossingSegments.java
r3260 r4162 10 10 import org.openstreetmap.josm.plugins.validator.*; 11 11 import org.openstreetmap.josm.plugins.validator.util.Bag; 12 import org.openstreetmap.josm.plugins.validator.util.Util; 12 13 13 14 /** … … 53 54 return; 54 55 55 if( w.get("highway") == null && w.get("waterway") == null && w.get("railway") == null ) 56 String coastline1 = w.get("natural"); 57 boolean isCoastline1 = coastline1 != null && (coastline1.equals("water") || coastline1.equals("coastline")); 58 String railway1 = w.get("railway"); 59 boolean isSubway1 = railway1 != null && railway1.equals("subway"); 60 if( w.get("highway") == null && w.get("waterway") == null && !isSubway1 && !isCoastline1) 56 61 return; 57 62 58 63 String layer1 = w.get("layer"); 59 String railway1 = w.get("railway");60 64 for(Segment s : w.segments) 61 65 { … … 63 67 continue; 64 68 65 ExtendedSegment es1 = new ExtendedSegment(s, layer1, railway1 );69 ExtendedSegment es1 = new ExtendedSegment(s, layer1, railway1, coastline1); 66 70 List<List<ExtendedSegment>> cellSegments = getSegments(s); 67 71 for( List<ExtendedSegment> segments : cellSegments) … … 74 78 String layer2 = es2.layer; 75 79 String railway2 = es2.railway; 76 if( (layer1 == null && layer2 == null || layer1 != null && layer1.equals(layer2)) && 77 !("subway".equals(railway1) && "subway".equals(railway2)) && 78 es1.intersects(es2)) 79 { 80 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 81 primitives.add(es1.s); 82 primitives.add(es2.s); 83 errors.add( new TestError(this, Severity.WARNING, tr("Crossing roads"), primitives) ); 84 } 80 String coastline2 = es2.coastline; 81 if( (layer1 != null || layer2 != null) && (layer1 == null || !layer1.equals(layer2)) ) 82 continue; 83 84 if( !es1.intersects(es2) ) continue; 85 if( isSubway1 && "subway".equals(railway2)) continue; 86 87 boolean isCoastline2 = coastline2 != null && (coastline2.equals("water") || coastline2.equals("coastline")); 88 if( isCoastline1 != isCoastline2 ) continue; 89 90 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 91 primitives.add(es1.s); 92 primitives.add(es2.s); 93 errors.add( new TestError(this, Severity.WARNING, tr("Crossing roads"), primitives) ); 85 94 } 86 95 segments.add(es1); … … 92 101 * Returns all the cells this segment crosses . Each cell contains the list 93 102 * of segments already processed 94 * <p>95 * This method uses the Bresenham algorithm to follow all cells this segment96 * crosses, so, in very few cases (when the segment is very long, and97 * crosses a cell very close to the corner), it can miss a cell.98 103 * 99 104 * @param s The segment … … 103 108 { 104 109 List<List<ExtendedSegment>> cells = new ArrayList<List<ExtendedSegment>>(); 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 ); 110 for( Point2D cell : Util.getSegmentCells(s, 10000) ) 111 { 112 List<ExtendedSegment> segments = cellSegments.get( cell ); 132 113 if( segments == null ) 133 114 { 134 115 segments = new ArrayList<ExtendedSegment>(); 135 cellSegments.put( p, segments);116 cellSegments.put(cell, segments); 136 117 } 137 118 cells.add(segments); 138 139 error += dy;140 if( error > 0 )141 {142 error -= dx;143 y += ystep;144 }145 119 } 146 120 … … 162 136 /** The railway type */ 163 137 private String railway; 138 139 /** The coastline type */ 140 private String coastline; 164 141 165 142 /** … … 168 145 * @param layer The layer of the way this segment is in 169 146 * @param railway The railway type of the way this segment is in 147 * @param coastline The coastlyne typo of the way the segment is in 170 148 */ 171 public ExtendedSegment(Segment s, String layer, String railway )149 public ExtendedSegment(Segment s, String layer, String railway, String coastline) 172 150 { 173 151 this.s = s; 174 152 this.layer = layer; 175 153 this.railway = railway; 154 this.coastline = coastline; 176 155 } 177 156 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/Util.java
r4122 r4162 261 261 262 262 // First, round coordinates 263 long x0 = Math.round(start.from.eastNorth.east() * 10000 0);264 long y0 = Math.round(start.from.eastNorth.north() * 10000 0);265 long x1 = Math.round(end.to.eastNorth.east() * 10000 0);266 long y1 = Math.round(end.to.eastNorth.north() * 10000 0);263 long x0 = Math.round(start.from.eastNorth.east() * 10000); 264 long y0 = Math.round(start.from.eastNorth.north() * 10000); 265 long x1 = Math.round(end.to.eastNorth.east() * 10000); 266 long y1 = Math.round(end.to.eastNorth.north() * 10000); 267 267 268 268 // Start of the way … … 292 292 293 293 // Then floor coordinates, in case the way is in the border of the cell. 294 x0 = (long)Math.floor(start.from.eastNorth.east() * 10000 0);295 y0 = (long)Math.floor(start.from.eastNorth.north() * 10000 0);296 x1 = (long)Math.floor(end.to.eastNorth.east() * 10000 0);297 y1 = (long)Math.floor(end.to.eastNorth.north() * 10000 0);294 x0 = (long)Math.floor(start.from.eastNorth.east() * 10000); 295 y0 = (long)Math.floor(start.from.eastNorth.north() * 10000); 296 x1 = (long)Math.floor(end.to.eastNorth.east() * 10000); 297 y1 = (long)Math.floor(end.to.eastNorth.north() * 10000); 298 298 299 299 // Start of the way … … 327 327 return cells; 328 328 } 329 330 /** 331 * Returns the coordinates of all cells in a grid that a segment goes through. 332 * 333 * @param s The segment 334 * @param gridDetail The detail of the grid. Bigger values give smaller cells, but a bigger number of them. 335 * @return A list with the coordinates of all cells 336 */ 337 public static List<Point2D> getSegmentCells(Segment s, int gridDetail) 338 { 339 List<Point2D> cells = new ArrayList<Point2D>(); 340 double x0 = s.from.eastNorth.east() * gridDetail; 341 double x1 = s.to.eastNorth.east() * gridDetail; 342 double y0 = s.from.eastNorth.north()* gridDetail + 1; 343 double y1 = s.to.eastNorth.north() * gridDetail + 1; 344 345 if( x0 > x1 ) 346 { 347 // Move to 1st-4th cuadrants 348 double aux; 349 aux = x0; x0 = x1; x1 = aux; 350 aux = y0; y0 = y1; y1 = aux; 351 } 352 353 double dx = x1 - x0; 354 double dy = y1 - y0; 355 long stepY = y0 <= y1 ? 1 : -1; 356 long gridX0 = (long)Math.floor(x0); 357 long gridX1 = (long)Math.floor(x1); 358 long gridY0 = (long)Math.floor(y0); 359 long gridY1 = (long)Math.floor(y1); 360 361 long maxSteps = (gridX1 - gridX0) + Math.abs(gridY1 - gridY0) + 1; 362 while( (gridX0 <= gridX1 && (gridY0 - gridY1)*stepY <= 0) && maxSteps-- > 0) 363 { 364 cells.add( new Point2D.Double(gridX0, gridY0) ); 365 366 // Is the cross between the segment and next vertical line nearer than the cross with next horizontal line? 367 // Note: segment line formula: y=dy/dx(x-x1)+y1 368 // Note: if dy < 0, must use *bottom* line. If dy > 0, must use upper line 369 double scanY = dy/dx * (gridX0 + 1 - x1) + y1 + (dy < 0 ? -1 : 0); 370 double scanX = dx/dy * (gridY0 + (dy < 0 ? 0 : 1)*stepY - y1) + x1; 371 372 double distX = Math.pow(gridX0 + 1 - x0, 2) + Math.pow(scanY - y0, 2); 373 double distY = Math.pow(scanX - x0, 2) + Math.pow(gridY0 + stepY - y0, 2); 374 375 if( distX < distY) 376 gridX0 += 1; 377 else 378 gridY0 += stepY; 379 } 380 381 return cells; 382 } 329 383 }
Note:
See TracChangeset
for help on using the changeset viewer.