Changeset 19566 in josm


Ignore:
Timestamp:
2026-04-17T06:25:19+02:00 (3 hours ago)
Author:
GerdP
Message:

fix #24695: Unpredictable result when scaling or rotating an object again

  • change code to handle repeated scale or rotation

(patch 24695.patch without the additional check reg. moved nodes outside download area)

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r19556 r19566  
    5252import org.openstreetmap.josm.gui.MapView;
    5353import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
     54import org.openstreetmap.josm.gui.Notification;
    5455import org.openstreetmap.josm.gui.SelectionManager;
    5556import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
     
    793794                if (mode == Mode.ROTATE) {
    794795                    if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) {
    795                         ((RotateCommand) c).handleEvent(currentEN);
     796                        if (didMouseDrag) {
     797                            ((RotateCommand) c).handleEvent(currentEN);
     798                        } else {
     799                            ((RotateCommand) c).handleUpdate(currentEN);
     800                        }
    796801                    } else {
    797802                        UndoRedoHandler.getInstance().add(new RotateCommand(selection, currentEN));
     
    799804                } else if (mode == Mode.SCALE) {
    800805                    if (c instanceof ScaleCommand && affectedNodes.equals(((ScaleCommand) c).getTransformedNodes())) {
    801                         ((ScaleCommand) c).handleEvent(currentEN);
     806                        if (didMouseDrag) {
     807                            ((ScaleCommand) c).handleEvent(currentEN);
     808                        } else {
     809                            ((ScaleCommand) c).handleUpdate(currentEN);
     810                        }
    802811                    } else {
    803812                        UndoRedoHandler.getInstance().add(new ScaleCommand(selection, currentEN));
  • trunk/src/org/openstreetmap/josm/command/RotateCommand.java

    r17632 r19566  
    2626     * angle of rotation starting click to pivot
    2727     */
    28     private final double startAngle;
     28    private double startAngle;
    2929
    3030    /**
     
    3232     */
    3333    private double rotationAngle;
     34
     35    private double deltaAngle;
    3436
    3537    /**
     
    6668    public final void handleEvent(EastNorth currentEN) {
    6769        double currentAngle = getAngle(currentEN);
    68         rotationAngle = currentAngle - startAngle;
     70        rotationAngle = currentAngle - startAngle + deltaAngle;
    6971        transformNodes();
     72    }
     73
     74    /**
     75     * Handle a repeated rotation action where the mouse was moved to a different position
     76     * see #24695
     77     * @param startEN start cursor position of a repeated rotation
     78     */
     79    public void handleUpdate(EastNorth startEN) {
     80        deltaAngle = rotationAngle;
     81        startAngle = getAngle(startEN);
    7082    }
    7183
  • trunk/src/org/openstreetmap/josm/command/ScaleCommand.java

    r17632 r19566  
    2727
    2828    /**
     29     * scaling factor applied previously
     30     */
     31    private double deltaScalingFactor;
     32
     33    /**
    2934     * World position of the mouse when the user started the command.
    3035     */
    31     private final EastNorth startEN;
     36    private EastNorth startEN;
    3237
    3338    /**
     
    5863    @Override
    5964    public final void handleEvent(EastNorth currentEN) {
    60         double startAngle = Math.atan2(startEN.east()-pivot.east(), startEN.north()-pivot.north());
    61         double endAngle = Math.atan2(currentEN.east()-pivot.east(), currentEN.north()-pivot.north());
     65        setScalingFactor(deltaScalingFactor + calcScalingFactor(currentEN));
     66        transformNodes();
     67    }
     68
     69    /**
     70     * Handle a repeated scaling action where the mouse was moved to a different position
     71     * see #24695
     72     * @param newStartEN start cursor position of a repeated scaling
     73     */
     74    public void handleUpdate(EastNorth newStartEN) {
     75        startEN = newStartEN;
     76        deltaScalingFactor = scalingFactor - calcScalingFactor(newStartEN);
     77    }
     78
     79    private double calcScalingFactor(EastNorth currentEN) {
     80        double startAngle = Math.atan2(startEN.east() - pivot.east(), startEN.north() - pivot.north());
     81        double endAngle = Math.atan2(currentEN.east() - pivot.east(), currentEN.north() - pivot.north());
    6282        double startDistance = pivot.distance(startEN);
    6383        double currentDistance = pivot.distance(currentEN);
    64         setScalingFactor(Math.cos(startAngle-endAngle) * currentDistance / startDistance);
    65         transformNodes();
     84        return Math.cos(startAngle - endAngle) * currentDistance / startDistance;
    6685    }
    6786
Note: See TracChangeset for help on using the changeset viewer.