Changeset 1636 in josm for trunk/src/org


Ignore:
Timestamp:
2009-06-06T13:38:32+02:00 (15 years ago)
Author:
stoecker
Message:

fix #2302 - patch by jttt - some code cleanup for better encapsulation

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

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

    r1415 r1636  
    1616import org.openstreetmap.josm.command.SequenceCommand;
    1717import org.openstreetmap.josm.data.coor.EastNorth;
    18 import org.openstreetmap.josm.data.coor.LatLon;
    1918import org.openstreetmap.josm.data.osm.Node;
    2019import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    135134        Collection<Node> nodes = new LinkedList<Node>();
    136135        Collection<Way> ways = new LinkedList<Way>();
    137         Node center = null;
     136        EastNorth center = null;
    138137        double radius = 0;
    139138        boolean regular = false;
     
    164163                } else {
    165164
    166                     center = (Node) nodes.toArray()[way.nodes.contains(nodes.toArray()[0]) ? 1 : 0];
     165                    center = ((Node) nodes.toArray()[way.nodes.contains(nodes.toArray()[0]) ? 1 : 0]).eastNorth;
    167166                    if (nodes.size() == 2)
    168167                        radius = distance(((Node) nodes.toArray()[0]).eastNorth, ((Node) nodes.toArray()[1]).eastNorth);
     
    184183        // Get average position of circumcircles of the triangles of all triplets of neighbour nodes
    185184        if (center == null) {
    186             center = new Node(new LatLon(0, 0));
    187             center.eastNorth = new EastNorth(0, 0); // to be independent of projection
     185            center = new EastNorth(0, 0);
    188186            Node n0 = (Node) nodes.toArray()[nodes.size() - 1];
    189187            Node n1 = (Node) nodes.toArray()[nodes.size() - 2];
     
    196194                if (cc == null)
    197195                    return;
    198                 center.eastNorth = new EastNorth(center.eastNorth.east() + cc.east(), center.eastNorth.north()
     196                center = new EastNorth(center.east() + cc.east(), center.north()
    199197                        + cc.north());
    200198            }
    201199
    202             center.eastNorth = new EastNorth(center.eastNorth.east() / nodes.size(), center.eastNorth.north()
     200            center = new EastNorth(center.east() / nodes.size(), center.north()
    203201                    / nodes.size());
    204             center.coor = Main.proj.eastNorth2latlon(center.eastNorth);
    205202        }
    206203
     
    212209        if (radius == 0) {
    213210            for (Node n : nodes) {
    214                 radius += distance(center.eastNorth, n.eastNorth);
     211                radius += distance(center, n.eastNorth);
    215212            }
    216213            radius = radius / nodes.size();
     
    223220        if (regular) { // Make a regular polygon
    224221            double angle = Math.PI * 2 / nodes.size();
    225             pc = new PolarCoor(((Node) nodes.toArray()[0]).eastNorth, center.eastNorth, 0);
    226 
    227             if (pc.angle > (new PolarCoor(((Node) nodes.toArray()[1]).eastNorth, center.eastNorth, 0).angle))
     222            pc = new PolarCoor(((Node) nodes.toArray()[0]).eastNorth, center, 0);
     223
     224            if (pc.angle > (new PolarCoor(((Node) nodes.toArray()[1]).eastNorth, center, 0).angle))
    228225                angle *= -1;
    229226
     
    236233        } else { // Move each node to that distance from the centre.
    237234            for (Node n : nodes) {
    238                 pc = new PolarCoor(n.eastNorth, center.eastNorth, 0);
     235                pc = new PolarCoor(n.eastNorth, center, 0);
    239236                pc.radius = radius;
    240237                EastNorth no = pc.toEastNorth();
  • trunk/src/org/openstreetmap/josm/actions/PasteAction.java

    r1592 r1636  
    1717import org.openstreetmap.josm.command.Command;
    1818import org.openstreetmap.josm.command.SequenceCommand;
     19import org.openstreetmap.josm.data.coor.EastNorth;
    1920import org.openstreetmap.josm.data.osm.DataSet;
    20 import org.openstreetmap.josm.data.osm.Relation;
    2121import org.openstreetmap.josm.data.osm.Node;
    2222import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.data.osm.Relation;
    2324import org.openstreetmap.josm.data.osm.RelationMember;
    2425import org.openstreetmap.josm.data.osm.Way;
    25 import org.openstreetmap.josm.data.coor.EastNorth;
    2626import org.openstreetmap.josm.gui.layer.Layer;
    2727import org.openstreetmap.josm.tools.Shortcut;
     
    7070            nnew.id = 0;
    7171            if (Main.main.editLayer() == source) {
    72                 nnew.eastNorth = new EastNorth(nnew.eastNorth.east() + offsetEast, nnew.eastNorth.north() + offsetNorth);
    73                 nnew.coor = Main.proj.eastNorth2latlon(nnew.eastNorth);
     72                nnew.setEastNorth(nnew.eastNorth.add(offsetEast, offsetNorth));
    7473            }
    7574            map.put(n, nnew);
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r1499 r1636  
    2121import org.openstreetmap.josm.command.Command;
    2222import org.openstreetmap.josm.command.SequenceCommand;
    23 import org.openstreetmap.josm.data.coor.EastNorth;
    2423import org.openstreetmap.josm.data.osm.Node;
    2524import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    149148        if(e.getSource() instanceof JPanel) {
    150149            MapView mv = Main.map.mapView;
    151             n.eastNorth = mv.getEastNorth(mv.lastMEvent.getX(), mv.lastMEvent.getY());
    152             n.coor = Main.proj.eastNorth2latlon(n.eastNorth);
     150            n.setEastNorth(mv.getEastNorth(mv.lastMEvent.getX(), mv.lastMEvent.getY()));
    153151        }
    154152       
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r1545 r1636  
    801801            // (for semi-parallel lines, intersection might be miles away!)
    802802            if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
    803                 n.eastNorth = intersection;
     803                n.setEastNorth(intersection);
    804804                return;
    805805            }
     
    814814            double c = A.distanceSq(B);
    815815            q = (a - b + c) / (2*c);
    816             n.eastNorth = new EastNorth(
    817                 B.east() + q * (A.east() - B.east()),
    818                 B.north() + q * (A.north() - B.north()));
     816            n.setEastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()));
    819817        }
    820818    }
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r1169 r1636  
    1515import javax.swing.tree.MutableTreeNode;
    1616
    17 import org.openstreetmap.josm.Main;
    1817import org.openstreetmap.josm.data.coor.EastNorth;
    1918import org.openstreetmap.josm.data.coor.LatLon;
     
    8887    public void moveAgain(double x, double y) {
    8988        for (Node n : objects) {
    90             n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y);
    91             n.coor = Main.proj.eastNorth2latlon(n.eastNorth);
     89            n.setEastNorth(n.eastNorth.add(x, y));
    9290        }
    9391        this.x += x;
     
    9795    @Override public boolean executeCommand() {
    9896        for (Node n : objects) {
    99             n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y);
    100             n.coor = Main.proj.eastNorth2latlon(n.eastNorth);
     97            n.setEastNorth(n.eastNorth.add(x, y));
    10198            n.modified = true;
    10299        }
     
    108105        for (Node n : objects) {
    109106            OldState os = it.next();
    110             n.eastNorth = os.eastNorth;
    111             n.coor = os.latlon;
     107            n.setEastNorth(os.eastNorth);
    112108            n.modified = os.modified;
    113109        }
  • trunk/src/org/openstreetmap/josm/command/RotateCommand.java

    r1169 r1636  
    1313import javax.swing.tree.MutableTreeNode;
    1414
    15 import org.openstreetmap.josm.Main;
    1615import org.openstreetmap.josm.data.coor.EastNorth;
    17 import org.openstreetmap.josm.data.coor.LatLon;
    1816import org.openstreetmap.josm.data.osm.Node;
    1917import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3634     * pivot point
    3735     */
    38     private Node pivot;
     36    private EastNorth pivot;
    3937
    4038    /**
     
    6260
    6361        this.objects = AllNodesVisitor.getAllNodes(objects);
    64         pivot = new Node(new LatLon(0,0));
    65         pivot.eastNorth = new EastNorth(0,0);
     62        pivot = new EastNorth(0,0);
    6663
    6764        for (Node n : this.objects) {
     
    7168            os.modified = n.modified;
    7269            oldState.put(n, os);
    73             pivot.eastNorth = new EastNorth(pivot.eastNorth.east()+os.eastNorth.east(), pivot.eastNorth.north()+os.eastNorth.north());
     70            pivot = pivot.add(os.eastNorth.east(), os.eastNorth.north());
    7471        }
    75         pivot.eastNorth = new EastNorth(pivot.eastNorth.east()/this.objects.size(), pivot.eastNorth.north()/this.objects.size());
    76         pivot.coor = Main.proj.eastNorth2latlon(pivot.eastNorth);
     72        pivot = new EastNorth(pivot.east()/this.objects.size(), pivot.north()/this.objects.size());
    7773
    7874        rotationAngle = Math.PI/2;
     
    8783    public void rotateAgain(EastNorth start, EastNorth end) {
    8884        // compute angle
    89         startAngle = Math.atan2(start.east()-pivot.eastNorth.east(), start.north()-pivot.eastNorth.north());
    90         double endAngle = Math.atan2(end.east()-pivot.eastNorth.east(), end.north()-pivot.eastNorth.north());
     85        startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north());
     86        double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north());
    9187        rotationAngle += startAngle - endAngle;
    9288        rotateNodes(false);
     
    10298            double sinPhi = Math.sin(rotationAngle);
    10399            EastNorth oldEastNorth = oldState.get(n).eastNorth;
    104             double x = oldEastNorth.east() - pivot.eastNorth.east();
    105             double y = oldEastNorth.north() - pivot.eastNorth.north();
    106             double nx =  sinPhi * x + cosPhi * y + pivot.eastNorth.east();
    107             double ny = -cosPhi * x + sinPhi * y + pivot.eastNorth.north();
    108             n.eastNorth = new EastNorth(nx, ny);
    109             n.coor = Main.proj.eastNorth2latlon(n.eastNorth);
     100            double x = oldEastNorth.east() - pivot.east();
     101            double y = oldEastNorth.north() - pivot.north();
     102            double nx =  sinPhi * x + cosPhi * y + pivot.east();
     103            double ny = -cosPhi * x + sinPhi * y + pivot.north();
     104            n.setEastNorth(nx, ny);
    110105            if (setModified)
    111106                n.modified = true;
     
    121116        for (Node n : objects) {
    122117            MoveCommand.OldState os = oldState.get(n);
    123             n.eastNorth = os.eastNorth;
    124             n.coor = os.latlon;
     118            n.setEastNorth(os.eastNorth);
    125119            n.modified = os.modified;
    126120        }
  • trunk/src/org/openstreetmap/josm/data/conflict/PositionConflict.java

    r1567 r1636  
    2323    @Override public void apply(OsmPrimitive target, OsmPrimitive other) {
    2424        if (target instanceof Node) {
    25             ((Node)target).coor = ((Node)other).coor;
    26             ((Node)target).eastNorth = ((Node)other).eastNorth;
     25            ((Node)target).setEastNorth(((Node)other).eastNorth);
    2726            int newversion = Math.max(target.version, other.version);
    2827            // set version on "other" as well in case user decides to keep local
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r1415 r1636  
    55
    66import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.data.coor.EastNorth;
    78import org.openstreetmap.josm.data.coor.LatLon;
    8 import org.openstreetmap.josm.data.coor.EastNorth;
    99import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
    1010import org.openstreetmap.josm.data.osm.visitor.Visitor;
     
    2020    public LatLon coor;
    2121    public volatile EastNorth eastNorth;
    22 
     22       
     23    public void setCoor(LatLon coor) {
     24        this.coor = coor;
     25        this.eastNorth = Main.proj.latlon2eastNorth(coor);
     26    }
     27       
     28    public void setEastNorth(EastNorth eastNorth) {
     29       this.eastNorth = eastNorth;
     30       this.coor = Main.proj.eastNorth2latlon(eastNorth);
     31    }
     32   
     33    public void setEastNorth(double east, double north) {
     34        this.setEastNorth(new EastNorth(east, north));
     35    }
     36   
    2337    private static CoordinateFormat mCord;
    2438
     
    4761
    4862    public Node(LatLon latlon) {
    49         this.coor = latlon;
    50         eastNorth = Main.proj.latlon2eastNorth(latlon);
     63        setCoor(latlon);
    5164    }
    5265
Note: See TracChangeset for help on using the changeset viewer.