From edf4ab3f7d1db7e5945ff78f37cc27baf8e7da8e Mon Sep 17 00:00:00 2001
From: Jiri Vlasak <jiri.hubacek@gmail.com>
Date: Mon, 14 Nov 2022 21:36:59 +0100
Subject: [PATCH 2/2] Add circularize selected ways code
---
.../josm/actions/AlignInCircleAction.java | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/src/org/openstreetmap/josm/actions/AlignInCircleAction.java b/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
index f3dec3f3db..c68886f6ab 100644
|
a
|
b
|
public final class AlignInCircleAction extends JosmAction {
|
| 149 | 149 | * <p> |
| 150 | 150 | * Case 3: Only nodes are selected |
| 151 | 151 | * --> Align these nodes, all are fix |
| | 152 | * <p> |
| | 153 | * Case 4: Circularize selected ways |
| | 154 | * --> Circularize each way of the selection. |
| 152 | 155 | * @param ds data set in which the command operates |
| 153 | 156 | * @return the resulting command to execute to perform action, or null if nothing was changed |
| 154 | 157 | * @throws InvalidSelection if selection cannot be used |
| … |
… |
public final class AlignInCircleAction extends JosmAction {
|
| 226 | 229 | } |
| 227 | 230 | fixNodes.addAll(onWay); |
| 228 | 231 | nodes = collectNodesAnticlockwise(ways); |
| | 232 | } else if (!ways.isEmpty() && selectedNodes.isEmpty()) { |
| | 233 | center = null; |
| | 234 | radius = 0; |
| | 235 | List<Command> rcmds = new LinkedList<>(); |
| | 236 | for (Way w : ways) { |
| | 237 | if (!w.isDeleted() && w.isArea()) { |
| | 238 | List<Node> wnodes = w.getNodes(); |
| | 239 | wnodes.remove(wnodes.size() - 1); |
| | 240 | if (validateGeometry(wnodes)) { |
| | 241 | center = Geometry.getCenter(wnodes); |
| | 242 | } |
| | 243 | if (center == null) { |
| | 244 | continue; |
| | 245 | } |
| | 246 | boolean skip_this_way = false; |
| | 247 | radius = 0; |
| | 248 | for (Node n : wnodes) { |
| | 249 | if (!n.isLatLonKnown()) { |
| | 250 | skip_this_way = true; |
| | 251 | break; |
| | 252 | } else { |
| | 253 | radius += center.distance(n.getEastNorth()); |
| | 254 | } |
| | 255 | } |
| | 256 | if (skip_this_way) { |
| | 257 | continue; |
| | 258 | } else { |
| | 259 | radius /= wnodes.size(); |
| | 260 | } |
| | 261 | Command c = moveNodesCommand( |
| | 262 | wnodes, new HashSet<Node>(), center, radius); |
| | 263 | if (c != null) { |
| | 264 | rcmds.add(c); |
| | 265 | } |
| | 266 | } |
| | 267 | } |
| | 268 | if (rcmds.isEmpty()) { |
| | 269 | return null; |
| | 270 | } |
| | 271 | return new SequenceCommand(tr("Align each Way in Circle"), rcmds); |
| 229 | 272 | } else { |
| 230 | 273 | throw new InvalidSelection(); |
| 231 | 274 | } |