Changeset 1846 in josm


Ignore:
Timestamp:
Jul 25, 2009 7:33:56 PM (4 years ago)
Author:
jttt
Message:

Fix inefficient use of Collection in create circle/align circle

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    r1820 r1846  
    1010import java.util.Collection; 
    1111import java.util.LinkedList; 
     12import java.util.List; 
    1213 
    1314import javax.swing.JOptionPane; 
     
    8384 
    8485        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>(); 
    8788        EastNorth center = null; 
    8889        double radius = 0; 
     
    100101        // then use the way's nodes 
    101102        if ((nodes.size() <= 2) && (ways.size() == 1)) { 
    102             Way way = (Way) ways.toArray()[0]; 
     103            Way way = ways.get(0); 
    103104 
    104105            // some more special combinations: 
     
    111112            // distance between two nodes. 
    112113            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))) { 
    114115                    regular = true; 
    115116                } else { 
    116117 
    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(); 
    118119                    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()); 
    120121                    } 
    121122                } 
     
    144145            // See http://en.wikipedia.org/w/index.php?title=Centroid&oldid=294224857#Centroid_of_polygon for the equation used here 
    145146            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(); 
    148149 
    149150                BigDecimal x0 = new BigDecimal(n0.east()); 
     
    187188        if (regular) { // Make a regular polygon 
    188189            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)) { 
    192193                angle *= -1; 
    193194            } 
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r1820 r1846  
    88import java.util.Collection; 
    99import java.util.LinkedList; 
     10import java.util.List; 
    1011 
    1112import javax.swing.JOptionPane; 
    1213 
    1314import org.openstreetmap.josm.Main; 
     15import org.openstreetmap.josm.command.AddCommand; 
     16import org.openstreetmap.josm.command.ChangeCommand; 
    1417import org.openstreetmap.josm.command.Command; 
    15 import org.openstreetmap.josm.command.AddCommand; 
    1618import org.openstreetmap.josm.command.DeleteCommand; 
    17 import org.openstreetmap.josm.command.ChangeCommand; 
    1819import org.openstreetmap.josm.command.SequenceCommand; 
    1920import org.openstreetmap.josm.data.coor.EastNorth; 
     
    2122import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    2223import org.openstreetmap.josm.data.osm.Way; 
     24import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 
    2325import org.openstreetmap.josm.tools.Shortcut; 
    24  
    25 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 
    2626 
    2727/** 
     
    8484 
    8585        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 
    86         Collection<Node> nodes = new LinkedList<Node>(); 
     86        List<Node> nodes = new LinkedList<Node>(); 
    8787        Way existingWay = null; 
    8888 
     
    113113            // diameter: two single nodes needed or a way with two nodes 
    114114 
    115             Node   n1 = ((Node)nodes.toArray()[0]); 
     115            Node   n1 = nodes.get(0); 
    116116            double x1 = n1.getEastNorth().east(); 
    117117            double y1 = n1.getEastNorth().north(); 
    118             Node   n2 = ((Node)nodes.toArray()[1]); 
     118            Node   n2 = nodes.get(1); 
    119119            double x2 = n2.getEastNorth().east(); 
    120120            double y2 = n2.getEastNorth().north(); 
     
    187187 
    188188            // let's get some shorter names 
    189             Node   n1 = ((Node)nodes.toArray()[0]); 
     189            Node   n1 = nodes.get(0); 
    190190            double x1 = n1.getEastNorth().east(); 
    191191            double y1 = n1.getEastNorth().north(); 
    192             Node   n2 = ((Node)nodes.toArray()[1]); 
     192            Node   n2 = nodes.get(1); 
    193193            double x2 = n2.getEastNorth().east(); 
    194194            double y2 = n2.getEastNorth().north(); 
    195             Node   n3 = ((Node)nodes.toArray()[2]); 
     195            Node   n3 = nodes.get(2); 
    196196            double x3 = n3.getEastNorth().east(); 
    197197            double y3 = n3.getEastNorth().north(); 
Note: See TracChangeset for help on using the changeset viewer.