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

Last change on this file since 159 was 159, checked in by imi, 18 years ago
  • moved translations into plugins
  • added main menu control to main
  • added ImageProvider access to plugins
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.Segment;
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
12 * EastNorth values 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(Segment ls) {
24 if (!ls.incomplete) {
25 visit(ls.from);
26 visit(ls.to);
27 }
28 }
29
30 public void visit(Way w) {
31 for (Segment ls : w.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.