# Changeset 6894 in josm for trunk/src

Ignore:
Timestamp:
2014-03-02T14:51:43+01:00 (6 years ago)
Message:

applied #9605 - Align Nodes in Line moves outer node instead of middle one (patch by Balaitous)

File:
1 edited

Unmodified
Removed
• ## trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java

 r6893 } // the joy of single return values only... /** * Compute 2 anchor points to align a set of nodes. * If all nodes are part of a same way anchor points are choose farthest relative to this way, * else choose farthest nodes. * @param nodes Nodes to be aligned * @param resultOut Array of size >= 2 */ private void nodePairFurthestApart(List nodes, Node[] resultOut) { if(resultOut.length < 2) throw new IllegalArgumentException(); // Find from the selected nodes two that are the furthest apart. // Let's call them A and B. double distance = 0; Node nodea = null; Node nodeb = null; for (int i = 0; i < nodes.size()-1; i++) { Node n = nodes.get(i); for (int j = i+1; j < nodes.size(); j++) { Node m = nodes.get(j); double dist = Math.sqrt(n.getEastNorth().distance(m.getEastNorth())); if (dist > distance) { nodea = n; nodeb = m; distance = dist; // Intersection of all ways referred by each node HashSet waysRef = null; for(Node n: nodes) { Collection ref = OsmPrimitive.getFilteredList(n.getReferrers(), Way.class); if(waysRef == null) waysRef = new HashSet(ref); else waysRef.retainAll(ref); } if(waysRef.size() == 1) { // All nodes are part of the same way. See #9605 HashSet remainNodes = new HashSet(nodes); Way way = waysRef.iterator().next(); for(Node n: way.getNodes()) { if(!remainNodes.contains(n)) continue; if(nodea == null) nodea = n; if(remainNodes.size() == 1) { nodeb = remainNodes.iterator().next(); break; } remainNodes.remove(n); } } else { // Find from the selected nodes two that are the furthest apart. // Let's call them A and B. double distance = 0; for (int i = 0; i < nodes.size()-1; i++) { Node n = nodes.get(i); for (int j = i+1; j < nodes.size(); j++) { Node m = nodes.get(j); double dist = Math.sqrt(n.getEastNorth().distance(m.getEastNorth())); if (dist > distance) { nodea = n; nodeb = m; distance = dist; } } }
Note: See TracChangeset for help on using the changeset viewer.