Changeset 1169 in josm for trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
- Timestamp:
- 2008-12-23T15:07:05+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r1090 r1169 28 28 29 29 /** 30 * Align edges of a way so all angles are right angles. 31 * 30 * Align edges of a way so all angles are right angles. 31 * 32 32 * 1. Find orientation of all edges 33 33 * 2. Compute main orientation, weighted by length of edge, normalized to angles between 0 and pi/2 … … 38 38 public final class OrthogonalizeAction extends JosmAction { 39 39 40 public OrthogonalizeAction() {41 super(tr("Orthogonalize shape"), 42 "ortho", 40 public OrthogonalizeAction() { 41 super(tr("Orthogonalize shape"), 42 "ortho", 43 43 tr("Move nodes so all angles are 90 or 270deg"), 44 Shortcut.registerShortcut("tools:orthogonalize", tr("Tool: {0}", tr("Orthogonalize")), 45 KeyEvent.VK_Q, 44 Shortcut.registerShortcut("tools:orthogonalize", tr("Tool: {0}", tr("Orthogonalize")), 45 KeyEvent.VK_Q, 46 46 Shortcut.GROUP_EDIT), true); 47 }47 } 48 48 49 49 public void actionPerformed(ActionEvent e) { … … 60 60 JOptionPane.showMessageDialog(Main.parent, tr("Only two nodes allowed")); 61 61 return; 62 } 62 } 63 63 dirnodes.add((Node) osm); 64 64 continue; … … 68 68 JOptionPane.showMessageDialog(Main.parent, tr("Selection must consist only of ways.")); 69 69 return; 70 } 70 } 71 71 72 72 // Check if every way is made of at least four segments and closed … … 78 78 79 79 // Check if every edge in the way is a definite edge of at least 45 degrees of direction change 80 // Otherwise, two segments could be turned into same direction and intersection would fail. 80 // Otherwise, two segments could be turned into same direction and intersection would fail. 81 81 // Or changes of shape would be too serious. 82 82 for (int i1=0; i1 < way.nodes.size()-1; i1++) { … … 116 116 boolean use_dirnodes = false; 117 117 118 if (dirnodes.size() == 2) { 119 // When selection contains two nodes, use the nodes to compute a direction 118 if (dirnodes.size() == 2) { 119 // When selection contains two nodes, use the nodes to compute a direction 120 120 // to align all ways to 121 121 align_to_heading = normalize_angle(dirnodes.get(0).eastNorth.heading(dirnodes.get(1).eastNorth)); … … 124 124 125 125 for (OsmPrimitive osm : sel) { 126 if(!(osm instanceof Way)) 126 if(!(osm instanceof Way)) 127 127 continue; 128 128 … … 164 164 165 165 if (angle_diff_max > Math.PI/3) { 166 // rearrange headings: everything < 0 gets PI/2-rotated 166 // rearrange headings: everything < 0 gets PI/2-rotated 167 167 for (int i=0; i < sides; i++) { 168 if (headings[i] < 0) 168 if (headings[i] < 0) 169 169 headings[i] += Math.PI/2; 170 170 } … … 183 183 sum_weights += weights[i]; 184 184 } 185 align_to_heading = normalize_angle(sum_weighted_headings/sum_weights); 185 align_to_heading = normalize_angle(sum_weighted_headings/sum_weights); 186 186 } 187 187 188 188 189 189 for (int i=0; i < sides; i++) { 190 // Compute handy indices of three nodes to be used in one loop iteration. 191 // We use segments (i1,i2) and (i2,i3), align them and compute the new 190 // Compute handy indices of three nodes to be used in one loop iteration. 191 // We use segments (i1,i2) and (i2,i3), align them and compute the new 192 192 // position of the i2-node as the intersection of the realigned (i1,i2), (i2,i3) segments 193 193 // Not the most efficient algorithm, but we don't handle millions of nodes... … … 212 212 213 213 // compute intersection of segments 214 double u=det(B.east() - A.east(), B.north() - A.north(), 214 double u=det(B.east() - A.east(), B.north() - A.north(), 215 215 C.east() - D.east(), C.north() - D.north()); 216 216 217 217 // Check for parallel segments and do nothing if they are 218 // In practice this will probably only happen when a way has 218 // In practice this will probably only happen when a way has 219 219 // been duplicated 220 220 … … 225 225 // if the segment is scaled to length 1 226 226 227 double q = det(B.north() - C.north(), B.east() - C.east(), 227 double q = det(B.north() - C.north(), B.east() - C.east(), 228 228 D.north() - C.north(), D.east() - C.east()) / u; 229 229 EastNorth intersection = new EastNorth( … … 239 239 cmds.add(new MoveCommand(n, dx, dy)); 240 240 } 241 } 241 } 242 242 } 243 243
Note:
See TracChangeset
for help on using the changeset viewer.
