Changeset 11118 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-10-11T20:20:06+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r11109 r11118 9 9 import java.awt.event.KeyEvent; 10 10 import java.util.ArrayList; 11 import java.util.Arrays; 11 12 import java.util.Collection; 12 13 import java.util.Collections; … … 134 135 */ 135 136 protected boolean isRequiredNode(Way way, Node node) { 136 boolean isRequired = Collections.frequency(way.getNodes(), node) > 1; 137 int frequency = Collections.frequency(way.getNodes(), node); 138 if ((way.getNode(0) == node) && (way.getNode(way.getNodesCount()-1) == node)) { 139 frequency = frequency - 1; // closed way closing node counted only once 140 } 141 boolean isRequired = frequency > 1; 137 142 if (!isRequired) { 138 143 List<OsmPrimitive> parents = new LinkedList<>(); … … 187 192 lower = i; 188 193 i++; 194 } 195 196 if ((newNodes.size() > 3) && (newNodes.get(0) == newNodes.get(newNodes.size() - 1))) { 197 // Closed way, check if the first node could also be simplified ... 198 if (!isRequiredNode(w, newNodes.get(0))) { 199 final List<Node> l1 = Arrays.asList(newNodes.get(newNodes.size() - 2), newNodes.get(0), newNodes.get(1)); 200 final List<Node> l2 = new ArrayList<>(3); 201 buildSimplifiedNodeList(l1, 0, 2, threshold, l2); 202 if (!l2.contains(newNodes.get(0))) { 203 newNodes.remove(0); 204 newNodes.set(newNodes.size() - 1, newNodes.get(0)); // close the way 205 } 206 } 189 207 } 190 208 … … 253 271 * http://williams.best.vwh.net/avform.htm 254 272 */ 255 p ublicstatic double dist(double lat1, double lon1, double lat2, double lon2) {273 private static double dist(double lat1, double lon1, double lat2, double lon2) { 256 274 return 2 * Math.asin(Math.sqrt(Math.pow(Math.sin((lat1 - lat2) / 2), 2) + Math.cos(lat1) * Math.cos(lat2) 257 275 * Math.pow(Math.sin((lon1 - lon2) / 2), 2))); 258 276 } 259 277 260 p ublicstatic double course(double lat1, double lon1, double lat2, double lon2) {278 private static double course(double lat1, double lon1, double lat2, double lon2) { 261 279 return Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) 262 280 * Math.cos(lat2) * Math.cos(lon1 - lon2)) … … 264 282 } 265 283 266 p ublicstatic double xtd(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3) {284 private static double xtd(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3) { 267 285 double distAD = dist(lat1, lon1, lat3, lon3); 268 286 double crsAD = course(lat1, lon1, lat3, lon3);
Note:
See TracChangeset
for help on using the changeset viewer.