Changeset 23478 in osm for applications
- Timestamp:
- 2010-10-05T20:00:42+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
r23193 r23478 164 164 * the way to simplify 165 165 */ 166 private SequenceCommand simplifyWay(final Way w) { 166 @SuppressWarnings("null") 167 private SequenceCommand simplifyWay(final Way w) { 167 168 final double angleThreshold = Double.parseDouble(Main.pref.get("simplify-area.angle", "10.0")); 168 169 final double distanceTreshold = Double.parseDouble(Main.pref.get("simplify-area.distance", "0.2")); … … 202 203 final LatLon coord2 = n2.getCoor(); 203 204 204 if (isRequiredNode(w, n1) || isRequiredNode(w, n2) || co mputeDistance(coord1,coord2) > distanceTreshold) {205 if (isRequiredNode(w, n1) || isRequiredNode(w, n2) || coord1.greatCircleDistance(coord2) > distanceTreshold) { 205 206 if (!closing) { 206 207 newNodes.add(n1); 207 208 } 208 209 } else { 209 moveCommandList.add(new MoveCommand(n2, new LatLon((coord1.lat() + coord2.lat()) / 2.0, (coord1.lon() + coord2.lon()) / 2.0)));210 moveCommandList.add(new MoveCommand(n2, coord1.getCenter(coord2))); 210 211 if (closing) { 211 212 newNodes.remove(0); … … 228 229 229 230 if (coord1 != null) { 231 // System.out.print("AREA: " + computeArea(coord1, coord2, coord3) + "; ANGLE: " + computeConvectAngle(coord1, coord2, coord3)); 230 232 if (isRequiredNode(w, prevNode) || 231 Math.abs(computeBearing(coord2, coord3) - computeBearing(coord1, coord2)) > angleThreshold || 233 !closed && i == len - 1 || // don't remove last node of the not closed way 234 computeConvectAngle(coord1, coord2, coord3) > angleThreshold || 232 235 computeArea(coord1, coord2, coord3) > areaTreshold) { 233 236 newNodes2.add(prevNode); 237 // System.out.println(" ... KEEP"); 234 238 } else { 239 // System.out.println(" ... REMOVE"); 235 240 coord2 = coord1; // at the end of the iteration preserve coord1 236 241 } … … 267 272 268 273 269 private double computeBearing(final LatLon coord1, final LatLon coord2) { 270 final double lon1 = Math.toRadians(coord1.getX()); 271 final double lat1 = Math.toRadians(coord1.getY()); 272 273 final double lon2 = Math.toRadians(coord2.getX()); 274 final double lat2 = Math.toRadians(coord2.getY()); 275 276 final double dLon = lon2 - lon1; 277 final double y = Math.sin(dLon) * Math.cos(lat2); 278 final double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon); 279 return Math.toDegrees(Math.atan2(y, x)); 280 } 281 282 283 private double computeDistance(final LatLon coord1, final LatLon coord2) { 284 final double lon1 = Math.toRadians(coord1.getX()); 285 final double lon2 = Math.toRadians(coord2.getX()); 286 final double lat1 = Math.toRadians(coord1.getY()); 287 final double lat2 = Math.toRadians(coord2.getY()); 288 289 final double R = 6378137d; // m 290 final double dLon = lon2 - lon1; 291 final double dLat = lat2 - lat1; 292 final double a = Math.sin(dLat / 2d) * Math.sin(dLat / 2d) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2d) * Math.sin(dLon / 2d); 293 final double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 294 return R * c; 295 } 274 public double computeConvectAngle(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 275 final double angle = Math.abs(coord2.heading(coord3) - coord1.heading(coord2)); 276 return Math.toDegrees(angle < Math.PI ? angle : 2 * Math.PI - angle); 277 } 278 296 279 297 280 298 281 private double computeArea(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 299 final double a = co mputeDistance(coord1,coord2);300 final double b = co mputeDistance(coord2,coord3);301 final double c = co mputeDistance(coord3,coord1);282 final double a = coord1.greatCircleDistance(coord2); 283 final double b = coord2.greatCircleDistance(coord3); 284 final double c = coord3.greatCircleDistance(coord1); 302 285 303 286 final double p = (a + b + c) / 2.0;
Note:
See TracChangeset
for help on using the changeset viewer.