Ticket #20159: 20159-count-changes.patch

File 20159-count-changes.patch, 2.1 KB (added by GerdP, 3 years ago)
  • src/org/openstreetmap/josm/actions/SplitWayAction.java

     
    142142            sel.addAll(selectedWays);
    143143
    144144            final List<Way> newWays = SplitWayCommand.createNewWaysFromChunks(selectedWay, wayChunks);
    145             final Way wayToKeep = SplitWayCommand.Strategy.keepLongestChunk().determineWayToKeep(newWays);
     145            final Way wayToKeep = SplitWayCommand.smallestChangeset(selectedWay, newWays);
    146146
    147147            if (ExpertToggleAction.isExpert() && !selectedWay.isNew()) {
    148148                final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, sel);
  • src/org/openstreetmap/josm/command/SplitWayCommand.java

     
    427427        }
    428428    }
    429429
     430    /**
     431     * Calculate the best way
     432     * @param way the way to split
     433     * @param newWays potential new ways
     434     * @return the way to keep to reduce the number of changed relations
     435     * @since xxx
     436     */
     437    public static Way smallestChangeset(Way way, List<Way> newWays) {
     438        if (way.isNew())
     439            return Strategy.keepLongestChunk().determineWayToKeep(newWays);
     440        int bestCount = Integer.MAX_VALUE;
     441        Way wayToKeep = newWays.iterator().next();
     442        for (Way w : newWays) {
     443            Analysis res = analyseSplit(way, w, newWays);
     444            if (res.numberOfRelations < bestCount) {
     445                bestCount = res.numberOfRelations;
     446                wayToKeep = w;
     447            }
     448            res.cleanup();
     449        }
     450        return wayToKeep;
     451    }
     452
    430453    static Analysis analyseSplit(Way way,
    431454                                 Way wayToKeep,
    432455                                 List<Way> newWays) {