source: josm/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java@ 73

Last change on this file since 73 was 73, checked in by imi, 18 years ago

fixed bug where lat/lon was exchanged in download dialog and quick fix for Java6 - gui problem

File size: 1.5 KB
Line 
1package org.openstreetmap.josm.data.osm.visitor;
2
3import org.openstreetmap.josm.Main;
4import org.openstreetmap.josm.data.Bounds;
5import org.openstreetmap.josm.data.coor.EastNorth;
6import org.openstreetmap.josm.data.osm.LineSegment;
7import org.openstreetmap.josm.data.osm.Node;
8import org.openstreetmap.josm.data.osm.Way;
9
10/**
11 * Calculates the total bounding rectangle of a serie of OsmPrimitives, using the EastNorth values
12 * as reference.
13 * @author imi
14 */
15public class BoundingXYVisitor implements Visitor {
16
17 public EastNorth min, max;
18
19 public void visit(Node n) {
20 visit(n.eastNorth);
21 }
22
23 public void visit(LineSegment ls) {
24 if (!ls.incomplete) {
25 visit(ls.from);
26 visit(ls.to);
27 }
28 }
29
30 public void visit(Way t) {
31 for (LineSegment ls : t.segments)
32 visit(ls);
33 }
34
35 public void visit(EastNorth eastNorth) {
36 if (eastNorth != null) {
37 if (min == null)
38 min = eastNorth;
39 else if (eastNorth.east() < min.east() || eastNorth.north() < min.north())
40 min = new EastNorth(Math.min(min.east(), eastNorth.east()), Math.min(min.north(), eastNorth.north()));
41
42 if (max == null)
43 max = eastNorth;
44 else if (eastNorth.east() > max.east() || eastNorth.north() > max.north())
45 max = new EastNorth(Math.max(max.east(), eastNorth.east()), Math.max(max.north(), eastNorth.north()));
46 }
47 }
48
49 /**
50 * @return The bounding box or <code>null</code> if no coordinates have passed
51 */
52 public Bounds getBounds() {
53 if (min == null || max == null)
54 return null;
55 return new Bounds(Main.proj.eastNorth2latlon(min), Main.proj.eastNorth2latlon(max));
56 }
57}
Note: See TracBrowser for help on using the repository browser.