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

Last change on this file since 2103 was 2017, checked in by Gubaer, 15 years ago

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

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