Changeset 10805 in josm for trunk/src/org/openstreetmap/josm/data/projection
 Timestamp:
 20160815T14:45:38+02:00 (4 years ago)
 Location:
 trunk/src/org/openstreetmap/josm/data/projection
 Files:

 2 added
 4 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java
r10699 r10805 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.projection; 3 4 import java.util.Collections; 5 import java.util.HashMap; 6 import java.util.Map; 7 import java.util.function.DoubleUnaryOperator; 3 8 4 9 import org.openstreetmap.josm.data.Bounds; … … 8 13 import org.openstreetmap.josm.data.projection.datum.Datum; 9 14 import org.openstreetmap.josm.data.projection.proj.Proj; 15 import org.openstreetmap.josm.tools.Utils; 10 16 11 17 /** … … 116 122 @Override 117 123 public LatLon eastNorth2latlon(EastNorth en) { 124 return eastNorth2latlon(en, LatLon::normalizeLon); 125 } 126 127 @Override 128 public LatLon eastNorth2latlonClamped(EastNorth en) { 129 LatLon ll = eastNorth2latlon(en, lon > Utils.clamp(lon, 180, 180)); 130 Bounds bounds = getWorldBoundsLatLon(); 131 return new LatLon(Utils.clamp(ll.lat(), bounds.getMinLat(), bounds.getMaxLat()), 132 Utils.clamp(ll.lon(), bounds.getMinLon(), bounds.getMaxLon())); 133 } 134 135 private LatLon eastNorth2latlon(EastNorth en, DoubleUnaryOperator normalizeLon) { 118 136 double[] latlonRad = proj.invproject((en.east() * toMeter  x0) / ellps.a / k0, (en.north() * toMeter  y0) / ellps.a / k0); 119 LatLon ll = new LatLon(Math.toDegrees(latlonRad[0]), LatLon.normalizeLon(Math.toDegrees(latlonRad[1]) + lon0 + pm)); 137 double lon = Math.toDegrees(latlonRad[1]) + lon0 + pm; 138 LatLon ll = new LatLon(Math.toDegrees(latlonRad[0]), normalizeLon.applyAsDouble(lon)); 120 139 return datum.toWGS84(ll); 140 } 141 142 @Override 143 public Map<ProjectionBounds, Projecting> getProjectingsForArea(ProjectionBounds area) { 144 if (proj.lonIsLinearToEast()) { 145 //FIXME: Respect datum? 146 // wrap the wrold around 147 Bounds bounds = getWorldBoundsLatLon(); 148 double minEast = latlon2eastNorth(bounds.getMin()).east(); 149 double maxEast = latlon2eastNorth(bounds.getMax()).east(); 150 double dEast = maxEast  minEast; 151 if ((area.minEast < minEast  area.maxEast > maxEast) && dEast > 0) { 152 // We could handle the dEast < 0 case but we don't need it atm. 153 int minChunk = (int) Math.floor((area.minEast  minEast) / dEast); 154 int maxChunk = (int) Math.floor((area.maxEast  minEast) / dEast); 155 HashMap<ProjectionBounds, Projecting> ret = new HashMap<>(); 156 for (int chunk = minChunk; chunk <= maxChunk; chunk++) { 157 ret.put(new ProjectionBounds(Math.max(area.minEast, minEast + chunk * dEast), area.minNorth, 158 Math.min(area.maxEast, maxEast + chunk * dEast), area.maxNorth), 159 new ShiftedProjecting(this, new EastNorth(chunk * dEast, 0))); 160 } 161 return ret; 162 } 163 } 164 165 return Collections.singletonMap(area, this); 121 166 } 122 167 … … 179 224 return projectionBoundsBox; 180 225 } 226 227 @Override 228 public Projection getBaseProjection() { 229 return this; 230 } 181 231 } 
trunk/src/org/openstreetmap/josm/data/projection/Projection.java
r10381 r10805 14 14 * factor and x/y offset. 15 15 */ 16 public interface Projection {16 public interface Projection extends Projecting { 17 17 /** 18 18 * The default scale factor in east/north units per pixel … … 22 22 */ 23 23 double getDefaultZoomInPPD(); 24 25 /**26 * Convert from lat/lon to easting/northing.27 *28 * @param ll the geographical point to convert (in WGS84 lat/lon)29 * @return the corresponding east/north coordinates30 */31 EastNorth latlon2eastNorth(LatLon ll);32 24 33 25 /** 
trunk/src/org/openstreetmap/josm/data/projection/proj/Mercator.java
r10378 r10805 120 120 return scaleFactor; 121 121 } 122 123 @Override 124 public boolean lonIsLinearToEast() { 125 return true; 126 } 122 127 } 
trunk/src/org/openstreetmap/josm/data/projection/proj/Proj.java
r10001 r10805 91 91 */ 92 92 boolean isGeographic(); 93 94 /** 95 * Checks wether the result of projecting a lon coordinate only has a linear relation to the east coordinate and 96 * is not related to lat/north at all. 97 * @return <code>true</code> if lon has a linear relationship to east only. 98 * @since 10805 99 */ 100 default boolean lonIsLinearToEast() { 101 return false; 102 } 93 103 }
Note: See TracChangeset
for help on using the changeset viewer.