source: josm/trunk/src/org/openstreetmap/josm/command/RotateCommand.java@ 8392

Last change on this file since 8392 was 8392, checked in by Don-vip, 9 years ago

remove useless code (Method implemented with an exact copy of its superclass's method)

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.trn;
5
6import java.util.Collection;
7
8import org.openstreetmap.josm.data.coor.EastNorth;
9import org.openstreetmap.josm.data.osm.Node;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11
12/**
13 * RotateCommand rotates a number of objects around their centre.
14 *
15 * @author Frederik Ramm
16 */
17public class RotateCommand extends TransformNodesCommand {
18
19 /**
20 * Pivot point
21 */
22 private EastNorth pivot;
23
24 /**
25 * angle of rotation starting click to pivot
26 */
27 private double startAngle = 0.0;
28
29 /**
30 * computed rotation angle between starting click and current mouse pos
31 */
32 private double rotationAngle = 0.0;
33
34 /**
35 * Creates a RotateCommand.
36 * Assign the initial object set, compute pivot point and inital rotation angle.
37 */
38 public RotateCommand(Collection<OsmPrimitive> objects, EastNorth currentEN) {
39 super(objects);
40
41 pivot = getNodesCenter();
42 startAngle = getAngle(currentEN);
43 rotationAngle = 0.0;
44
45 handleEvent(currentEN);
46 }
47
48 /**
49 * Get angle between the horizontal axis and the line formed by the pivot and give points.
50 **/
51 protected final double getAngle(EastNorth currentEN) {
52 if ( pivot == null )
53 return 0.0; // should never happen by contract
54 return Math.atan2(currentEN.east()-pivot.east(), currentEN.north()-pivot.north());
55 }
56
57 /**
58 * Compute new rotation angle and transform nodes accordingly.
59 */
60 @Override
61 public final void handleEvent(EastNorth currentEN) {
62 double currentAngle = getAngle(currentEN);
63 rotationAngle = currentAngle - startAngle;
64 transformNodes();
65 }
66
67 /**
68 * Rotate nodes.
69 */
70 @Override
71 protected void transformNodes() {
72 for (Node n : nodes) {
73 double cosPhi = Math.cos(rotationAngle);
74 double sinPhi = Math.sin(rotationAngle);
75 EastNorth oldEastNorth = oldStates.get(n).getEastNorth();
76 double x = oldEastNorth.east() - pivot.east();
77 double y = oldEastNorth.north() - pivot.north();
78 double nx = cosPhi * x + sinPhi * y + pivot.east();
79 double ny = -sinPhi * x + cosPhi * y + pivot.north();
80 n.setEastNorth(new EastNorth(nx, ny));
81 }
82 }
83
84 @Override
85 public String getDescriptionText() {
86 return trn("Rotate {0} node", "Rotate {0} nodes", nodes.size(), nodes.size());
87 }
88}
Note: See TracBrowser for help on using the repository browser.