Ignore:
Timestamp:
2011-01-12T07:53:25+01:00 (14 years ago)
Author:
mzdila
Message:

indent with spaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java

    r25007 r25030  
    7676                Main.parent,
    7777                "<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                         + "<br>" + tr("This can lead to nodes being deleted accidentally.") + "<br>" + tr("Do you want to delete them anyway?") + "</html>",
     78                + "<br>" + tr("This can lead to nodes being deleted accidentally.") + "<br>" + tr("Do you want to delete them anyway?") + "</html>",
    7979                tr("Delete nodes outside of data regions?"), JOptionPane.WARNING_MESSAGE, null, // no special icon
    8080                options, options[0], null);
     
    168168     *            the way to simplify
    169169     */
    170         private SequenceCommand simplifyWay(final Way w) {
     170    private SequenceCommand simplifyWay(final Way w) {
    171171        final double angleThreshold = Main.pref.getDouble("simplify-area.angle.threshold", 10);
    172172        final double angleFactor = Main.pref.getDouble("simplify-area.angle.factor", 1.0);
     
    193193
    194194        while (true) {
    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);
     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);
    232232        }
    233233
     
    237237        final Map<Node, LatLon> coordMap = new HashMap<Node, LatLon>();
    238238        for (final Node n : nodes) {
    239                 coordMap.put(n, n.getCoor());
     239            coordMap.put(n, n.getCoor());
    240240        }
    241241
     
    243243
    244244        while (true) {
    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);
     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);
    277277        }
    278278
     
    301301
    302302    public static double computeConvectAngle(final LatLon coord1, final LatLon coord2, final LatLon coord3) {
    303         final double angle =  Math.abs(heading(coord2, coord3) - heading(coord1, coord2));
    304         return Math.toDegrees(angle < Math.PI ? angle : 2 * Math.PI - angle);
     303        final double angle =  Math.abs(heading(coord2, coord3) - heading(coord1, coord2));
     304        return Math.toDegrees(angle < Math.PI ? angle : 2 * Math.PI - angle);
    305305    }
    306306
     
    314314
    315315        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                 return q < 0.0 ? 0.0 : Math.sqrt(q);
     316        return q < 0.0 ? 0.0 : Math.sqrt(q);
    317317    }
    318318
     
    327327    public static double heading(final LatLon a, final LatLon b) {
    328328        double hd = Math.atan2(sin(toRadians(a.lon() - b.lon())) * cos(toRadians(b.lat())),
    329                         cos(toRadians(a.lat())) * sin(toRadians(b.lat())) -
    330                         sin(toRadians(a.lat())) * cos(toRadians(b.lat())) * cos(toRadians(a.lon() - b.lon())));
     329                cos(toRadians(a.lat())) * sin(toRadians(b.lat())) -
     330                sin(toRadians(a.lat())) * cos(toRadians(b.lat())) * cos(toRadians(a.lon() - b.lon())));
    331331        hd %= 2 * Math.PI;
    332332        if (hd < 0) {
Note: See TracChangeset for help on using the changeset viewer.