Changeset 23484 in osm for applications/editors/josm
- Timestamp:
- 2010-10-06T22:09:43+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java
r23480 r23484 167 167 * the way to simplify 168 168 */ 169 @SuppressWarnings("null")170 169 private SequenceCommand simplifyWay(final Way w) { 171 170 final double angleThreshold = Main.pref.getDouble("simplify-area.angle", 10); … … 191 190 } 192 191 193 { 194 // remove near nodes 195 for (int i = 0; i < size; i++) { 196 final boolean closing = closed && i == size - 1; 197 final Node n1 = closing ? nodes.get(0) : nodes.get(i); 198 199 if (newNodes.isEmpty()) { 192 // remove near nodes 193 for (int i = 0; i < size; i++) { 194 final boolean closing = closed && i == size - 1; 195 final Node n1 = closing ? nodes.get(0) : nodes.get(i); 196 197 if (newNodes.isEmpty()) { 198 newNodes.add(n1); 199 continue; 200 } 201 202 final Node n2 = newNodes.get(newNodes.size() - 1); 203 204 final LatLon coord1 = n1.getCoor(); 205 final LatLon coord2 = n2.getCoor(); 206 207 if (isRequiredNode(w, n1) || isRequiredNode(w, n2) || coord1.greatCircleDistance(coord2) > mergeThreshold) { 208 if (!closing) { 200 209 newNodes.add(n1); 201 continue;202 210 } 203 204 final Node n2 = newNodes.get(newNodes.size() - 1); 205 206 final LatLon coord1 = n1.getCoor(); 207 final LatLon coord2 = n2.getCoor(); 208 209 if (isRequiredNode(w, n1) || isRequiredNode(w, n2) || coord1.greatCircleDistance(coord2) > mergeThreshold) { 210 if (!closing) { 211 newNodes.add(n1); 212 } 213 } else { 214 moveCommandList.add(new MoveCommand(n2, coord1.getCenter(coord2))); 215 if (closing) { 216 newNodes.remove(0); 217 } 211 } else { 212 moveCommandList.add(new MoveCommand(n2, coord1.getCenter(coord2))); 213 if (closing) { 214 newNodes.remove(0); 218 215 } 219 216 } … … 233 230 234 231 if (coord1 != null) { 235 // System.out.print("AREA: " + computeArea(coord1, coord2, coord3) + "; ANGLE: " + computeConvectAngle(coord1, coord2, coord3) + "; XTE: "+crossTrackError(coord1, coord2, coord3));232 System.out.print("AREA: " + computeArea(coord1, coord2, coord3) + "; ANGLE: " + computeConvectAngle(coord1, coord2, coord3) + "; XTE: " + crossTrackError(coord1, coord2, coord3)); 236 233 if (isRequiredNode(w, prevNode) || 237 234 !closed && i == len - 1 || // don't remove last node of the not closed way … … 240 237 crossTrackError(coord1, coord2, coord3) > distanceThreshold) { 241 238 newNodes2.add(prevNode); 242 //System.out.println(" ... KEEP");239 System.out.println(" ... KEEP"); 243 240 } else { 244 //System.out.println(" ... REMOVE");241 System.out.println(" ... REMOVE"); 245 242 coord2 = coord1; // at the end of the iteration preserve coord1 246 243 } … … 278 275 279 276 public static double computeConvectAngle(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 280 final double angle = heading(coord2, coord3) - heading(coord1, coord2); 281 return Math.toDegrees(Math.abs(angle_mPI_to_PI(angle))); 282 } 283 284 285 286 private double computeArea(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 277 final double angle = Math.abs(heading(coord2, coord3) - heading(coord1, coord2)); 278 return Math.toDegrees(angle < Math.PI ? angle : 2 * Math.PI - angle); 279 } 280 281 282 public static double computeArea(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 287 283 final double a = coord1.greatCircleDistance(coord2); 288 284 final double b = coord2.greatCircleDistance(coord3); … … 293 289 return Math.sqrt(p * (p - a) * (p - b) * (p - c)); 294 290 } 295 291 292 296 293 public static double R = 6378135; 297 298 public static double crossTrackError(LatLon l1, LatLon l2, LatLon l3) { 299 return R*Math.asin(Math.sin(l1.greatCircleDistance(l2) / R) * Math.sin(heading(l1, l2) - heading(l1, l3))); 300 } 301 302 public static double heading(LatLon a, LatLon b) { 294 295 public static double crossTrackError(final LatLon l1, final LatLon l2, final LatLon l3) { 296 return R * Math.asin(sin(l1.greatCircleDistance(l2) / R) * sin(heading(l1, l2) - heading(l1, l3))); 297 } 298 299 300 public static double heading(final LatLon a, final LatLon b) { 303 301 double hd = Math.atan2(sin(toRadians(a.lon() - b.lon())) * cos(toRadians(b.lat())), 304 305 302 cos(toRadians(a.lat())) * sin(toRadians(b.lat())) - 303 sin(toRadians(a.lat())) * cos(toRadians(b.lat())) * cos(toRadians(a.lon() - b.lon()))); 306 304 hd %= 2 * Math.PI; 307 305 if (hd < 0) { … … 311 309 } 312 310 313 public static double angle_mPI_to_PI(double a) {314 a = a % (2 * Math.PI);315 if (a > Math.PI) {316 a -= 2 * Math.PI;317 }318 if (a <= - Math.PI) {319 a += 2 * Math.PI;320 }321 return a;322 }323 311 324 312 @Override
Note:
See TracChangeset
for help on using the changeset viewer.