-
diff --git a/src/org/openstreetmap/josm/actions/AddNodeAction.java b/src/org/openstreetmap/josm/actions/AddNodeAction.java
index 5cc050f..8130bf2 100644
a
|
b
|
public final class AddNodeAction extends JosmAction {
|
66 | 66 | Main.main.undoRedo.add(new AddCommand(nnew)); |
67 | 67 | getLayerManager().getEditDataSet().setSelected(nnew); |
68 | 68 | if (Main.map.mapView != null) { |
69 | | if (Main.map.mapView.getRealBounds().contains(nnew.getCoor())) { |
| 69 | if (Main.map.mapView.getRealBounds().contains(nnew)) { |
70 | 70 | Main.map.mapView.repaint(); |
71 | 71 | } else { |
72 | 72 | AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew)); |
-
diff --git a/src/org/openstreetmap/josm/actions/CopyCoordinatesAction.java b/src/org/openstreetmap/josm/actions/CopyCoordinatesAction.java
index f13f2db..e07dfa1 100644
a
|
b
|
public class CopyCoordinatesAction extends JosmAction {
|
30 | 30 | public void actionPerformed(ActionEvent ae) { |
31 | 31 | StringBuilder s = new StringBuilder(); |
32 | 32 | for (Node n : getSelectedNodes()) { |
33 | | s.append(n.getCoor().lat()); |
| 33 | s.append(n.lat()); |
34 | 34 | s.append(", "); |
35 | | s.append(n.getCoor().lon()); |
| 35 | s.append(n.lon()); |
36 | 36 | s.append('\n'); |
37 | 37 | } |
38 | 38 | ClipboardUtils.copyString(s.toString().trim()); |
-
diff --git a/src/org/openstreetmap/josm/actions/SimplifyWayAction.java b/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
index 8a979c3..c828c68 100644
a
|
b
|
public class SimplifyWayAction extends JosmAction {
|
227 | 227 | for (int i = from + 1; i < to; i++) { |
228 | 228 | Node n = wnew.get(i); |
229 | 229 | double xte = Math.abs(Ellipsoid.WGS84.a |
230 | | * xtd(fromN.getCoor().lat() * Math.PI / 180, fromN.getCoor().lon() * Math.PI / 180, toN.getCoor().lat() * Math.PI |
231 | | / 180, toN.getCoor().lon() * Math.PI / 180, n.getCoor().lat() * Math.PI / 180, n.getCoor().lon() * Math.PI |
232 | | / 180)); |
| 230 | * xtd(fromN.lat() * Math.PI / 180, fromN.lon() * Math.PI / 180, toN.lat() * Math.PI / 180, |
| 231 | toN.lon() * Math.PI / 180, n.lat() * Math.PI / 180, n.lon() * Math.PI / 180)); |
233 | 232 | if (xte > xtemax) { |
234 | 233 | xtemax = xte; |
235 | 234 | imax = i; |
-
diff --git a/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java b/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
index ca1ede9..7f3ba05 100644
a
|
b
|
public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPress
|
1062 | 1062 | } |
1063 | 1063 | } else if (mode == Mode.translate || mode == Mode.translate_node) { |
1064 | 1064 | g2.setColor(mainColor); |
1065 | | if (p1.distance(p2) < 3) { |
| 1065 | MapViewPath line = new MapViewPath(mv.getState()).moveTo(p1).lineTo(p2); |
| 1066 | if (line.getBounds2D().getWidth() < 3 && line.getBounds2D().getHeight() < 3) { |
1066 | 1067 | g2.setStroke(mainStroke); |
1067 | | g2.draw(new MapViewPath(mv.getState()).shapeAround(p1, SymbolShape.CIRCLE, symbolSize)); |
| 1068 | g2.draw(new MapViewPath(mv.getState()).shapeAround(p1.interpolate(p2, .5), SymbolShape.CIRCLE, symbolSize)); |
1068 | 1069 | } else { |
1069 | 1070 | g2.setStroke(oldLineStroke); |
1070 | | g2.draw(new MapViewPath(mv.getState()).moveTo(p1).lineTo(p2)); |
| 1071 | g2.draw(line); |
1071 | 1072 | } |
1072 | 1073 | |
1073 | 1074 | if (dualAlignActive) { |
-
diff --git a/src/org/openstreetmap/josm/data/Bounds.java b/src/org/openstreetmap/josm/data/Bounds.java
index 5cdbd0e..9c8c620 100644
a
|
b
|
import java.text.MessageFormat;
|
9 | 9 | import java.util.Objects; |
10 | 10 | import java.util.function.Consumer; |
11 | 11 | |
| 12 | import org.openstreetmap.josm.data.coor.ILatLon; |
12 | 13 | import org.openstreetmap.josm.data.coor.LatLon; |
13 | 14 | import org.openstreetmap.josm.data.osm.BBox; |
14 | 15 | import org.openstreetmap.josm.data.projection.Projection; |
… |
… |
public class Bounds {
|
345 | 346 | |
346 | 347 | /** |
347 | 348 | * Determines if the given point {@code ll} is within these bounds. |
| 349 | * <p> |
| 350 | * Points with unknown coordinates are always outside the coordinates. |
348 | 351 | * @param ll The lat/lon to check |
349 | 352 | * @return {@code true} if {@code ll} is within these bounds, {@code false} otherwise |
350 | 353 | */ |
351 | 354 | public boolean contains(LatLon ll) { |
| 355 | // binary compatibility |
| 356 | return contains((ILatLon) ll); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Determines if the given point {@code ll} is within these bounds. |
| 361 | * <p> |
| 362 | * Points with unknown coordinates are always outside the coordinates. |
| 363 | * @param ll The lat/lon to check |
| 364 | * @return {@code true} if {@code ll} is within these bounds, {@code false} otherwise |
| 365 | */ |
| 366 | public boolean contains(ILatLon ll) { |
| 367 | if (!ll.isLatLonKnown()) { |
| 368 | return false; |
| 369 | } |
352 | 370 | if (ll.lat() < minLat || ll.lat() > maxLat) |
353 | 371 | return false; |
354 | 372 | if (crosses180thMeridian()) { |
-
diff --git a/src/org/openstreetmap/josm/data/coor/CachedLatLon.java b/src/org/openstreetmap/josm/data/coor/CachedLatLon.java
index 12ee12b..36cc364 100644
a
|
b
|
package org.openstreetmap.josm.data.coor;
|
4 | 4 | import java.util.Objects; |
5 | 5 | |
6 | 6 | import org.openstreetmap.josm.Main; |
7 | | import org.openstreetmap.josm.data.projection.Projection; |
| 7 | import org.openstreetmap.josm.data.projection.Projecting; |
8 | 8 | |
9 | 9 | /** |
10 | 10 | * LatLon class that maintains a cache of projected EastNorth coordinates. |
… |
… |
public class CachedLatLon extends LatLon {
|
19 | 19 | private static final long serialVersionUID = 1L; |
20 | 20 | |
21 | 21 | private EastNorth eastNorth; |
22 | | private transient Projection proj; |
| 22 | private transient Object proj; |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Constructs a new {@code CachedLatLon}. |
… |
… |
public class CachedLatLon extends LatLon {
|
45 | 45 | */ |
46 | 46 | public CachedLatLon(EastNorth eastNorth) { |
47 | 47 | super(Main.getProjection().eastNorth2latlon(eastNorth)); |
48 | | proj = Main.getProjection(); |
| 48 | proj = Main.getProjection().getCacheKey(); |
49 | 49 | this.eastNorth = eastNorth; |
50 | 50 | } |
51 | 51 | |
… |
… |
public class CachedLatLon extends LatLon {
|
54 | 54 | * |
55 | 55 | * @return the internally cached east/north coordinates. null, if the globally defined projection is null |
56 | 56 | */ |
57 | | public final EastNorth getEastNorth() { |
58 | | if (!Objects.equals(proj, Main.getProjection())) { |
59 | | proj = Main.getProjection(); |
60 | | eastNorth = proj.latlon2eastNorth(this); |
| 57 | @Override |
| 58 | public final EastNorth getEastNorth(Projecting projecting) { |
| 59 | if (!Objects.equals(proj, projecting.getCacheKey())) { |
| 60 | proj = projecting.getCacheKey(); |
| 61 | eastNorth = projecting.latlon2eastNorth(this); |
61 | 62 | } |
62 | 63 | return eastNorth; |
63 | 64 | } |
-
diff --git a/src/org/openstreetmap/josm/data/coor/ILatLon.java b/src/org/openstreetmap/josm/data/coor/ILatLon.java
new file mode 100644
index 0000000..8447e68
-
|
+
|
|
| 1 | // License: GPL. For details, see LICENSE file. |
| 2 | package org.openstreetmap.josm.data.coor; |
| 3 | |
| 4 | import org.openstreetmap.josm.Main; |
| 5 | import org.openstreetmap.josm.data.projection.Projecting; |
| 6 | |
| 7 | /** |
| 8 | * This interface represents a coordinate in LatLon space. |
| 9 | * <p> |
| 10 | * It provides methods to get the coordinates. The coordinates may be unknown. |
| 11 | * In this case, both {@link #lat()} and {@link #lon()} need to return a NaN value and {@link #isLatLonKnown()} needs to return false. |
| 12 | * <p> |
| 13 | * Whether the coordinates are immutable or not is implementation specific. |
| 14 | * |
| 15 | * @author Michael Zangl |
| 16 | * @since xxx |
| 17 | */ |
| 18 | public interface ILatLon { |
| 19 | |
| 20 | /** |
| 21 | * Returns the longitude, i.e., the east-west position in degrees. |
| 22 | * @return the longitude or NaN if {@link #isLatLonKnown()} returns false |
| 23 | */ |
| 24 | public double lon(); |
| 25 | |
| 26 | /** |
| 27 | * Returns the latitude, i.e., the north-south position in degrees. |
| 28 | * @return the latitude or NaN if {@link #isLatLonKnown()} returns false |
| 29 | */ |
| 30 | public double lat(); |
| 31 | |
| 32 | /** |
| 33 | * Determines if this object has valid coordinates. |
| 34 | * @return {@code true} if this object has valid coordinates |
| 35 | */ |
| 36 | default boolean isLatLonKnown() { |
| 37 | return !Double.isNaN(lat()) && !Double.isNaN(lon()); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * <p>Replies the projected east/north coordinates.</p> |
| 42 | * |
| 43 | * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates.</p> |
| 44 | * |
| 45 | * @return the east north coordinates or {@code null} if #is |
| 46 | */ |
| 47 | default EastNorth getEastNorth() { |
| 48 | return getEastNorth(Main.getProjection()); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Replies the projected east/north coordinates. |
| 53 | * <p> |
| 54 | * The result of the last conversion is cached. The cache object is used as cache key. |
| 55 | * @param projecting The projection to use. |
| 56 | * @return The projected east/north coordinates |
| 57 | * @since 10827 |
| 58 | */ |
| 59 | default EastNorth getEastNorth(Projecting projecting) { |
| 60 | return projecting.latlon2eastNorth(this); |
| 61 | } |
| 62 | } |
-
diff --git a/src/org/openstreetmap/josm/data/coor/LatLon.java b/src/org/openstreetmap/josm/data/coor/LatLon.java
index 2a7e628..f6257e9 100644
a
|
b
|
import org.openstreetmap.josm.tools.Utils;
|
38 | 38 | * |
39 | 39 | * @author Imi |
40 | 40 | */ |
41 | | public class LatLon extends Coordinate { |
| 41 | public class LatLon extends Coordinate implements ILatLon { |
42 | 42 | |
43 | 43 | private static final long serialVersionUID = 1L; |
44 | 44 | |
… |
… |
public class LatLon extends Coordinate {
|
213 | 213 | super(lon, lat); |
214 | 214 | } |
215 | 215 | |
216 | | protected LatLon(LatLon coor) { |
| 216 | /** |
| 217 | * Creates a new LatLon object for the given coordinate |
| 218 | * @param coor The coordinates to copy from. |
| 219 | */ |
| 220 | public LatLon(ILatLon coor) { |
217 | 221 | super(coor.lon(), coor.lat()); |
218 | 222 | } |
219 | 223 | |
… |
… |
public class LatLon extends Coordinate {
|
225 | 229 | this(coor.getLat(), coor.getLon()); |
226 | 230 | } |
227 | 231 | |
228 | | /** |
229 | | * Returns the latitude, i.e., the north-south position in degrees. |
230 | | * @return the latitude |
231 | | */ |
| 232 | @Override |
232 | 233 | public double lat() { |
233 | 234 | return y; |
234 | 235 | } |
… |
… |
public class LatLon extends Coordinate {
|
251 | 252 | } |
252 | 253 | } |
253 | 254 | |
254 | | /** |
255 | | * Returns the longitude, i.e., the east-west position in degrees. |
256 | | * @return the longitude |
257 | | */ |
| 255 | @Override |
258 | 256 | public double lon() { |
259 | 257 | return x; |
260 | 258 | } |
-
diff --git a/src/org/openstreetmap/josm/data/osm/BBox.java b/src/org/openstreetmap/josm/data/osm/BBox.java
index a5c5d78..e4bafc9 100644
a
|
b
|
import java.awt.geom.Rectangle2D;
|
5 | 5 | import java.util.Arrays; |
6 | 6 | import java.util.Objects; |
7 | 7 | |
| 8 | import org.openstreetmap.josm.data.coor.ILatLon; |
8 | 9 | import org.openstreetmap.josm.data.coor.LatLon; |
9 | 10 | import org.openstreetmap.josm.data.coor.QuadTiling; |
10 | 11 | import org.openstreetmap.josm.tools.Utils; |
… |
… |
public class BBox {
|
75 | 76 | |
76 | 77 | public BBox(Way w) { |
77 | 78 | for (Node n : w.getNodes()) { |
78 | | LatLon coor = n.getCoor(); |
79 | | if (coor == null) { |
80 | | continue; |
81 | | } |
82 | | add(coor); |
| 79 | add(n); |
83 | 80 | } |
84 | 81 | } |
85 | 82 | |
86 | | public BBox(Node n) { |
87 | | LatLon coor = n.getCoor(); |
88 | | if (coor == null) { |
| 83 | public BBox(ILatLon n) { |
| 84 | if (!n.isLatLonKnown()) { |
89 | 85 | xmin = xmax = ymin = ymax = 0; |
90 | 86 | } else { |
91 | | xmin = xmax = coor.lon(); |
92 | | ymin = ymax = coor.lat(); |
| 87 | xmin = xmax = n.lon(); |
| 88 | ymin = ymax = n.lat(); |
93 | 89 | } |
94 | 90 | } |
95 | 91 | |
| 92 | public BBox(Node n) { |
| 93 | this((ILatLon) n); |
| 94 | } |
| 95 | |
96 | 96 | private void sanity() { |
97 | 97 | if (xmin < -180.0) { |
98 | 98 | xmin = -180.0; |
… |
… |
public class BBox {
|
112 | 112 | add(c.lon(), c.lat()); |
113 | 113 | } |
114 | 114 | |
| 115 | public final void add(ILatLon c) { |
| 116 | if (c.isLatLonKnown()) { |
| 117 | add(c.lon(), c.lat()); |
| 118 | } |
| 119 | } |
| 120 | |
115 | 121 | /** |
116 | 122 | * Extends this bbox to include the point (x, y) |
117 | 123 | * @param x X coordinate |
-
diff --git a/src/org/openstreetmap/josm/data/osm/INode.java b/src/org/openstreetmap/josm/data/osm/INode.java
index b9b43c5..02d7b8a 100644
a
|
b
|
|
2 | 2 | package org.openstreetmap.josm.data.osm; |
3 | 3 | |
4 | 4 | import org.openstreetmap.josm.data.coor.EastNorth; |
| 5 | import org.openstreetmap.josm.data.coor.ILatLon; |
5 | 6 | import org.openstreetmap.josm.data.coor.LatLon; |
6 | 7 | |
7 | 8 | /** |
8 | 9 | * INode captures the common functions of {@link Node} and {@link NodeData}. |
9 | 10 | * @since 4098 |
10 | 11 | */ |
11 | | public interface INode extends IPrimitive { |
| 12 | public interface INode extends IPrimitive, ILatLon { |
12 | 13 | |
13 | 14 | /** |
14 | 15 | * Returns lat/lon coordinates of this node. |
… |
… |
public interface INode extends IPrimitive {
|
23 | 24 | void setCoor(LatLon coor); |
24 | 25 | |
25 | 26 | /** |
26 | | * Returns east/north coordinates of this node. |
27 | | * @return east/north coordinates of this node |
28 | | */ |
29 | | EastNorth getEastNorth(); |
30 | | |
31 | | /** |
32 | 27 | * Sets east/north coordinates of this node. |
33 | 28 | * @param eastNorth east/north coordinates of this node |
34 | 29 | */ |
-
diff --git a/src/org/openstreetmap/josm/data/osm/Node.java b/src/org/openstreetmap/josm/data/osm/Node.java
index cb753f0..80e302e 100644
a
|
b
|
import org.openstreetmap.josm.data.coor.EastNorth;
|
12 | 12 | import org.openstreetmap.josm.data.coor.LatLon; |
13 | 13 | import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; |
14 | 14 | import org.openstreetmap.josm.data.osm.visitor.Visitor; |
15 | | import org.openstreetmap.josm.data.projection.Projection; |
| 15 | import org.openstreetmap.josm.data.projection.Projecting; |
16 | 16 | import org.openstreetmap.josm.data.projection.Projections; |
17 | 17 | import org.openstreetmap.josm.tools.CheckParameterUtil; |
18 | 18 | import org.openstreetmap.josm.tools.Utils; |
… |
… |
public final class Node extends OsmPrimitive implements INode {
|
45 | 45 | * @return {@code true} if this node has valid coordinates |
46 | 46 | * @since 7828 |
47 | 47 | */ |
| 48 | @Override |
48 | 49 | public boolean isLatLonKnown() { |
| 50 | // We cannot use default implementation - if we remove this implementation, we will break binary compatibility. |
49 | 51 | return !Double.isNaN(lat) && !Double.isNaN(lon); |
50 | 52 | } |
51 | 53 | |
… |
… |
public final class Node extends OsmPrimitive implements INode {
|
74 | 76 | |
75 | 77 | @Override |
76 | 78 | public LatLon getCoor() { |
77 | | if (!isLatLonKnown()) return null; |
78 | | return new LatLon(lat, lon); |
| 79 | if (!isLatLonKnown()) { |
| 80 | return null; |
| 81 | } else { |
| 82 | return new LatLon(lat, lon); |
| 83 | } |
79 | 84 | } |
80 | 85 | |
81 | | /** |
82 | | * <p>Replies the projected east/north coordinates.</p> |
83 | | * |
84 | | * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates. |
85 | | * Internally caches the projected coordinates.</p> |
86 | | * |
87 | | * <p>Replies {@code null} if this node doesn't know lat/lon-coordinates, i.e. because it is an incomplete node. |
88 | | * |
89 | | * @return the east north coordinates or {@code null} |
90 | | * @see #invalidateEastNorthCache() |
91 | | * |
92 | | */ |
93 | 86 | @Override |
94 | | public EastNorth getEastNorth() { |
95 | | return getEastNorth(Main.getProjection()); |
| 87 | public double lat() { |
| 88 | return lat; |
96 | 89 | } |
97 | 90 | |
98 | | /** |
99 | | * Replies the projected east/north coordinates. |
100 | | * <p> |
101 | | * The result of the last conversion is cached. The cache object is used as cache key. |
102 | | * @param projection The projection to use. |
103 | | * @return The projected east/north coordinates |
104 | | * @since 10827 |
105 | | */ |
106 | | public EastNorth getEastNorth(Projection projection) { |
| 91 | @Override |
| 92 | public double lon() { |
| 93 | return lon; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public EastNorth getEastNorth(Projecting projection) { |
107 | 98 | if (!isLatLonKnown()) return null; |
108 | 99 | |
109 | 100 | if (Double.isNaN(east) || Double.isNaN(north) || !Objects.equals(projection.getCacheKey(), eastNorthCacheKey)) { |
-
diff --git a/src/org/openstreetmap/josm/data/osm/NodeData.java b/src/org/openstreetmap/josm/data/osm/NodeData.java
index 650ab19..d3a0578 100644
a
|
b
|
public class NodeData extends PrimitiveData implements INode {
|
31 | 31 | setCoor(data.getCoor()); |
32 | 32 | } |
33 | 33 | |
34 | | private boolean isLatLonKnown() { |
| 34 | @Override |
| 35 | public double lat() { |
| 36 | return lat; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public double lon() { |
| 41 | return lon; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public boolean isLatLonKnown() { |
35 | 46 | return !Double.isNaN(lat) && !Double.isNaN(lon); |
36 | 47 | } |
37 | 48 | |
-
diff --git a/src/org/openstreetmap/josm/data/osm/NodePositionComparator.java b/src/org/openstreetmap/josm/data/osm/NodePositionComparator.java
index a6b0312..96aa69a 100644
a
|
b
|
public class NodePositionComparator implements Comparator<Node>, Serializable {
|
19 | 19 | if (n1.getCoor().equalsEpsilon(n2.getCoor())) |
20 | 20 | return 0; |
21 | 21 | |
22 | | int dLat = Double.compare(n1.getCoor().lat(), n2.getCoor().lat()); |
23 | | return dLat != 0 ? dLat : Double.compare(n1.getCoor().lon(), n2.getCoor().lon()); |
| 22 | int dLat = Double.compare(n1.lat(), n2.lat()); |
| 23 | return dLat != 0 ? dLat : Double.compare(n1.lon(), n2.lon()); |
24 | 24 | } |
25 | 25 | } |
-
diff --git a/src/org/openstreetmap/josm/data/projection/AbstractProjection.java b/src/org/openstreetmap/josm/data/projection/AbstractProjection.java
index 8129cbc..eeefb8a 100644
a
|
b
|
import java.util.function.DoubleUnaryOperator;
|
9 | 9 | import org.openstreetmap.josm.data.Bounds; |
10 | 10 | import org.openstreetmap.josm.data.ProjectionBounds; |
11 | 11 | import org.openstreetmap.josm.data.coor.EastNorth; |
| 12 | import org.openstreetmap.josm.data.coor.ILatLon; |
12 | 13 | import org.openstreetmap.josm.data.coor.LatLon; |
13 | 14 | import org.openstreetmap.josm.data.projection.datum.Datum; |
14 | 15 | import org.openstreetmap.josm.data.projection.proj.Proj; |
… |
… |
public abstract class AbstractProjection implements Projection {
|
113 | 114 | } |
114 | 115 | |
115 | 116 | @Override |
116 | | public EastNorth latlon2eastNorth(LatLon ll) { |
| 117 | public EastNorth latlon2eastNorth(ILatLon ll) { |
117 | 118 | ll = datum.fromWGS84(ll); |
118 | 119 | double[] en = proj.project(Math.toRadians(ll.lat()), Math.toRadians(LatLon.normalizeLon(ll.lon() - lon0 - pm))); |
119 | 120 | return new EastNorth((ellps.a * k0 * en[0] + x0) / toMeter, (ellps.a * k0 * en[1] + y0) / toMeter); |
… |
… |
public abstract class AbstractProjection implements Projection {
|
121 | 122 | |
122 | 123 | @Override |
123 | 124 | public LatLon eastNorth2latlon(EastNorth en) { |
| 125 | // We know it is a latlon. Nice would be to change this method return type to ILatLon |
124 | 126 | return eastNorth2latlon(en, LatLon::normalizeLon); |
125 | 127 | } |
126 | 128 | |
127 | 129 | @Override |
128 | 130 | public LatLon eastNorth2latlonClamped(EastNorth en) { |
129 | | LatLon ll = eastNorth2latlon(en, lon -> Utils.clamp(lon, -180, 180)); |
| 131 | ILatLon ll = eastNorth2latlon(en, lon -> Utils.clamp(lon, -180, 180)); |
130 | 132 | Bounds bounds = getWorldBoundsLatLon(); |
131 | 133 | return new LatLon(Utils.clamp(ll.lat(), bounds.getMinLat(), bounds.getMaxLat()), |
132 | 134 | Utils.clamp(ll.lon(), bounds.getMinLon(), bounds.getMaxLon())); |
-
diff --git a/src/org/openstreetmap/josm/data/projection/Ellipsoid.java b/src/org/openstreetmap/josm/data/projection/Ellipsoid.java
index 4ea41db..a7e60c7 100644
a
|
b
|
|
6 | 6 | */ |
7 | 7 | package org.openstreetmap.josm.data.projection; |
8 | 8 | |
| 9 | import org.openstreetmap.josm.data.coor.ILatLon; |
9 | 10 | import org.openstreetmap.josm.data.coor.LatLon; |
10 | 11 | |
11 | 12 | /** |
… |
… |
public final class Ellipsoid {
|
347 | 348 | * @param coord The Latitude and longitude in degrees |
348 | 349 | * @return the corresponding (X, Y Z) cartesian coordinates in meters. |
349 | 350 | */ |
350 | | public double[] latLon2Cart(LatLon coord) { |
| 351 | public double[] latLon2Cart(ILatLon coord) { |
351 | 352 | double phi = Math.toRadians(coord.lat()); |
352 | 353 | double lambda = Math.toRadians(coord.lon()); |
353 | 354 | |
-
diff --git a/src/org/openstreetmap/josm/data/projection/Projecting.java b/src/org/openstreetmap/josm/data/projection/Projecting.java
index 80d0101..6cdca12 100644
a
|
b
|
import java.util.Map;
|
5 | 5 | |
6 | 6 | import org.openstreetmap.josm.data.ProjectionBounds; |
7 | 7 | import org.openstreetmap.josm.data.coor.EastNorth; |
| 8 | import org.openstreetmap.josm.data.coor.ILatLon; |
8 | 9 | import org.openstreetmap.josm.data.coor.LatLon; |
9 | 10 | |
10 | 11 | /** |
… |
… |
public interface Projecting {
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Convert from lat/lon to easting/northing. |
| 22 | * <p> |
| 23 | * This method exists to not break binary compatibility with old plugins |
21 | 24 | * |
22 | 25 | * @param ll the geographical point to convert (in WGS84 lat/lon) |
23 | 26 | * @return the corresponding east/north coordinates |
24 | 27 | */ |
25 | | EastNorth latlon2eastNorth(LatLon ll); |
| 28 | default EastNorth latlon2eastNorth(LatLon ll) { |
| 29 | return latlon2eastNorth((ILatLon) ll); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Convert from lat/lon to easting/northing. This method uses the newer {@link ILatLon} interface. |
| 34 | * |
| 35 | * @param ll the geographical point to convert (in WGS84 lat/lon) |
| 36 | * @return the corresponding east/north coordinates |
| 37 | */ |
| 38 | EastNorth latlon2eastNorth(ILatLon ll); |
26 | 39 | |
27 | 40 | /** |
28 | 41 | * Convert a east/north coordinate to the {@link LatLon} coordinate. |
… |
… |
public interface Projecting {
|
47 | 60 | * @return a map of non-overlapping {@link ProjectionBounds} instances mapped to the {@link Projecting} object to use for that area. |
48 | 61 | */ |
49 | 62 | Map<ProjectionBounds, Projecting> getProjectingsForArea(ProjectionBounds area); |
| 63 | |
| 64 | /** |
| 65 | * Gets the object used as cache identifier when caching results of this projection. |
| 66 | * @return The object to use as cache key |
| 67 | * @since 10827 |
| 68 | */ |
| 69 | default Object getCacheKey() { |
| 70 | return this; |
| 71 | } |
50 | 72 | } |
-
diff --git a/src/org/openstreetmap/josm/data/projection/Projection.java b/src/org/openstreetmap/josm/data/projection/Projection.java
index e2739d1..62c7050 100644
a
|
b
|
public interface Projection extends Projecting {
|
102 | 102 | * @return true if natural order of coordinates is North East, false if East North |
103 | 103 | */ |
104 | 104 | boolean switchXY(); |
105 | | |
106 | | /** |
107 | | * Gets the object used as cache identifier when caching results of this projection. |
108 | | * @return The object to use as cache key |
109 | | * @since 10827 |
110 | | */ |
111 | | default Object getCacheKey() { |
112 | | return this; |
113 | | } |
114 | 105 | } |
-
diff --git a/src/org/openstreetmap/josm/data/projection/ShiftedProjecting.java b/src/org/openstreetmap/josm/data/projection/ShiftedProjecting.java
index 3b30174..6638263 100644
a
|
b
|
import java.util.Map;
|
6 | 6 | |
7 | 7 | import org.openstreetmap.josm.data.ProjectionBounds; |
8 | 8 | import org.openstreetmap.josm.data.coor.EastNorth; |
| 9 | import org.openstreetmap.josm.data.coor.ILatLon; |
9 | 10 | import org.openstreetmap.josm.data.coor.LatLon; |
10 | 11 | |
11 | 12 | /** |
… |
… |
public class ShiftedProjecting implements Projecting {
|
28 | 29 | } |
29 | 30 | |
30 | 31 | @Override |
31 | | public EastNorth latlon2eastNorth(LatLon ll) { |
| 32 | public EastNorth latlon2eastNorth(ILatLon ll) { |
32 | 33 | return base.latlon2eastNorth(ll).add(offset); |
33 | 34 | } |
34 | 35 | |
-
diff --git a/src/org/openstreetmap/josm/data/projection/datum/CentricDatum.java b/src/org/openstreetmap/josm/data/projection/datum/CentricDatum.java
index 0def3ea..fd938a1 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.data.projection.datum; |
3 | 3 | |
| 4 | import org.openstreetmap.josm.data.coor.ILatLon; |
4 | 5 | import org.openstreetmap.josm.data.coor.LatLon; |
5 | 6 | import org.openstreetmap.josm.data.projection.Ellipsoid; |
6 | 7 | |
… |
… |
public class CentricDatum extends AbstractDatum {
|
15 | 16 | } |
16 | 17 | |
17 | 18 | @Override |
18 | | public LatLon toWGS84(LatLon ll) { |
| 19 | public LatLon toWGS84(ILatLon ll) { |
19 | 20 | return Ellipsoid.WGS84.cart2LatLon(ellps.latLon2Cart(ll)); |
20 | 21 | } |
21 | 22 | |
22 | 23 | @Override |
23 | | public LatLon fromWGS84(LatLon ll) { |
| 24 | public ILatLon fromWGS84(ILatLon ll) { |
24 | 25 | return this.ellps.cart2LatLon(Ellipsoid.WGS84.latLon2Cart(ll)); |
25 | 26 | } |
26 | 27 | |
-
diff --git a/src/org/openstreetmap/josm/data/projection/datum/Datum.java b/src/org/openstreetmap/josm/data/projection/datum/Datum.java
index 16cf527..04a30d7 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.data.projection.datum; |
3 | 3 | |
| 4 | import org.openstreetmap.josm.data.coor.ILatLon; |
4 | 5 | import org.openstreetmap.josm.data.coor.LatLon; |
5 | 6 | import org.openstreetmap.josm.data.projection.Ellipsoid; |
6 | 7 | |
… |
… |
public interface Datum {
|
33 | 34 | * @param ll original lat/lon in this datum |
34 | 35 | * @return lat/lon converted to WGS84 |
35 | 36 | */ |
36 | | LatLon toWGS84(LatLon ll); |
| 37 | LatLon toWGS84(ILatLon ll); |
37 | 38 | |
38 | 39 | /** |
39 | 40 | * Convert lat/lon from {@link Ellipsoid#WGS84} to this datum. |
40 | 41 | * @param ll original lat/lon in WGS84 |
41 | 42 | * @return converted lat/lon in this datum |
42 | 43 | */ |
43 | | LatLon fromWGS84(LatLon ll); |
| 44 | ILatLon fromWGS84(ILatLon ll); |
44 | 45 | } |
-
diff --git a/src/org/openstreetmap/josm/data/projection/datum/NTV2Datum.java b/src/org/openstreetmap/josm/data/projection/datum/NTV2Datum.java
index dd427b8..fcf69c8 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.data.projection.datum; |
3 | 3 | |
| 4 | import org.openstreetmap.josm.data.coor.ILatLon; |
4 | 5 | import org.openstreetmap.josm.data.coor.LatLon; |
5 | 6 | import org.openstreetmap.josm.data.projection.Ellipsoid; |
6 | 7 | |
… |
… |
public class NTV2Datum extends AbstractDatum {
|
17 | 18 | } |
18 | 19 | |
19 | 20 | @Override |
20 | | public LatLon toWGS84(LatLon ll) { |
| 21 | public LatLon toWGS84(ILatLon ll) { |
21 | 22 | NTV2GridShift gs = new NTV2GridShift(ll); |
22 | 23 | nadgrids.getShiftFile().gridShiftForward(gs); |
23 | 24 | return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees()); |
24 | 25 | } |
25 | 26 | |
26 | 27 | @Override |
27 | | public LatLon fromWGS84(LatLon ll) { |
| 28 | public ILatLon fromWGS84(ILatLon ll) { |
28 | 29 | NTV2GridShift gs = new NTV2GridShift(ll); |
29 | 30 | nadgrids.getShiftFile().gridShiftReverse(gs); |
30 | 31 | return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees()); |
-
diff --git a/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShift.java b/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShift.java
index f38e97d..9ab56d0 100644
a
|
b
|
package org.openstreetmap.josm.data.projection.datum;
|
21 | 21 | |
22 | 22 | import java.io.Serializable; |
23 | 23 | |
24 | | import org.openstreetmap.josm.data.coor.LatLon; |
| 24 | import org.openstreetmap.josm.data.coor.ILatLon; |
25 | 25 | import org.openstreetmap.josm.data.projection.Ellipsoid; |
26 | 26 | |
27 | 27 | /** |
… |
… |
public class NTV2GridShift implements Serializable {
|
62 | 62 | * Constructs a new {@code NTV2GridShift} from a {@code LatLon}. |
63 | 63 | * @param p lat/lon |
64 | 64 | */ |
65 | | public NTV2GridShift(LatLon p) { |
| 65 | public NTV2GridShift(ILatLon p) { |
66 | 66 | setLatDegrees(p.lat()); |
67 | 67 | setLonPositiveEastDegrees(p.lon()); |
68 | 68 | } |
-
diff --git a/src/org/openstreetmap/josm/data/projection/datum/NullDatum.java b/src/org/openstreetmap/josm/data/projection/datum/NullDatum.java
index b86a59c..24d0cdd 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.data.projection.datum; |
3 | 3 | |
| 4 | import org.openstreetmap.josm.data.coor.ILatLon; |
4 | 5 | import org.openstreetmap.josm.data.coor.LatLon; |
5 | 6 | import org.openstreetmap.josm.data.projection.Ellipsoid; |
6 | 7 | |
… |
… |
public class NullDatum extends AbstractDatum {
|
15 | 16 | } |
16 | 17 | |
17 | 18 | @Override |
18 | | public LatLon toWGS84(LatLon ll) { |
19 | | return ll; |
| 19 | public LatLon toWGS84(ILatLon ll) { |
| 20 | return new LatLon(ll); |
20 | 21 | } |
21 | 22 | |
22 | 23 | @Override |
23 | | public LatLon fromWGS84(LatLon ll) { |
| 24 | public ILatLon fromWGS84(ILatLon ll) { |
24 | 25 | return ll; |
25 | 26 | } |
26 | 27 | |
-
diff --git a/src/org/openstreetmap/josm/data/projection/datum/SevenParameterDatum.java b/src/org/openstreetmap/josm/data/projection/datum/SevenParameterDatum.java
index 65c28d7..114eefb 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.data.projection.datum; |
3 | 3 | |
| 4 | import org.openstreetmap.josm.data.coor.ILatLon; |
4 | 5 | import org.openstreetmap.josm.data.coor.LatLon; |
5 | 6 | import org.openstreetmap.josm.data.projection.Ellipsoid; |
6 | 7 | |
… |
… |
public class SevenParameterDatum extends AbstractDatum {
|
45 | 46 | } |
46 | 47 | |
47 | 48 | @Override |
48 | | public LatLon toWGS84(LatLon ll) { |
| 49 | public LatLon toWGS84(ILatLon ll) { |
49 | 50 | double[] xyz = ellps.latLon2Cart(ll); |
50 | 51 | double x = dx + xyz[0]*(1+s) + xyz[2]*ry - xyz[1]*rz; |
51 | 52 | double y = dy + xyz[1]*(1+s) + xyz[0]*rz - xyz[2]*rx; |
… |
… |
public class SevenParameterDatum extends AbstractDatum {
|
54 | 55 | } |
55 | 56 | |
56 | 57 | @Override |
57 | | public LatLon fromWGS84(LatLon ll) { |
| 58 | public ILatLon fromWGS84(ILatLon ll) { |
58 | 59 | double[] xyz = Ellipsoid.WGS84.latLon2Cart(ll); |
59 | 60 | double x = (1-s)*(-dx + xyz[0] + ((-dz+xyz[2])*(-ry) - (-dy+xyz[1])*(-rz))); |
60 | 61 | double y = (1-s)*(-dy + xyz[1] + ((-dx+xyz[0])*(-rz) - (-dz+xyz[2])*(-rx))); |
-
diff --git a/src/org/openstreetmap/josm/data/projection/datum/ThreeParameterDatum.java b/src/org/openstreetmap/josm/data/projection/datum/ThreeParameterDatum.java
index 7311915..1fe6f73 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.data.projection.datum; |
3 | 3 | |
| 4 | import org.openstreetmap.josm.data.coor.ILatLon; |
4 | 5 | import org.openstreetmap.josm.data.coor.LatLon; |
5 | 6 | import org.openstreetmap.josm.data.projection.Ellipsoid; |
6 | 7 | |
… |
… |
public class ThreeParameterDatum extends AbstractDatum {
|
19 | 20 | } |
20 | 21 | |
21 | 22 | @Override |
22 | | public LatLon toWGS84(LatLon ll) { |
| 23 | public LatLon toWGS84(ILatLon ll) { |
23 | 24 | double[] xyz = ellps.latLon2Cart(ll); |
24 | 25 | xyz[0] += dx; |
25 | 26 | xyz[1] += dy; |
… |
… |
public class ThreeParameterDatum extends AbstractDatum {
|
28 | 29 | } |
29 | 30 | |
30 | 31 | @Override |
31 | | public LatLon fromWGS84(LatLon ll) { |
| 32 | public ILatLon fromWGS84(ILatLon ll) { |
32 | 33 | double[] xyz = Ellipsoid.WGS84.latLon2Cart(ll); |
33 | 34 | xyz[0] -= dx; |
34 | 35 | xyz[1] -= dy; |
-
diff --git a/src/org/openstreetmap/josm/data/validation/PaintVisitor.java b/src/org/openstreetmap/josm/data/validation/PaintVisitor.java
index 18181ae..185d6c2 100644
a
|
b
|
|
2 | 2 | package org.openstreetmap.josm.data.validation; |
3 | 3 | |
4 | 4 | import java.awt.Color; |
5 | | import java.awt.Graphics; |
| 5 | import java.awt.Graphics2D; |
6 | 6 | import java.awt.Point; |
7 | 7 | import java.util.HashSet; |
8 | 8 | import java.util.List; |
… |
… |
import org.openstreetmap.josm.data.osm.Way;
|
17 | 17 | import org.openstreetmap.josm.data.osm.WaySegment; |
18 | 18 | import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; |
19 | 19 | import org.openstreetmap.josm.gui.MapView; |
| 20 | import org.openstreetmap.josm.gui.draw.MapViewPath; |
| 21 | import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; |
20 | 22 | |
21 | 23 | /** |
22 | 24 | * Visitor that highlights the primitives affected by an error |
… |
… |
import org.openstreetmap.josm.gui.MapView;
|
25 | 27 | */ |
26 | 28 | public class PaintVisitor extends AbstractVisitor implements ValidatorVisitor { |
27 | 29 | /** The graphics */ |
28 | | private final Graphics g; |
| 30 | private final Graphics2D g; |
29 | 31 | /** The MapView */ |
30 | 32 | private final MapView mv; |
31 | 33 | |
… |
… |
public class PaintVisitor extends AbstractVisitor implements ValidatorVisitor {
|
42 | 44 | * @param g The graphics |
43 | 45 | * @param mv The Mapview |
44 | 46 | */ |
45 | | public PaintVisitor(Graphics g, MapView mv) { |
| 47 | public PaintVisitor(Graphics2D g, MapView mv) { |
46 | 48 | this.g = g; |
47 | 49 | this.mv = mv; |
48 | 50 | } |
… |
… |
public class PaintVisitor extends AbstractVisitor implements ValidatorVisitor {
|
119 | 121 | PaintedPoint pp = new PaintedPoint(n.getCoor(), color); |
120 | 122 | |
121 | 123 | if (!paintedPoints.contains(pp)) { |
122 | | Point p = mv.getPoint(n); |
| 124 | MapViewPath circle = new MapViewPath(mv.getState()).shapeAround(n, SymbolShape.CIRCLE, 10); |
123 | 125 | |
124 | 126 | if (selected) { |
125 | 127 | g.setColor(getHighlightColor(color)); |
126 | | g.fillOval(p.x - 5, p.y - 5, 10, 10); |
| 128 | g.fill(circle); |
127 | 129 | } |
128 | 130 | g.setColor(color); |
129 | | g.drawOval(p.x - 5, p.y - 5, 10, 10); |
| 131 | g.draw(circle); |
130 | 132 | paintedPoints.add(pp); |
131 | 133 | } |
132 | 134 | } |
-
diff --git a/src/org/openstreetmap/josm/gui/MapViewState.java b/src/org/openstreetmap/josm/gui/MapViewState.java
index e3bbe51..cef7239 100644
a
|
b
|
import org.openstreetmap.josm.Main;
|
17 | 17 | import org.openstreetmap.josm.data.Bounds; |
18 | 18 | import org.openstreetmap.josm.data.ProjectionBounds; |
19 | 19 | import org.openstreetmap.josm.data.coor.EastNorth; |
| 20 | import org.openstreetmap.josm.data.coor.ILatLon; |
20 | 21 | import org.openstreetmap.josm.data.coor.LatLon; |
21 | | import org.openstreetmap.josm.data.osm.Node; |
22 | 22 | import org.openstreetmap.josm.data.projection.Projecting; |
23 | 23 | import org.openstreetmap.josm.data.projection.Projection; |
24 | 24 | import org.openstreetmap.josm.gui.download.DownloadDialog; |
… |
… |
public final class MapViewState implements Serializable {
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | | * Gets the {@link MapViewPoint} for the given {@link LatLon} coordinate. |
178 | | * @param latlon the position |
179 | | * @return The point for that position. |
180 | | * @since 10651 |
181 | | */ |
182 | | public MapViewPoint getPointFor(LatLon latlon) { |
183 | | return getPointFor(getProjection().latlon2eastNorth(latlon)); |
184 | | } |
185 | | |
186 | | /** |
187 | | * Gets the {@link MapViewPoint} for the given node. This is faster than {@link #getPointFor(LatLon)} because it uses the node east/north |
188 | | * cache. |
189 | | * @param node The node |
190 | | * @return The position of that node. |
191 | | * @since 10827 |
| 177 | * Gets the {@link MapViewPoint} for the given lat lon coordinates. |
| 178 | * @param latlon The lat lon position, e.g. a node |
| 179 | * @return The position of that object. |
| 180 | * @since xxx |
192 | 181 | */ |
193 | | public MapViewPoint getPointFor(Node node) { |
194 | | return getPointFor(node.getEastNorth(getProjection())); |
| 182 | public MapViewPoint getPointFor(ILatLon latlon) { |
| 183 | return getPointFor(latlon.getEastNorth(getProjecting())); |
195 | 184 | } |
196 | 185 | |
197 | 186 | /** |
… |
… |
public final class MapViewState implements Serializable {
|
248 | 237 | /** |
249 | 238 | * Gets the current projection used for the MapView. |
250 | 239 | * @return The projection. |
| 240 | * @see #getProjecting() |
251 | 241 | */ |
252 | 242 | public Projection getProjection() { |
253 | 243 | return projecting.getBaseProjection(); |
254 | 244 | } |
255 | 245 | |
256 | 246 | /** |
| 247 | * Gets the current projecting instance that is used to convert between east/north and lat/lon space. |
| 248 | * @return The projection. |
| 249 | * @since xxx |
| 250 | */ |
| 251 | public Projecting getProjecting() { |
| 252 | return projecting; |
| 253 | } |
| 254 | |
| 255 | /** |
257 | 256 | * Creates an affine transform that is used to convert the east/north coordinates to view coordinates. |
258 | 257 | * @return The affine transform. It should not be changed. |
259 | 258 | * @since 10375 |
-
diff --git a/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java b/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java
index 11cb3f9..99a0649 100644
a
|
b
|
public class InspectPrimitiveDataText {
|
202 | 202 | } |
203 | 203 | |
204 | 204 | void addCoordinates(Node n) { |
205 | | if (n.getCoor() != null) { |
| 205 | if (n.isLatLonKnown()) { |
206 | 206 | add(tr("Coordinates: "), |
207 | | Double.toString(n.getCoor().lat()), ", ", |
208 | | Double.toString(n.getCoor().lon())); |
| 207 | Double.toString(n.lat()), ", ", |
| 208 | Double.toString(n.lon())); |
209 | 209 | add(tr("Coordinates (projected): "), |
210 | 210 | Double.toString(n.getEastNorth().east()), ", ", |
211 | 211 | Double.toString(n.getEastNorth().north())); |
-
diff --git a/src/org/openstreetmap/josm/gui/draw/MapViewPath.java b/src/org/openstreetmap/josm/gui/draw/MapViewPath.java
index 7b2fb49..55d29a9 100644
a
|
b
|
|
2 | 2 | package org.openstreetmap.josm.gui.draw; |
3 | 3 | |
4 | 4 | import org.openstreetmap.josm.data.coor.EastNorth; |
5 | | import org.openstreetmap.josm.data.osm.Node; |
| 5 | import org.openstreetmap.josm.data.coor.ILatLon; |
6 | 6 | import org.openstreetmap.josm.gui.MapViewState; |
7 | 7 | import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; |
8 | 8 | import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; |
… |
… |
public class MapViewPath extends MapPath2D {
|
29 | 29 | * @param n The node |
30 | 30 | * @return this for easy chaining. |
31 | 31 | */ |
32 | | public MapViewPath moveTo(Node n) { |
33 | | moveTo(n.getEastNorth()); |
| 32 | public MapViewPath moveTo(ILatLon n) { |
| 33 | moveTo(n.getEastNorth(state.getProjecting())); |
34 | 34 | return this; |
35 | 35 | } |
36 | 36 | |
… |
… |
public class MapViewPath extends MapPath2D {
|
55 | 55 | * @param n The node |
56 | 56 | * @return this for easy chaining. |
57 | 57 | */ |
58 | | public MapViewPath lineTo(Node n) { |
59 | | lineTo(n.getEastNorth()); |
| 58 | public MapViewPath lineTo(ILatLon n) { |
| 59 | lineTo(n.getEastNorth(state.getProjecting())); |
60 | 60 | return this; |
61 | 61 | } |
62 | 62 | |
… |
… |
public class MapViewPath extends MapPath2D {
|
83 | 83 | * @param size The size of the symbol in pixel |
84 | 84 | * @return this for easy chaining. |
85 | 85 | */ |
86 | | public MapViewPath shapeAround(Node p1, SymbolShape symbol, double size) { |
87 | | shapeAround(p1.getEastNorth(), symbol, size); |
| 86 | public MapViewPath shapeAround(ILatLon p1, SymbolShape symbol, double size) { |
| 87 | shapeAround(p1.getEastNorth(state.getProjecting()), symbol, size); |
88 | 88 | return this; |
89 | 89 | } |
90 | 90 | |
… |
… |
public class MapViewPath extends MapPath2D {
|
112 | 112 | * @param connect <code>true</code> if we should use a lineTo as first command. |
113 | 113 | * @return this for easy chaining. |
114 | 114 | */ |
115 | | public MapViewPath append(Iterable<Node> nodes, boolean connect) { |
| 115 | public MapViewPath append(Iterable<? extends ILatLon> nodes, boolean connect) { |
116 | 116 | appendWay(nodes, connect, false); |
117 | 117 | return this; |
118 | 118 | } |
… |
… |
public class MapViewPath extends MapPath2D {
|
123 | 123 | * @param connect <code>true</code> if we should use a lineTo as first command. |
124 | 124 | * @return this for easy chaining. |
125 | 125 | */ |
126 | | public MapViewPath appendClosed(Iterable<Node> nodes, boolean connect) { |
| 126 | public MapViewPath appendClosed(Iterable<? extends ILatLon> nodes, boolean connect) { |
127 | 127 | appendWay(nodes, connect, true); |
128 | 128 | return this; |
129 | 129 | } |
130 | 130 | |
131 | | private void appendWay(Iterable<Node> nodes, boolean connect, boolean close) { |
| 131 | private void appendWay(Iterable<? extends ILatLon> nodes, boolean connect, boolean close) { |
132 | 132 | boolean useMoveTo = !connect; |
133 | | Node first = null; |
134 | | for (Node n : nodes) { |
| 133 | ILatLon first = null; |
| 134 | for (ILatLon n : nodes) { |
135 | 135 | if (useMoveTo) { |
136 | 136 | moveTo(n); |
137 | 137 | } else { |
-
diff --git a/src/org/openstreetmap/josm/tools/Geometry.java b/src/org/openstreetmap/josm/tools/Geometry.java
index 7cafef3..d399d89 100644
a
|
b
|
import org.openstreetmap.josm.command.AddCommand;
|
21 | 21 | import org.openstreetmap.josm.command.ChangeCommand; |
22 | 22 | import org.openstreetmap.josm.command.Command; |
23 | 23 | import org.openstreetmap.josm.data.coor.EastNorth; |
24 | | import org.openstreetmap.josm.data.coor.LatLon; |
25 | 24 | import org.openstreetmap.josm.data.osm.BBox; |
26 | 25 | import org.openstreetmap.josm.data.osm.MultipolygonBuilder; |
27 | 26 | import org.openstreetmap.josm.data.osm.MultipolygonBuilder.JoinedPolygon; |
… |
… |
public final class Geometry {
|
218 | 217 | |
219 | 218 | BBox bounds = new BBox(nodes.get(0)); |
220 | 219 | for (Node n: nodes) { |
221 | | bounds.add(n.getCoor()); |
| 220 | bounds.add(n); |
222 | 221 | } |
223 | 222 | return bounds; |
224 | 223 | } |
… |
… |
public final class Geometry {
|
413 | 412 | else if (segmentOnly && offset >= 1) |
414 | 413 | return p2; |
415 | 414 | else |
416 | | return new EastNorth(p1.getX() + ldx * offset, p1.getY() + ldy * offset); |
| 415 | return p1.interpolate(p2, offset); |
417 | 416 | } |
418 | 417 | |
419 | 418 | /** |
… |
… |
public final class Geometry {
|
510 | 509 | boolean begin = true; |
511 | 510 | for (Node n : polygon) { |
512 | 511 | if (begin) { |
513 | | path.moveTo(n.getCoor().lon(), n.getCoor().lat()); |
| 512 | path.moveTo(n.lon(), n.lat()); |
514 | 513 | begin = false; |
515 | 514 | } else { |
516 | | path.lineTo(n.getCoor().lon(), n.getCoor().lat()); |
| 515 | path.lineTo(n.lon(), n.lat()); |
517 | 516 | } |
518 | 517 | } |
519 | 518 | if (!begin) { |
… |
… |
public final class Geometry {
|
706 | 705 | double area2 = 0.; |
707 | 706 | |
708 | 707 | for (int node = 1; node <= /*sic! consider last-first as well*/ nodesCount; node++) { |
709 | | LatLon coorPrev = nodes.get(node - 1).getCoor(); |
710 | | LatLon coorCurr = nodes.get(node % nodesCount).getCoor(); |
| 708 | Node coorPrev = nodes.get(node - 1); |
| 709 | Node coorCurr = nodes.get(node % nodesCount); |
711 | 710 | area2 += coorPrev.lon() * coorCurr.lat(); |
712 | 711 | area2 -= coorCurr.lon() * coorPrev.lat(); |
713 | 712 | } |
… |
… |
public final class Geometry {
|
966 | 965 | CheckParameterUtil.ensureParameterNotNull(nodes, "nodes"); |
967 | 966 | double area = 0; |
968 | 967 | double perimeter = 0; |
| 968 | Projection useProjection = projection == null ? Main.getProjection() : projection; |
| 969 | |
969 | 970 | if (!nodes.isEmpty()) { |
970 | 971 | boolean closed = nodes.get(0) == nodes.get(nodes.size() - 1); |
971 | 972 | int numSegments = closed ? nodes.size() - 1 : nodes.size(); |
972 | | EastNorth p1 = projection == null ? nodes.get(0).getEastNorth() : projection.latlon2eastNorth(nodes.get(0).getCoor()); |
| 973 | EastNorth p1 = nodes.get(0).getEastNorth(useProjection); |
973 | 974 | for (int i = 1; i <= numSegments; i++) { |
974 | 975 | final Node node = nodes.get(i == numSegments ? 0 : i); |
975 | | final EastNorth p2 = projection == null ? node.getEastNorth() : projection.latlon2eastNorth(node.getCoor()); |
| 976 | final EastNorth p2 = node.getEastNorth(useProjection); |
976 | 977 | if (p1 != null && p2 != null) { |
977 | 978 | area += p1.east() * p2.north() - p2.east() * p1.north(); |
978 | 979 | perimeter += p1.distance(p2); |
-
diff --git a/test/unit/org/openstreetmap/josm/data/projection/ShiftedProjectionTest.java b/test/unit/org/openstreetmap/josm/data/projection/ShiftedProjectionTest.java
index 8a2b625..7e5c2a1 100644
a
|
b
|
import java.util.stream.Collectors;
|
13 | 13 | import org.junit.Test; |
14 | 14 | import org.openstreetmap.josm.data.ProjectionBounds; |
15 | 15 | import org.openstreetmap.josm.data.coor.EastNorth; |
| 16 | import org.openstreetmap.josm.data.coor.ILatLon; |
16 | 17 | import org.openstreetmap.josm.data.coor.LatLon; |
17 | 18 | |
18 | 19 | /** |
… |
… |
import org.openstreetmap.josm.data.coor.LatLon;
|
22 | 23 | public class ShiftedProjectionTest { |
23 | 24 | private static final class ProjectingBase implements Projecting { |
24 | 25 | @Override |
25 | | public EastNorth latlon2eastNorth(LatLon ll) { |
| 26 | public EastNorth latlon2eastNorth(ILatLon ll) { |
26 | 27 | return new EastNorth(ll.lat() * 2, ll.lon() * 3); |
27 | 28 | } |
28 | 29 | |
… |
… |
public class ShiftedProjectionTest {
|
52 | 53 | } |
53 | 54 | |
54 | 55 | /** |
55 | | * Test {@link ShiftedProjecting#latlon2eastNorth(LatLon)} |
| 56 | * Test {@link ShiftedProjecting#latlon2eastNorth(ILatLon)} |
56 | 57 | */ |
57 | 58 | @Test |
58 | 59 | public void testLatlon2eastNorth() { |