Changeset 25030 in osm for applications/editors/josm/plugins/simplifyarea/src/sk/zdila
- Timestamp:
- 2011-01-12T07:53:25+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java
r25007 r25030 76 76 Main.parent, 77 77 "<html>" + trn("The selected way has nodes outside of the downloaded data region.", "The selected ways have nodes outside of the downloaded data region.", getCurrentDataSet().getSelectedWays().size()) 78 78 + "<br>" + tr("This can lead to nodes being deleted accidentally.") + "<br>" + tr("Do you want to delete them anyway?") + "</html>", 79 79 tr("Delete nodes outside of data regions?"), JOptionPane.WARNING_MESSAGE, null, // no special icon 80 80 options, options[0], null); … … 168 168 * the way to simplify 169 169 */ 170 170 private SequenceCommand simplifyWay(final Way w) { 171 171 final double angleThreshold = Main.pref.getDouble("simplify-area.angle.threshold", 10); 172 172 final double angleFactor = Main.pref.getDouble("simplify-area.angle.factor", 1.0); … … 193 193 194 194 while (true) { 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 195 Node prevNode = null; 196 LatLon coord1 = null; 197 LatLon coord2 = null; 198 199 double minWeight = Double.MAX_VALUE; 200 Node bestMatch = null; 201 202 for (int i = 0, len = nodes.size() + (closed ? 2 : 1); i < len; i++) { 203 final Node n = nodes.get(i % nodes.size()); 204 final LatLon coord3 = n.getCoor(); 205 206 if (coord1 != null) { 207 final double angleWeight = computeConvectAngle(coord1, coord2, coord3) / angleThreshold; 208 final double areaWeight = computeArea(coord1, coord2, coord3) / areaThreshold; 209 final double distanceWeight = Math.abs(crossTrackError(coord1, coord2, coord3)) / distanceThreshold; 210 211 final double weight = isRequiredNode(w, prevNode) || 212 !closed && i == len - 1 || // don't remove last node of the not closed way 213 angleWeight > 1.0 || areaWeight > 1.0 || distanceWeight > 1.0 ? Double.MAX_VALUE : 214 angleWeight * angleFactor + areaWeight * areaFactor + distanceWeight * distanceFactor; 215 216 if (weight < minWeight) { 217 minWeight = weight; 218 bestMatch = prevNode; 219 } 220 } 221 222 coord1 = coord2; 223 coord2 = coord3; 224 prevNode = n; 225 } 226 227 if (bestMatch == null) { 228 break; 229 } 230 231 nodes.remove(bestMatch); 232 232 } 233 233 … … 237 237 final Map<Node, LatLon> coordMap = new HashMap<Node, LatLon>(); 238 238 for (final Node n : nodes) { 239 239 coordMap.put(n, n.getCoor()); 240 240 } 241 241 … … 243 243 244 244 while (true) { 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 245 double minDist = Double.MAX_VALUE; 246 Node node1 = null; 247 Node node2 = null; 248 249 for (int i = 0, len = nodes.size() + (closed ? 2 : 1); i < len; i++) { 250 final Node n1 = nodes.get(i % nodes.size()); 251 final Node n2 = nodes.get((i + 1) % nodes.size()); 252 253 if (isRequiredNode(w, n1) || isRequiredNode(w, n2)) { 254 continue; 255 } 256 257 final double dist = coordMap.get(n1).greatCircleDistance(coordMap.get(n2)); 258 if (dist < minDist && dist < mergeThreshold) { 259 minDist = dist; 260 node1 = n1; 261 node2 = n2; 262 } 263 } 264 265 if (node1 == null || node2 == null) { 266 break; 267 } 268 269 270 final LatLon coord = coordMap.get(node1).getCenter(coordMap.get(node2)); 271 coordMap.put(node1, coord); 272 moveCommandList.put(node1, new MoveCommand(node1, coord)); 273 274 nodes.remove(node2); 275 coordMap.remove(node2); 276 moveCommandList.remove(node2); 277 277 } 278 278 … … 301 301 302 302 public static double computeConvectAngle(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 303 304 303 final double angle = Math.abs(heading(coord2, coord3) - heading(coord1, coord2)); 304 return Math.toDegrees(angle < Math.PI ? angle : 2 * Math.PI - angle); 305 305 } 306 306 … … 314 314 315 315 final double q = p * (p - a) * (p - b) * (p - c); // I found this negative in one case (:-o) when nodes were in line on a small area 316 316 return q < 0.0 ? 0.0 : Math.sqrt(q); 317 317 } 318 318 … … 327 327 public static double heading(final LatLon a, final LatLon b) { 328 328 double hd = Math.atan2(sin(toRadians(a.lon() - b.lon())) * cos(toRadians(b.lat())), 329 330 329 cos(toRadians(a.lat())) * sin(toRadians(b.lat())) - 330 sin(toRadians(a.lat())) * cos(toRadians(b.lat())) * cos(toRadians(a.lon() - b.lon()))); 331 331 hd %= 2 * Math.PI; 332 332 if (hd < 0) {
Note:
See TracChangeset
for help on using the changeset viewer.