Changeset 18468 in josm


Ignore:
Timestamp:
2022-06-06T20:35:45+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #21893: Align movement of objects when the last selected way has two nodes and the ctrl/meta modifier is pressed (patch by cmuelle8, modified)

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

Legend:

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

    r18456 r18468  
    725725                MoveCommand moveCmd = null;
    726726                if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
     727                    EastNorth clampedEastNorth = currentEN;
     728                    if (platformMenuShortcutKeyMask) {
     729                        Way w = ds.getLastSelectedWay();
     730                        if (w != null && w.getNodesCount() == 2) {
     731                            double clamph = w.firstNode().getEastNorth().heading(w.lastNode().getEastNorth());
     732                            double dh = startEN.heading(currentEN, clamph);
     733                            switch ((int) (dh / (Math.PI/4))) {
     734                            case 1:
     735                            case 2:
     736                                dh -= Math.PI/2;
     737                                break;
     738                            case 3:
     739                            case 4:
     740                                dh += Math.PI;
     741                                break;
     742                            case 5:
     743                            case 6:
     744                                dh += Math.PI/2;
     745                                break;
     746                            }
     747                            clampedEastNorth = currentEN.rotate(startEN, -dh);
     748                        }
     749                    }
    727750                    moveCmd = (MoveCommand) c;
    728751                    moveCmd.saveCheckpoint();
    729                     moveCmd.applyVectorTo(currentEN);
     752                    moveCmd.applyVectorTo(clampedEastNorth);
    730753                } else if (!selection.isEmpty()) {
    731754                    moveCmd = new MoveCommand(selection, startEN, currentEN);
  • trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java

    r18342 r18468  
    142142    public double heading(EastNorth other) {
    143143        double hd = Math.atan2(other.east() - east(), other.north() - north());
     144        if (hd < 0) {
     145            hd = 2 * Math.PI + hd;
     146        }
     147        return hd;
     148    }
     149
     150    /**
     151     * Behaves exactly like {@link EastNorth#heading(EastNorth)} if {@code refHeading} is {@code 0.0},
     152     * otherwise gives a heading not relative to north (0.0).  It replies the radians needed to add to
     153     * {@code refHeading} to get from this EastNorth to another.
     154     * @param other the "destination" position
     155     * @param refHeading origin ("false" north if different from {@code 0.0})
     156     * @return heading with respect to {@code refHeading} as origin
     157     * @since 18468
     158     */
     159    public double heading(EastNorth other, double refHeading) {
     160        double hd = heading(other);
     161        hd -= refHeading;
    144162        if (hd < 0) {
    145163            hd = 2 * Math.PI + hd;
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r18200 r18468  
    601601    }
    602602
     603    /**
     604     * Returns the way selected last or null if no way primitives were selected or selection is empty.
     605     * @return last way in selection or null
     606     * @since 18468
     607     */
     608    public Way getLastSelectedWay() {
     609        Way lastWay = null;
     610        for (Way way: getSelectedWays()) lastWay = way;
     611        return lastWay;
     612    }
     613
    603614    @Override
    604615    public Collection<WaySegment> getHighlightedVirtualNodes() {
Note: See TracChangeset for help on using the changeset viewer.