Ignore:
Timestamp:
2010-02-17T08:17:23+01:00 (14 years ago)
Author:
jttt
Message:

Fix #4541 simplify way tool creates ways with duplicate nodes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r2976 r2999  
    88import java.awt.event.ActionEvent;
    99import java.awt.event.KeyEvent;
     10import java.util.ArrayList;
    1011import java.util.Collection;
    1112import java.util.Collections;
     
    216217        int lower = 0;
    217218        int i = 0;
    218         List<Node> newNodes = new LinkedList<Node>();
     219        List<Node> newNodes = new ArrayList<Node>(w.getNodesCount());
    219220        while(i < w.getNodesCount()){
    220221            if (isRequiredNode(w,w.getNode(i))) {
     
    232233            }
    233234            // ... and simplify them
    234             buildSimplifiedNodeList(w, lower, Math.min(w.getNodesCount()-1, i), threshold,newNodes);
     235            buildSimplifiedNodeList(w.getNodes(), lower, Math.min(w.getNodesCount()-1, i), threshold,newNodes);
    235236            lower=i;
    236237            i++;
     
    260261     * @param threshold
    261262     */
    262     protected void buildSimplifiedNodeList(Way wnew, int from, int to, double threshold, List<Node> simplifiedNodes) {
    263 
    264         Node fromN = wnew.getNode(from);
    265         Node toN = wnew.getNode(to);
    266 
     263    protected void buildSimplifiedNodeList(List<Node> wnew, int from, int to, double threshold, List<Node> simplifiedNodes) {
     264
     265        Node fromN = wnew.get(from);
     266        Node toN = wnew.get(to);
     267
     268        // Get max xte
    267269        int imax = -1;
    268270        double xtemax = 0;
    269271        for (int i = from + 1; i < to; i++) {
    270             Node n = wnew.getNode(i);
     272            Node n = wnew.get(i);
    271273            double xte = Math.abs(EARTH_RAD
    272274                    * xtd(fromN.getCoor().lat() * Math.PI / 180, fromN.getCoor().lon() * Math.PI / 180, toN.getCoor().lat() * Math.PI
     
    280282
    281283        if (imax != -1 && xtemax >= threshold) {
     284            // Segment cannot be simplified - try shorter segments
    282285            buildSimplifiedNodeList(wnew, from, imax,threshold,simplifiedNodes);
    283             simplifiedNodes.add(wnew.getNode(imax));
     286            //simplifiedNodes.add(wnew.get(imax));
    284287            buildSimplifiedNodeList(wnew, imax, to, threshold,simplifiedNodes);
    285288        } else {
     289            // Simplify segment
    286290            if (simplifiedNodes.isEmpty() || simplifiedNodes.get(simplifiedNodes.size()-1) != fromN) {
    287291                simplifiedNodes.add(fromN);
    288292            }
    289             if (simplifiedNodes.isEmpty() || simplifiedNodes.get(simplifiedNodes.size()-1) != toN) {
     293            if (fromN != toN) {
    290294                simplifiedNodes.add(toN);
    291295            }
Note: See TracChangeset for help on using the changeset viewer.