Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/data/Bounds.java
r14095 r14521 500 500 */ 501 501 public Rectangle2D.Double asRect() { 502 double w = getWidth(); 503 return new Rectangle2D.Double(minLon, minLat, w, maxLatminLat); 504 } 505 506 private double getWidth() { 502 return new Rectangle2D.Double(minLon, minLat, getWidth(), getHeight()); 503 } 504 505 /** 506 * Returns the bounds width. 507 * @return the bounds width 508 * @since 14521 509 */ 510 public double getHeight() { 511 return maxLatminLat; 512 } 513 514 /** 515 * Returns the bounds width. 516 * @return the bounds width 517 * @since 14521 518 */ 519 public double getWidth() { 507 520 return maxLonminLon + (crosses180thMeridian() ? 360.0 : 0.0); 508 521 } … … 513 526 */ 514 527 public double getArea() { 515 return getWidth() * (maxLat  minLat);528 return getWidth() * getHeight(); 516 529 } 517 530 
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r14273 r14521 840 840 BigDecimal east = BigDecimal.ZERO; 841 841 842 // See https://en.wikipedia.org/wiki/Centroid# Centroid_of_a_polygon for the equation used here842 // See https://en.wikipedia.org/wiki/Centroid#Of_a_polygon for the equation used here 843 843 for (int i = 0; i < size; i++) { 844 844 EastNorth n0 = nodes.get(i); 
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14519 r14521 13 13 import java.util.Set; 14 14 import java.util.TreeMap; 15 import java.util.stream.Collectors;16 15 17 16 import org.junit.Rule; 18 17 import org.junit.Test; 18 import org.openstreetmap.gui.jmapviewer.Coordinate; 19 19 import org.openstreetmap.gui.jmapviewer.TileXY; 20 20 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; … … 23 23 import org.openstreetmap.gui.jmapviewer.tilesources.ScanexTileSource; 24 24 import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource; 25 import org.openstreetmap.josm.data.Bounds; 25 26 import org.openstreetmap.josm.data.coor.LatLon; 26 27 import org.openstreetmap.josm.data.imagery.CoordinateConversion; … … 33 34 import org.openstreetmap.josm.data.imagery.WMTSTileSource; 34 35 import org.openstreetmap.josm.data.imagery.WMTSTileSource.WMTSGetCapabilitiesException; 35 import org.openstreetmap.josm.data.projection.Projection;36 36 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 37 37 import org.openstreetmap.josm.testutils.JOSMTestRules; 38 import org.openstreetmap.josm.tools.Geometry;39 38 import org.openstreetmap.josm.tools.HttpClient; 40 39 import org.openstreetmap.josm.tools.HttpClient.Response; … … 106 105 } 107 106 107 private static LatLon getPointInShape(Shape shape) { 108 final Coordinate p1 = shape.getPoints().get(0); 109 final Bounds bounds = new Bounds(p1.getLat(), p1.getLon(), p1.getLat(), p1.getLon()); 110 shape.getPoints().forEach(p > bounds.extend(p.getLat(), p.getLon())); 111 112 final double w = bounds.getWidth(); 113 final double h = bounds.getHeight(); 114 115 final double x2 = bounds.getMinLon() + (w / 2.0); 116 final double y2 = bounds.getMinLat() + (h / 2.0); 117 118 final LatLon center = new LatLon(y2, x2); 119 120 // check to see if center is inside shape 121 if (shape.contains(center)) { 122 return center; 123 } 124 125 // if center position (C) is not inside shape, try naively some other positions as follows: 126 final double x1 = bounds.getMinLon() + (.25 * w); 127 final double x3 = bounds.getMinLon() + (.75 * w); 128 final double y1 = bounds.getMinLat() + (.25 * h); 129 final double y3 = bounds.getMinLat() + (.75 * h); 130 // ++ 131 //  5 1 6  132 //  4 C 2  133 //  8 3 7  134 // ++ 135 for (LatLon candidate : new LatLon[] { 136 new LatLon(y1, x2), 137 new LatLon(y2, x3), 138 new LatLon(y3, x2), 139 new LatLon(y2, x1), 140 new LatLon(y1, x1), 141 new LatLon(y1, x3), 142 new LatLon(y3, x3), 143 new LatLon(y3, x1) 144 }) { 145 if (shape.contains(candidate)) { 146 return candidate; 147 } 148 } 149 return center; 150 } 151 108 152 private static LatLon getCenter(ImageryBounds bounds) { 109 153 List<Shape> shapes = bounds.getShapes(); 110 Projection proj = ProjectionRegistry.getProjection(); 111 return shapes != null && shapes.size() > 1 112 ? proj.eastNorth2latlon( 113 Geometry.getCentroidEN(shapes.get(0).getPoints().stream() 114 .map(CoordinateConversion::coorToLL) 115 .map(proj::latlon2eastNorth) 116 .collect(Collectors.toList()))) 117 : bounds.getCenter(); 154 return shapes != null && !shapes.isEmpty() ? getPointInShape(shapes.get(0)) : bounds.getCenter(); 118 155 } 119 156
Note: See TracChangeset
for help on using the changeset viewer.