Ignore:
Timestamp:
2011-03-10T22:28:29+01:00 (14 years ago)
Author:
mzdila
Message:

fixed node weight cache using index + 1

File:
1 edited

Legend:

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

    r25488 r25560  
    316316
    317317    private void addNodesToDelete(final Collection<Node> nodesToDelete, final Way w) {
    318 //        System.out.println("---------------- " + w.getId());
    319 
    320318        final double angleThreshold = Main.pref.getDouble("simplify-area.angle.threshold", 10);
    321319        final double angleFactor = Main.pref.getDouble("simplify-area.angle.factor", 1.0);
     
    346344
    347345        while (true) {
    348 //            System.out.println(nodes.size());
    349346            Node prevNode = null;
    350347            LatLon coord1 = null;
    351348            LatLon coord2 = null;
     349            int prevIndex = -1;
    352350
    353351            double minWeight = Double.MAX_VALUE;
    354352            Node bestMatch = null;
    355353
    356             for (int i = 0, len = nodes.size() + (closed ? 2 : 1); i < len; i++) {
    357                 final int index = i % nodes.size();
     354            final int size2 = nodes.size();
     355
     356            for (int i = 0, len = size2 + (closed ? 2 : 1); i < len; i++) {
     357                final int index = i % size2;
    358358
    359359                final Node n = nodes.get(index);
     
    363363                    final double weight;
    364364
    365                     if (weightList.get(index) == null) {
     365                    if (weightList.get(prevIndex) == null) {
    366366                        final double angleWeight = computeConvectAngle(coord1, coord2, coord3) / angleThreshold;
    367367                        final double areaWeight = computeArea(coord1, coord2, coord3) / areaThreshold;
    368368                        final double distanceWeight = Math.abs(crossTrackError(coord1, coord2, coord3)) / distanceThreshold;
    369369
    370                         weight = /*isRequiredNode(w, prevNode, minUse) ||*/
    371                         !closed && i == len - 1 || // don't remove last node of the not closed way
    372                         angleWeight > 1.0 || areaWeight > 1.0 || distanceWeight > 1.0 ? Double.MAX_VALUE :
    373                             angleWeight * angleFactor + areaWeight * areaFactor + distanceWeight * distanceFactor;
    374 
    375                         weightList.set(index, weight);
     370                        weight = !closed && i == len - 1 || // don't remove last node of the not closed way
     371                                angleWeight > 1.0 || areaWeight > 1.0 || distanceWeight > 1.0 ? Double.MAX_VALUE :
     372                                angleWeight * angleFactor + areaWeight * areaFactor + distanceWeight * distanceFactor;
     373
     374                        weightList.set(prevIndex, weight);
    376375                    } else {
    377                         weight = weightList.get(index);
     376                        weight = weightList.get(prevIndex);
    378377                    }
    379378
     
    387386                coord2 = coord3;
    388387                prevNode = n;
     388                prevIndex = index;
    389389            }
    390390
     
    395395            final int index = nodes.indexOf(bestMatch);
    396396
    397             final int size2 = nodes.size();
    398397            weightList.set((index - 1 + size2) % size2, null);
    399398            weightList.set((index + 1 + size2) % size2, null);
Note: See TracChangeset for help on using the changeset viewer.