Changeset 11481 in josm for trunk/src/org


Ignore:
Timestamp:
2017-01-18T09:04:51+01:00 (8 years ago)
Author:
Don-vip
Message:

sonar - squid:S3518 - Zero should not be a possible denominator

File:
1 edited

Legend:

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

    r11109 r11481  
    111111            return candidates.get(size - 1);
    112112        case 1:
    113             double east1 = 0, north1 = 0;
     113            double east1 = 0;
     114            double north1 = 0;
    114115            for (final Node n : candidates) {
    115116                EastNorth en = n.getEastNorth();
     
    132133            }
    133134
    134             double east2 = 0, north2 = 0, weight = 0;
     135            double east2 = 0;
     136            double north2 = 0;
     137            double weight = 0;
    135138            for (int i = 0; i < size; i++) {
    136139                final EastNorth en = candidates.get(i).getEastNorth();
     
    140143                weight += w;
    141144            }
     145
     146            if (weight == 0) // to avoid division by 0
     147                return candidates.get(0);
    142148
    143149            return new Node(new EastNorth(east2 / weight, north2 / weight));
Note: See TracChangeset for help on using the changeset viewer.