Ticket #8987: coords.diff
File coords.diff, 13.7 KB (added by , 11 years ago) |
---|
-
src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
683 683 Point p3 = mv.getPoint(newN1en); 684 684 Point p4 = mv.getPoint(newN2en); 685 685 686 EastNorthnormalUnitVector = getNormalUniVector();686 Point2D normalUnitVector = getNormalUniVector(); 687 687 688 688 if (mode == Mode.extrude || mode == Mode.create_new) { 689 689 g2.setColor(mainColor); … … 752 752 } 753 753 } 754 754 755 private EastNorthgetNormalUniVector() {756 double fac = 1.0 / activeMoveDirection.en. distance(0,0);755 private Point2D getNormalUniVector() { 756 double fac = 1.0 / activeMoveDirection.en.length(); 757 757 // mult by factor to get unit vector. 758 EastNorth normalUnitVector = new EastNorth(activeMoveDirection.en.getX() * fac, activeMoveDirection.en.getY() * fac);758 Point2D normalUnitVector = new Point2D.Double(activeMoveDirection.en.getX() * fac, activeMoveDirection.en.getY() * fac); 759 759 760 760 // Check to see if our new N1 is in a positive direction with respect to the normalUnitVector. 761 761 // Even if the x component is zero, we should still be able to discern using +0.0 and -0.0 762 762 if (newN1en != null && ((newN1en.getX() > initialN1en.getX()) != (normalUnitVector.getX() > -0.0))) { 763 763 // If not, use a sign-flipped version of the normalUnitVector. 764 normalUnitVector = new EastNorth(-normalUnitVector.getX(), -normalUnitVector.getY());764 normalUnitVector = new Point2D.Double(-normalUnitVector.getX(), -normalUnitVector.getY()); 765 765 } 766 766 767 767 //HACK: swap Y, because the target pixels are top down, but EastNorth is bottom-up. … … 770 770 return normalUnitVector; 771 771 } 772 772 773 private void drawAngleSymbol(Graphics2D g2, Point2D center, EastNorthnormal, boolean mirror) {773 private void drawAngleSymbol(Graphics2D g2, Point2D center, Point2D normal, boolean mirror) { 774 774 // EastNorth units per pixel 775 775 double factor = 1.0/g2.getTransform().getScaleX(); 776 776 double raoffsetx = symbolSize*factor*normal.getX(); -
src/org/openstreetmap/josm/command/Command.java
15 15 import javax.swing.JPanel; 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.coor.LatLon;19 18 import org.openstreetmap.josm.data.osm.Node; 20 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 20 import org.openstreetmap.josm.data.osm.PrimitiveData; … … 221 220 222 221 private static boolean isOutlying(OsmPrimitive osm, Area area) { 223 222 if (osm instanceof Node && !osm.isNewOrUndeleted()) { 224 LatLon coor = ((Node) osm).getCoor(); 225 return coor != null && !area.contains(coor); 223 return !((Node) osm).getCoor().isIn(area); 226 224 } else if (osm instanceof Way) { 227 225 for (Node n : ((Way) osm).getNodes()) { 228 226 if (isOutlying(n, area)) { -
src/org/openstreetmap/josm/command/SequenceCommand.java
6 6 import java.util.Arrays; 7 7 import java.util.Collection; 8 8 import java.util.HashSet; 9 import java.util.List;10 9 11 10 import javax.swing.Icon; 12 11 -
src/org/openstreetmap/josm/data/Bounds.java
205 205 if (crosses180thMeridian()) { 206 206 LatLon result = new LatLon(minLat, minLon-360.0).getCenter(getMax()); 207 207 if (result.lon() < -180.0) { 208 result .setLocation(result.lon()+360.0, result.lat());208 result = new LatLon(result.lat(), result.lon() + 360.0); 209 209 } 210 210 return result; 211 211 } else { -
src/org/openstreetmap/josm/data/coor/CachedLatLon.java
32 32 this.eastNorth = eastNorth; 33 33 } 34 34 35 public final void setCoor(LatLon coor) {36 setLocation(coor.lon(), coor.lat());37 proj = null;38 }39 40 public final void setEastNorth(EastNorth eastNorth) {41 proj = Main.getProjection();42 this.eastNorth = eastNorth;43 LatLon l = proj.eastNorth2latlon(eastNorth);44 setLocation(l.lon(), l.lat());45 }46 47 35 /** 48 36 * Replies the projected east/north coordinates. 49 37 * -
src/org/openstreetmap/josm/data/coor/Coordinate.java
1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.data.coor; 3 3 4 import java.awt.geom.Point2D;5 4 import java.io.Serializable; 6 5 7 6 /** … … 16 15 * 17 16 * @author imi 18 17 */ 19 abstract class Coordinate extends Point2Dimplements Serializable {18 abstract class Coordinate implements Serializable { 20 19 21 protected double x;22 protected double y;20 protected final double x; 21 protected final double y; 23 22 24 23 /** 25 24 * Construct the point with latitude / longitude values. … … 31 30 this.x = x; this.y = y; 32 31 } 33 32 34 @Override35 33 public double getX() { 36 34 return x; 37 35 } 38 36 39 @Override40 37 public double getY() { 41 38 return y; 42 39 } 43 40 44 41 @Override 45 public void setLocation (double x, double y) {46 this.x = x;47 this.y = y;48 }49 50 @Override51 42 public int hashCode() { 52 43 final int prime = 31; 53 44 int result = super.hashCode(); -
src/org/openstreetmap/josm/data/coor/EastNorth.java
43 43 return new EastNorth((this.x + en2.x)/2.0, (this.y + en2.y)/2.0); 44 44 } 45 45 46 public double distance(EastNorth en2) { 47 return Math.sqrt((this.x-en2.x)*(this.x-en2.x) + (this.y-en2.y)*(this.y-en2.y)); 46 /** 47 * Counts euclidean distance between this and other EastNorth. 48 * 49 * @param en2 other EastNorth 50 * @return distance between this and other EastNorth 51 */ 52 public double distance(final EastNorth en2) { 53 final double dx = this.x-en2.x; 54 final double dy = this.y-en2.y; 55 return Math.sqrt(dx*dx + dy*dy); 48 56 } 49 57 50 58 /** 59 * Counts square of euclidean distance between this and other EastNorth. 60 * 61 * @param en2 other EastNorth 62 * @return square of distance between this and other EastNorth 63 */ 64 public double distanceSq(final EastNorth en2) { 65 final double dx = this.x-en2.x; 66 final double dy = this.y-en2.y; 67 return dx*dx + dy*dy; 68 } 69 70 /** 71 * Counts length (distance from [0,0]) of this. 72 * 73 * @return length of this 74 */ 75 public double length(){ 76 return Math.sqrt(x*x + y*y); 77 } 78 79 /** 51 80 * Returns the heading, in radians, that you have to use to get from 52 81 * this EastNorth to another. Heading is mapped into [0, 2pi) 53 82 * -
src/org/openstreetmap/josm/data/coor/LatLon.java
10 10 import static java.lang.Math.toRadians; 11 11 import static org.openstreetmap.josm.tools.I18n.trc; 12 12 13 import java.awt.geom.Area; 13 14 import java.text.DecimalFormat; 14 15 import java.text.NumberFormat; 15 16 import java.util.Locale; … … 221 222 } 222 223 223 224 /** 225 * Check if this is contained in given area or area is null. 226 * 227 * @param a Area 228 * @return <code>true</code> if this is contained in given area or area is null. 229 */ 230 public boolean isIn(Area a) { 231 return a == null || a.contains(x, y); 232 } 233 234 /** 224 235 * Computes the distance between this lat/lon and another point on the earth. 225 236 * Uses Haversine formular. 226 237 * @param other the other point. … … 285 296 return new LatLon((this.lat() + ll2.lat())/2.0, (this.lon() + ll2.lon())/2.0); 286 297 } 287 298 299 /** 300 * Counts euclidean distance between this and other LatLon. 301 * 302 * @param ll2 other LatLon 303 * @return distance between this and other LatLon 304 */ 305 public double distance(final LatLon ll2) { 306 final double dx = this.x-ll2.x; 307 final double dy = this.y-ll2.y; 308 return Math.sqrt(dx*dx + dy*dy); 309 } 310 288 311 @Override public String toString() { 289 312 return "LatLon[lat="+lat()+",lon="+lon()+"]"; 290 313 } -
src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
1341 1341 Path2D.Double path = new Path2D.Double(); 1342 1342 boolean initial = true; 1343 1343 for (Node n : w.getNodes()) { 1344 Point2Dp = n.getEastNorth();1344 EastNorth p = n.getEastNorth(); 1345 1345 if (p != null) { 1346 1346 if (initial) { 1347 1347 path.moveTo(p.getX(), p.getY()); -
src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java
17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 19 19 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 20 import org.openstreetmap.josm.data.coor.EastNorth; 20 21 import org.openstreetmap.josm.data.osm.DataSet; 21 22 import org.openstreetmap.josm.data.osm.Node; 22 23 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 212 213 private void buildPoly() { 213 214 boolean initial = true; 214 215 for (Node n : nodes) { 215 Point2Dp = n.getEastNorth();216 EastNorth p = n.getEastNorth(); 216 217 if (p != null) { 217 218 if (initial) { 218 219 poly.moveTo(p.getX(), p.getY()); -
src/org/openstreetmap/josm/data/validation/tests/Coastlines.java
149 149 if (headWays == 0 || tailWays == 0) { 150 150 List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>(); 151 151 152 if (headWays == 0 && (downloadedArea == null || downloadedArea.contains(head.getCoor()))) {152 if (headWays == 0 && head.getCoor().isIn(downloadedArea)) { 153 153 highlight.add(head); 154 154 } 155 if (tailWays == 0 && (downloadedArea == null || downloadedArea.contains(tail.getCoor()))) {155 if (tailWays == 0 && tail.getCoor().isIn(downloadedArea)) { 156 156 highlight.add(tail); 157 157 } 158 158 -
src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
292 292 found_nodes.addAll(endnodes.search(new BBox(bounds.get(0), bounds.get(1)))); 293 293 294 294 for (Node n : found_nodes) { 295 if (!nearby(n, dist) || 296 (ds_area != null && !ds_area.contains(n.getCoor()))) { 295 if (!nearby(n, dist) || !n.getCoor().isIn(ds_area)) { 297 296 continue; 298 297 } 299 298 // It is actually very rare for us to find a node -
src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
340 340 } 341 341 342 342 public final void setCoor(LatLon coor) { 343 if(this.coor == null) { 344 this.coor = new CachedLatLon(coor); 345 } else { 346 this.coor.setCoor(coor); 347 } 343 this.coor = new CachedLatLon(coor); 348 344 } 349 345 350 346 public final LatLon getCoor() { … … 352 348 } 353 349 354 350 public final void setEastNorth(EastNorth eastNorth) { 355 coor.setEastNorth(eastNorth);351 this.coor = new CachedLatLon(eastNorth); 356 352 } 357 353 358 354 public final EastNorth getEastNorth() {