Changeset 6411 in josm for trunk


Ignore:
Timestamp:
2013-11-25T02:03:59+01:00 (10 years ago)
Author:
Don-vip
Message:

allow to call SimplifyWayAction with a custom threshold

File:
1 edited

Legend:

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

    r6380 r6411  
    3535/**
    3636 * Delete unnecessary nodes from a way
     37 * @since 2575
    3738 */
    3839public class SimplifyWayAction extends JosmAction {
     
    110111            Collection<Command> allCommands = new LinkedList<Command>();
    111112            for (Way way: ways) {
    112                 SequenceCommand simplifyCommand = simplifyWay(way, ds);
     113                SequenceCommand simplifyCommand = simplifyWay(way);
    113114                if (simplifyCommand == null) {
    114115                    continue;
     
    152153
    153154    /**
    154      * Simplifies a way
     155     * Simplifies a way with default threshold (read from preferences).
    155156     *
    156157     * @param w the way to simplify
    157      */
    158     public SequenceCommand simplifyWay(Way w, DataSet ds) {
    159         double threshold = Main.pref.getDouble("simplify-way.max-error", 3.0);
     158     * @return The sequence of commands to run
     159     * @since 6411
     160     */
     161    public final SequenceCommand simplifyWay(Way w) {
     162        return simplifyWay(w, Main.pref.getDouble("simplify-way.max-error", 3.0));
     163    }
     164
     165    /**
     166     * Simplifies a way with a given threshold.
     167     *
     168     * @param w the way to simplify
     169     * @return The sequence of commands to run
     170     * @since 6411
     171     */
     172    public SequenceCommand simplifyWay(Way w, double threshold) {
    160173        int lower = 0;
    161174        int i = 0;
     
    163176        while(i < w.getNodesCount()){
    164177            if (isRequiredNode(w,w.getNode(i))) {
    165                 // copy a required node to the list of new nodes. Simplify not
    166                 // possible
     178                // copy a required node to the list of new nodes. Simplify not possible
    167179                newNodes.add(w.getNode(i));
    168180                i++;
     
    192204        cmds.add(new ChangeCommand(w, newWay));
    193205        cmds.add(new DeleteCommand(delNodes));
    194         ds.clearSelection(delNodes);
     206        w.getDataSet().clearSelection(delNodes);
    195207        return new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds);
    196208    }
Note: See TracChangeset for help on using the changeset viewer.