Changeset 18615 in josm for trunk/src/org


Ignore:
Timestamp:
2022-12-13T22:24:53+01:00 (17 months ago)
Author:
taylor.smock
Message:

Fix #22504: Circularize multiple selected ways (patch by qeef, modified)

File:
1 edited

Legend:

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

    r17416 r18615  
    150150     * Case 3: Only nodes are selected
    151151     * --> Align these nodes, all are fix
     152     * <p>
     153     * Case 4: Circularize selected ways
     154     * --&gt; Circularize each way of the selection.
    152155     * @param ds data set in which the command operates
    153156     * @return the resulting command to execute to perform action, or null if nothing was changed
     
    227230            fixNodes.addAll(onWay);
    228231            nodes = collectNodesAnticlockwise(ways);
     232        } else if (!ways.isEmpty() && selectedNodes.isEmpty()) {
     233            List<Command> rcmds = new LinkedList<>();
     234            for (Way w : ways) {
     235                if (!w.isDeleted() && w.isArea()) {
     236                    List<Node> wnodes = w.getNodes();
     237                    wnodes.remove(wnodes.size() - 1);
     238                    if (validateGeometry(wnodes)) {
     239                        center = Geometry.getCenter(wnodes);
     240                    }
     241                    if (center == null) {
     242                        continue;
     243                    }
     244                    boolean skipThisWay = false;
     245                    radius = 0;
     246                    for (Node n : wnodes) {
     247                        if (!n.isLatLonKnown()) {
     248                            skipThisWay = true;
     249                            break;
     250                        } else {
     251                            radius += center.distance(n.getEastNorth());
     252                        }
     253                    }
     254                    if (skipThisWay) {
     255                        continue;
     256                    } else {
     257                        radius /= wnodes.size();
     258                    }
     259                    Command c = moveNodesCommand(wnodes, Collections.emptySet(), center, radius);
     260                    if (c != null) {
     261                        rcmds.add(c);
     262                    }
     263                }
     264            }
     265            if (rcmds.isEmpty()) {
     266                throw new InvalidSelection();
     267            }
     268            return new SequenceCommand(tr("Align each Way in Circle"), rcmds);
    229269        } else {
    230270            throw new InvalidSelection();
     
    259299            radius = radius / nodes.size();
    260300        }
    261 
     301        return moveNodesCommand(nodes, fixNodes, center, radius);
     302    }
     303
     304    /**
     305     * Move each node of the list of nodes to be arranged in a circle.
     306     * @param nodes The list of nodes to be moved.
     307     * @param fixNodes The list of nodes that must not be moved.
     308     * @param center A center of the circle formed by the nodes.
     309     * @param radius A radius of the circle formed by the nodes.
     310     * @return the command that arranges the nodes in a circle.
     311     * @since 18615
     312     */
     313    public static Command moveNodesCommand(
     314            List<Node> nodes,
     315            Set<Node> fixNodes,
     316            EastNorth center,
     317            double radius) {
    262318        List<Command> cmds = new LinkedList<>();
    263319
Note: See TracChangeset for help on using the changeset viewer.