source: josm/branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java@ 329

Last change on this file since 329 was 329, checked in by framm, 17 years ago

This commit is a manual merge of all changes that have been made to
the intermediate "core_0.5" branch on the main OSM repository,
bevore JOSM was moved to openstreetmap.de.

Changes incorporated here:

r4464@svn.openstreetmap.org
r4466@svn.openstreetmap.org
r4468@svn.openstreetmap.org
r4469@svn.openstreetmap.org
r4479@svn.openstreetmap.org

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