Changeset 8460 in josm


Ignore:
Timestamp:
2015-06-03T13:43:59+02:00 (9 years ago)
Author:
Don-vip
Message:

simplify usage of Way.firstNode()

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

Legend:

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

    r8419 r8460  
    147147        }
    148148
    149         if (ways.size() == 1 && ways.get(0).firstNode() != ways.get(0).lastNode()) {
     149        if (ways.size() == 1 && !ways.get(0).isClosed()) {
    150150            // Case 1
    151151            Way w = ways.get(0);
     
    379379    protected static boolean checkWaysArePolygon(Collection<Way> ways) {
    380380        // For each way, nodes strictly between first and last should't be reference by an other way
    381         for(Way way: ways) {
    382             for(Node node: way.getNodes()) {
    383                 if(node == way.firstNode() || node == way.lastNode()) continue;
    384                 for(Way wayOther: ways) {
    385                     if(way == wayOther) continue;
    386                     if(node.getReferrers().contains(wayOther)) return false;
     381        for (Way way: ways) {
     382            for (Node node: way.getNodes()) {
     383                if (way.isFirstLastNode(node)) continue;
     384                for (Way wayOther: ways) {
     385                    if (way == wayOther) continue;
     386                    if (node.getReferrers().contains(wayOther)) return false;
    387387                }
    388388            }
     
    392392        Node startNode = null, endNode = null;
    393393        int used = 0;
    394         while(true) {
     394        while (true) {
    395395            Way nextWay = null;
    396             for(Way w: ways) {
    397                 if(w.firstNode() == w.lastNode()) return ways.size() == 1;
    398                 if(w == currentWay) continue;
    399                 if(currentWay == null) {
     396            for (Way w: ways) {
     397                if (w.isClosed()) return ways.size() == 1;
     398                if (w == currentWay) continue;
     399                if (currentWay == null) {
    400400                    nextWay = w;
    401401                    startNode = w.firstNode();
     
    403403                    break;
    404404                }
    405                 if(w.firstNode() == endNode) {
     405                if (w.firstNode() == endNode) {
    406406                    nextWay = w;
    407407                    endNode = w.lastNode();
    408408                    break;
    409409                }
    410                 if(w.lastNode() == endNode) {
     410                if (w.lastNode() == endNode) {
    411411                    nextWay = w;
    412412                    endNode = w.firstNode();
     
    414414                }
    415415            }
    416             if(nextWay == null) return false;
     416            if (nextWay == null) return false;
    417417            used += 1;
    418418            currentWay = nextWay;
    419             if(endNode == startNode) return used == ways.size();
     419            if (endNode == startNode) return used == ways.size();
    420420        }
    421421    }
  • trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java

    r8459 r8460  
    235235        Set<Node> nodes = new HashSet<>();
    236236        Map<Way, Line> lines = new HashMap<>();
    237         for(Way w: ways) {
    238             if(w.firstNode() == w.lastNode())
     237        for (Way w: ways) {
     238            if (w.isClosed())
    239239                throw new InvalidSelection(tr("Can not align a polygon. Abort."));
    240240            nodes.addAll(w.getNodes());
     
    243243        Collection<Command> cmds = new ArrayList<>(nodes.size());
    244244        List<Way> referers = new ArrayList<>(ways.size());
    245         for(Node n: nodes) {
     245        for (Node n: nodes) {
    246246            referers.clear();
    247             for(OsmPrimitive o: n.getReferrers())
    248                 if(ways.contains(o))
     247            for (OsmPrimitive o: n.getReferrers())
     248                if (ways.contains(o))
    249249                    referers.add((Way) o);
    250             if(referers.size() == 1) {
     250            if (referers.size() == 1) {
    251251                Way way = referers.get(0);
    252                 if(n == way.firstNode() || n == way.lastNode()) continue;
     252                if (way.isFirstLastNode(n)) continue;
    253253                cmds.add(lines.get(way).projectionCommand(n));
    254             } else if(referers.size() == 2) {
     254            } else if (referers.size() == 2) {
    255255                Command cmd = lines.get(referers.get(0)).intersectionCommand(n, lines.get(referers.get(1)));
    256256                cmds.add(cmd);
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r8459 r8460  
    10701070        // Remove all of these way to make the next work.
    10711071        List<WayInPolygon> cleanMultigonWays = new ArrayList<>();
    1072         for(WayInPolygon way: multigonWays)
    1073             if(way.way.getNodesCount() == 2 && way.way.firstNode() == way.way.lastNode())
     1072        for (WayInPolygon way: multigonWays)
     1073            if (way.way.getNodesCount() == 2 && way.way.isClosed())
    10741074                discardedWays.add(way);
    10751075            else
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r8456 r8460  
    441441            return delete(layer, Collections.singleton(ws.way), false);
    442442
    443         if (ws.way.firstNode() == ws.way.lastNode()) {
    444             // If the way is circular (first and last nodes are the same),
    445             // the way shouldn't be splitted
     443        if (ws.way.isClosed()) {
     444            // If the way is circular (first and last nodes are the same), the way shouldn't be splitted
    446445
    447446            List<Node> n = new ArrayList<>();
     
    456455        }
    457456
    458         List<Node> n1 = new ArrayList<>(), n2 = new ArrayList<>();
     457        List<Node> n1 = new ArrayList<>();
     458        List<Node> n2 = new ArrayList<>();
    459459
    460460        n1.addAll(ws.way.getNodes().subList(0, ws.lowerIndex + 1));
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r8444 r8460  
    391391        boolean locked = writeLock();
    392392        try {
    393             boolean closed = lastNode() == firstNode() && selection.contains(lastNode());
     393            boolean closed = isClosed() && selection.contains(lastNode());
    394394            List<Node> copy = new ArrayList<>();
    395395
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSortUtils.java

    r7937 r8460  
    3434                w.getNode(1) != null &&
    3535                w.getNode(2) != null &&
    36                 w.firstNode() == w.lastNode()) {
     36                w.isClosed()) {
    3737            /** do some simple determinant / cross pruduct test on the first 3 nodes
    3838                to see, if the roundabout goes clock wise or ccw */
Note: See TracChangeset for help on using the changeset viewer.