source: josm/trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java@ 6162

Last change on this file since 6162 was 6162, checked in by bastiK, 11 years ago

applied #8987 - immutable coordinates (patch by shinigami)

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.coor;
3
4import org.openstreetmap.josm.Main;
5import org.openstreetmap.josm.data.projection.Projection;
6
7/**
8 * LatLon class that maintains a cache of projected EastNorth coordinates.
9 *
10 * This class is convenient to use, but has relatively high memory costs.
11 * It keeps a pointer to the last known projection in order to detect projection
12 * changes.
13 *
14 * Node and WayPoint have another, optimized, cache for projected coordinates.
15 */
16public class CachedLatLon extends LatLon {
17 private EastNorth eastNorth;
18 private Projection proj;
19
20 public CachedLatLon(double lat, double lon) {
21 super(lat, lon);
22 }
23
24 public CachedLatLon(LatLon coor) {
25 super(coor.lat(), coor.lon());
26 proj = null;
27 }
28
29 public CachedLatLon(EastNorth eastNorth) {
30 super(Main.getProjection().eastNorth2latlon(eastNorth));
31 proj = Main.getProjection();
32 this.eastNorth = eastNorth;
33 }
34
35 /**
36 * Replies the projected east/north coordinates.
37 *
38 * @return the internally cached east/north coordinates. null, if the globally defined projection is null
39 */
40 public final EastNorth getEastNorth() {
41 if(proj != Main.getProjection())
42 {
43 proj = Main.getProjection();
44 eastNorth = proj.latlon2eastNorth(this);
45 }
46 return eastNorth;
47 }
48 @Override public String toString() {
49 return "CachedLatLon[lat="+lat()+",lon="+lon()+"]";
50 }
51
52 // Only for Node.get3892DebugInfo()
53 public Projection getProjection() {
54 return proj;
55 }
56}
Note: See TracBrowser for help on using the repository browser.