Changeset 1846 in josm
- Timestamp:
- 2009-07-25T19:33:56+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
r1820 r1846 10 10 import java.util.Collection; 11 11 import java.util.LinkedList; 12 import java.util.List; 12 13 13 14 import javax.swing.JOptionPane; … … 83 84 84 85 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 85 Collection<Node> nodes = new LinkedList<Node>();86 Collection<Way> ways = new LinkedList<Way>();86 List<Node> nodes = new LinkedList<Node>(); 87 List<Way> ways = new LinkedList<Way>(); 87 88 EastNorth center = null; 88 89 double radius = 0; … … 100 101 // then use the way's nodes 101 102 if ((nodes.size() <= 2) && (ways.size() == 1)) { 102 Way way = (Way) ways.toArray()[0];103 Way way = ways.get(0); 103 104 104 105 // some more special combinations: … … 111 112 // distance between two nodes. 112 113 if (nodes.size() > 0) { 113 if (nodes.size() == 1 && way.nodes.contains(nodes. toArray()[0])) {114 if (nodes.size() == 1 && way.nodes.contains(nodes.get(0))) { 114 115 regular = true; 115 116 } else { 116 117 117 center = ((Node) nodes.toArray()[way.nodes.contains(nodes.toArray()[0]) ? 1 : 0]).getEastNorth();118 center = nodes.get(way.nodes.contains(nodes.get(0)) ? 1 : 0).getEastNorth(); 118 119 if (nodes.size() == 2) { 119 radius = distance( ((Node) nodes.toArray()[0]).getEastNorth(), ((Node) nodes.toArray()[1]).getEastNorth());120 radius = distance(nodes.get(0).getEastNorth(), nodes.get(1).getEastNorth()); 120 121 } 121 122 } … … 144 145 // See http://en.wikipedia.org/w/index.php?title=Centroid&oldid=294224857#Centroid_of_polygon for the equation used here 145 146 for (int i = 0; i < nodes.size(); i++) { 146 EastNorth n0 = ((Node) nodes.toArray()[i]).getEastNorth();147 EastNorth n1 = ((Node) nodes.toArray()[(i+1) % nodes.size()]).getEastNorth();147 EastNorth n0 = nodes.get(i).getEastNorth(); 148 EastNorth n1 = nodes.get((i+1) % nodes.size()).getEastNorth(); 148 149 149 150 BigDecimal x0 = new BigDecimal(n0.east()); … … 187 188 if (regular) { // Make a regular polygon 188 189 double angle = Math.PI * 2 / nodes.size(); 189 pc = new PolarCoor( ((Node) nodes.toArray()[0]).getEastNorth(), center, 0);190 191 if (pc.angle > (new PolarCoor( ((Node) nodes.toArray()[1]).getEastNorth(), center, 0).angle)) {190 pc = new PolarCoor(nodes.get(0).getEastNorth(), center, 0); 191 192 if (pc.angle > (new PolarCoor(nodes.get(1).getEastNorth(), center, 0).angle)) { 192 193 angle *= -1; 193 194 } -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r1820 r1846 8 8 import java.util.Collection; 9 9 import java.util.LinkedList; 10 import java.util.List; 10 11 11 12 import javax.swing.JOptionPane; 12 13 13 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.command.AddCommand; 16 import org.openstreetmap.josm.command.ChangeCommand; 14 17 import org.openstreetmap.josm.command.Command; 15 import org.openstreetmap.josm.command.AddCommand;16 18 import org.openstreetmap.josm.command.DeleteCommand; 17 import org.openstreetmap.josm.command.ChangeCommand;18 19 import org.openstreetmap.josm.command.SequenceCommand; 19 20 import org.openstreetmap.josm.data.coor.EastNorth; … … 21 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 23 25 import org.openstreetmap.josm.tools.Shortcut; 24 25 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;26 26 27 27 /** … … 84 84 85 85 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 86 Collection<Node> nodes = new LinkedList<Node>();86 List<Node> nodes = new LinkedList<Node>(); 87 87 Way existingWay = null; 88 88 … … 113 113 // diameter: two single nodes needed or a way with two nodes 114 114 115 Node n1 = ((Node)nodes.toArray()[0]);115 Node n1 = nodes.get(0); 116 116 double x1 = n1.getEastNorth().east(); 117 117 double y1 = n1.getEastNorth().north(); 118 Node n2 = ((Node)nodes.toArray()[1]);118 Node n2 = nodes.get(1); 119 119 double x2 = n2.getEastNorth().east(); 120 120 double y2 = n2.getEastNorth().north(); … … 187 187 188 188 // let's get some shorter names 189 Node n1 = ((Node)nodes.toArray()[0]);189 Node n1 = nodes.get(0); 190 190 double x1 = n1.getEastNorth().east(); 191 191 double y1 = n1.getEastNorth().north(); 192 Node n2 = ((Node)nodes.toArray()[1]);192 Node n2 = nodes.get(1); 193 193 double x2 = n2.getEastNorth().east(); 194 194 double y2 = n2.getEastNorth().north(); 195 Node n3 = ((Node)nodes.toArray()[2]);195 Node n3 = nodes.get(2); 196 196 double x3 = n3.getEastNorth().east(); 197 197 double y3 = n3.getEastNorth().north();
Note:
See TracChangeset
for help on using the changeset viewer.