Ignore:
Timestamp:
2010-02-05T15:09:00+01:00 (14 years ago)
Author:
petrdlouhy
Message:

more refactoring
deleted old classes

Location:
applications/editors/josm/plugins/tracer/src
Files:
3 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerAction.java

    r19872 r19881  
    3636import org.openstreetmap.josm.data.osm.BBox;
    3737import org.openstreetmap.josm.data.osm.OsmPrimitive;
     38import org.openstreetmap.josm.tools.Pair;
    3839
    3940class TracerAction extends MapMode implements MouseListener {
     
    126127        List<Command> cmds = new LinkedList<Command>();
    127128        Way newWay = new Way(way);
    128         for (int i = 1; i < way.getNodesCount(); i++) {
    129             Node n = way.getNode(i);
     129        for (Node n : way.getNodes()) {
    130130            LatLon ll = n.getCoor();
    131131            BBox bbox = new BBox(
     
    153153            //System.out.println("-------");
    154154            if (nearestNode == null) {
    155                 tryConnectNodeToAnyWay(way, newWay, n, cmds);
     155                cmds.addAll(tryConnectNodeToAnyWay(n));
    156156            } else {
    157                 nearestNode.setCoor(ll.getCenter(nearestNode.getCoor()));
    158                 int j = newWay.getNodes().indexOf(n);
    159                 newWay.addNode(j, nearestNode);
    160                 if (j == 0) {
    161                     // first + last point
    162                     newWay.addNode(newWay.getNodesCount(), nearestNode);
    163                 }
    164                 newWay.removeNode(n);
    165                 cmds.add(new DeleteCommand(n));
    166             }
    167         }
    168         trySplitWayByAnyNodes(way, newWay);
     157                cmds.add(mergeNodes(nearestNode, n, newWay));
     158            }
     159        }
     160        newWay = trySplitWayByAnyNodes(way);
    169161
    170162        cmds.add(new ChangeCommand(way, newWay));
     
    175167
    176168    /**
    177      * Try connect node "node" from way "oldWay" to way of other building.
     169     * Merges two nodes
     170     * @param n1 First node
     171     * @param n2 Second node
     172     * @param way Way containing first node
     173     * @return Command
     174     */
     175    private Command mergeNodes(Node n1, Node n2, Way way){
     176        n2.setCoor(n1.getCoor().getCenter(n2.getCoor()));
     177        int j = way.getNodes().indexOf(n1);
     178        way.addNode(j, n2);
     179        if (j == 0) {
     180            // first + last point
     181            way.addNode(way.getNodesCount(), n2);
     182        }
     183        way.removeNode(n1);
     184        return new DeleteCommand(n1);
     185    }
     186
     187    /**
     188     * Try connect node "node" from way "way" to way of other building.
    178189     *
    179190     * Zkusi zjistit, zda node neni tak blizko nejake usecky existujici budovy,
    180191     * ze by mel byt zacnenen do teto usecky. Pokud ano, provede to.
    181192     *
    182      * @param oldWay Way which contains node "node".
    183      * @param newWay Modified way.
    184193     * @param node Node to connect.
    185      * @param cmds Command list.
    186194     * @throws IllegalStateException
    187195     * @throws IndexOutOfBoundsException
     196     * @return List of Commands.
    188197     */
    189     private void tryConnectNodeToAnyWay(Way oldWay, Way newWay, Node node, List<Command> cmds)
     198    private List<Command> tryConnectNodeToAnyWay(Node node)
    190199            throws IllegalStateException, IndexOutOfBoundsException {
    191 
     200       
    192201        final double MIN_DISTANCE = 0.000015;
     202        List<Command> cmds = new LinkedList<Command>();
    193203
    194204        LatLon ll = node.getCoor();
     
    206216        int nearestNodeIndex = 0;
    207217        for (Way ww : ways) {
    208             if (!ww.isUsable() || ww == oldWay || ww == newWay || !isBuilding(ww)) {
     218            if (!ww.isUsable() || ww.containsNode(node) || !isBuilding(ww)) {
    209219                continue;
    210220            }
    211             for (int nindex = 0; nindex < ww.getNodesCount(); nindex++) {
    212                 Node n1 = ww.getNode(nindex);
    213                 Node n2 = ww.getNode((nindex + 1) % ww.getNodesCount());
    214                 double dist = TracerGeometry.distanceFromSegment(ll, n1.getCoor(), n2.getCoor());
     221            for (Pair<Node, Node> np : ww.getNodePairs(false)) {
     222                double dist = TracerGeometry.distanceFromSegment(ll, np.a.getCoor(), np.b.getCoor());
    215223                if (dist < minDist) {
    216224                    minDist = dist;
    217225                    nearestWay = ww;
    218                     nearestNodeIndex = nindex;
     226                    nearestNodeIndex = ww.getNodes().indexOf(np.a);
    219227                }
    220228            }
     
    227235            cmds.add(new ChangeCommand(nearestWay, newNWay));
    228236        }
     237        return cmds;
    229238    }
    230239
     
    232241     * Try split way by any existing buiding nodes.
    233242     *
    234      * Zkusi zjistit zda nejake usecka z oldWay by nemela prochazet nejakym existujicim bodem,
     243     * Zkusi zjistit zda nejake usecka z way by nemela prochazet nejakym existujicim bodem,
    235244     * ktery je ji velmi blizko. Pokud ano, tak puvodni usecku rozdeli na dve tak, aby
    236245     * prochazela takovym bodem.
    237246     *
    238      * @param oldWay Way to split.
    239      * @param newWay Modified way.
     247     * @param way Way to split.
    240248     * @throws IndexOutOfBoundsException
    241249     * @throws IllegalStateException
     250     * @return Modified way
    242251     */
    243     private void trySplitWayByAnyNodes(Way oldWay, Way newWay)
     252    private Way trySplitWayByAnyNodes(Way way)
    244253            throws IndexOutOfBoundsException, IllegalStateException {
    245254
    246255        // projdi kazdou novou usecku a zjisti, zda by nemela vest pres existujici body
    247256        int i = 0;
    248         while (i < newWay.getNodesCount()) {
     257        while (i < way.getNodesCount()) {
    249258            // usecka n1, n2
    250             LatLon n1 = newWay.getNodes().get(i).getCoor();
    251             LatLon n2 = newWay.getNodes().get((i + 1) % newWay.getNodesCount()).getCoor();
    252             //System.out.println(newWay.getNodes().get(i) + "-----" + newWay.getNodes().get((i + 1) % newWay.getNodesCount()));
     259            LatLon n1 = way.getNodes().get(i).getCoor();
     260            LatLon n2 = way.getNodes().get((i + 1) % way.getNodesCount()).getCoor();
     261            //System.out.println(way.getNodes().get(i) + "-----" + way.getNodes().get((i + 1) % way.getNodesCount()));
    253262            double minDistanceSq = 0.000015;
    254263            double maxAngle = 15;
    255             List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox(Math.min(n1.getX(), n2.getX()) - minDistanceSq, Math.min(n1.getY(), n2.getY()) - minDistanceSq, Math.max(n1.getX(), n2.getX()) + minDistanceSq, Math.max(n1.getY(), n2.getY()) + minDistanceSq));
     264            List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox(
     265                Math.min(n1.getX(), n2.getX()) - minDistanceSq,
     266                Math.min(n1.getY(), n2.getY()) - minDistanceSq,
     267                Math.max(n1.getX(), n2.getX()) + minDistanceSq,
     268                Math.max(n1.getY(), n2.getY()) + minDistanceSq
     269            ));
    256270            Node nearestNode = null;
    257271            for (Node nod : nodes) {
    258                 if (!nod.isUsable() || oldWay.containsNode(nod) || newWay.containsNode(nod) || !isInBuilding(nod)) {
     272                if (!nod.isUsable() || way.containsNode(nod) || !isInBuilding(nod)) {
    259273                    continue;
    260274                }
     
    275289            } else {
    276290                // rozdeleni usecky
    277                 newWay.addNode(i + 1, nearestNode);
     291                way.addNode(i + 1, nearestNode);
    278292                continue; // i nezvetsuji, treba bude treba rozdelit usecku znovu
    279293            }
    280294        }
     295        return way;
    281296    }
    282297
    283298    private void tagBuilding(Way way) {
    284         way.put("building", "yes");
     299        if(alt) way.put("building", "yes");
    285300        way.put("source", "cuzk:km");
    286301    }
  • applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerGeometry.java

    r19867 r19881  
    4444        double r_numerator = (cx - ax) * (bx - ax) + (cy - ay) * (by - ay);
    4545        double r_denomenator = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
     46        if(r_denomenator == 0)System.out.println("r_denomenator == 0    ------------");
    4647        double r = r_numerator / r_denomenator;
    4748        double s = ((ay - cy) * (bx - ax) - (ax - cx) * (by - ay)) / r_denomenator;
  • applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerPlugin.java

    r19868 r19881  
    55 */
    66
    7 package tracer;
     7package org.openstreetmap.josm.plugins.tracer;
    88
    99import org.openstreetmap.josm.Main;
  • applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerServer.java

    r19867 r19881  
    4747     * @return Building border.
    4848     */
    49     public ArrayList<double[]> trace(LatLon pos) {
     49    public ArrayList<LatLon> trace(LatLon pos) {
    5050        try {
    5151            String content = callServer("trace/simple/" + pos.lat() + ";" + pos.lon());
    52             ArrayList<double[]> nodelist = new ArrayList<double[]>();
     52            ArrayList<LatLon> nodelist = new ArrayList<LatLon>();
    5353            String[] lines = content.split("\\|");
    5454            for (String line : lines) {
     
    5656                double x = Double.parseDouble(items[0]);
    5757                double y = Double.parseDouble(items[1]);
    58                 double[] d = new double[2];
    59                 d[0] = x;
    60                 d[1] = y;
    61                 nodelist.add(d);
     58                nodelist.add(new LatLon(x, y));
    6259            }
    6360            return nodelist;
    6461        } catch (Exception e) {
    65             ArrayList<double[]> nodelist = new ArrayList<double[]>();
    66             return nodelist;
     62            return new ArrayList<LatLon>();
    6763        }
    6864    }
Note: See TracChangeset for help on using the changeset viewer.