source: josm/trunk/src/org/openstreetmap/josm/data/Bounds.java@ 1814

Last change on this file since 1814 was 1724, checked in by stoecker, 15 years ago

some more changes and bug fixes related to new projection stuff - GPX should now work also

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data;
3
4import java.awt.geom.Rectangle2D;
5
6import org.openstreetmap.josm.data.coor.LatLon;
7import org.openstreetmap.josm.data.projection.Projection;
8
9/**
10 * This is a simple data class for "rectangular" areas of the world, given in
11 * lat/lon min/max values.
12 *
13 * @author imi
14 */
15public class Bounds {
16 /**
17 * The minimum and maximum coordinates.
18 */
19 public LatLon min, max;
20
21 /**
22 * Construct bounds out of two points
23 */
24 public Bounds(LatLon min, LatLon max) {
25 this.min = min;
26 this.max = max;
27 }
28
29 public Bounds(LatLon b) {
30 this.min = b;
31 this.max = b;
32 }
33
34 @Override public String toString() {
35 return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]";
36 }
37
38 /**
39 * @return Center of the bounding box.
40 */
41 public LatLon getCenter()
42 {
43 return min.getCenter(max);
44 }
45
46 /**
47 * Extend the bounds if necessary to include the given point.
48 */
49 public void extend(LatLon ll) {
50 if (ll.lat() < min.lat() || ll.lon() < min.lon())
51 min = new LatLon(Math.min(ll.lat(), min.lat()), Math.min(ll.lon(), min.lon()));
52 if (ll.lat() > max.lat() || ll.lon() > max.lon())
53 max = new LatLon(Math.max(ll.lat(), max.lat()), Math.max(ll.lon(), max.lon()));
54 }
55 /**
56 * Is the given point within this bounds?
57 */
58 public boolean contains(LatLon ll) {
59 if (ll.lat() < min.lat() || ll.lon() < min.lon())
60 return false;
61 if (ll.lat() > max.lat() || ll.lon() > max.lon())
62 return false;
63 return true;
64 }
65
66 /**
67 * Converts the lat/lon bounding box to an object of type Rectangle2D.Double
68 * @return the bounding box to Rectangle2D.Double
69 */
70 public Rectangle2D.Double asRect() {
71 return new Rectangle2D.Double(min.lon(), min.lat(), max.lon()-min.lon(), max.lat()-min.lat());
72 }
73
74}
Note: See TracBrowser for help on using the repository browser.