Changeset 26832 in osm for applications


Ignore:
Timestamp:
2011-10-11T21:03:06+02:00 (13 years ago)
Author:
zverik
Message:

working with arcs was a bad decision. Commit code before I rip all that out

Location:
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java

    r26802 r26832  
    1111import relcontext.ChosenRelationListener;
    1212
    13 public class DeleteChosenRelationAction extends AbstractAction implements ChosenRelationListener {
     13/**
     14 * Make a single polygon out of the multipolygon relation. The relation must have only outer members.
     15 * @author Zverik
     16 */
     17public class ReconstructPolygonAction extends AbstractAction implements ChosenRelationListener {
    1418    private ChosenRelation rel;
    1519
    16     public DeleteChosenRelationAction( ChosenRelation rel ) {
    17         super(tr("Delete relation"));
     20    public ReconstructPolygonAction( ChosenRelation rel ) {
     21        super(tr("Reconstruct polygon"));
    1822        putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     23        putValue(LONG_DESCRIPTION, "Reconstruct polygon from multipolygon relation");
    1924        this.rel = rel;
    2025        rel.addChosenRelationListener(this);
     
    2530        Relation r = rel.get();
    2631        rel.clear();
    27         Main.main.undoRedo.add(new DeleteCommand(r));
     32//        Main.main.undoRedo.add(new DeleteCommand(r));
    2833    }
    2934
    3035    public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
    31         setEnabled(newRelation != null);
     36        setEnabled(newRelation != null); //todo
    3237    }
    3338}
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java

    r26820 r26832  
    2626        segments.add(new RingSegment(source));
    2727    }
    28 
     28   
    2929    public void collide( TheRing other ) {
    3030        boolean collideNoted = false;
     
    3232            if( !segments.get(i).isReference() ) {
    3333                for( int j = 0; j < other.segments.size(); j++ ) {
    34                     // not colliding referencing nodes: they've already collided, and
    35                     // there should be no more than two ways passing through two points.
    3634                    if( !other.segments.get(j).isReference() ) {
    37                         List<Node> intersectionNodes = new ArrayList<Node>();
    38                         boolean colliding = false;
    39                         List<Node> nodes1 = segments.get(i).getNodes();
    40                         List<Node> nodes2 = other.segments.get(j).getNodes();
    41                         for( int ni = 0; ni < nodes2.size(); ni++ ) {
    42                             if( nodes1.contains(nodes2.get(ni)) != colliding ) {
    43                                 intersectionNodes.add(nodes2.get(colliding ? ni - 1 : ni));
    44                                 colliding = !colliding;
     35                        RingSegment seg1 = segments.get(i);
     36                        RingSegment seg2 = other.segments.get(j);
     37                        boolean firstSegmentIsNotARing = !seg1.isRing() && segments.size() == 1;
     38                        if( !seg2.isRing() && other.segments.size() == 1 ) {
     39                            if( firstSegmentIsNotARing )
     40                                break; // not doing two arcs collision
     41                            RingSegment tmp = seg1;
     42                            seg1 = seg2;
     43                            seg2 = tmp;
     44                            firstSegmentIsNotARing = true;
     45                        }
     46                        if( firstSegmentIsNotARing ) {
     47                            if( seg2.getNodes().contains(seg1.getNodes().get(0)) && seg2.getNodes().contains(seg1.getNodes().get(seg1.getNodes().size()-2))) {
     48                                // segment touches a ring
     49                           
    4550                            }
     51                        } else {
     52                            // both are segments from rings, find intersection
    4653                        }
    47                         if( colliding )
    48                             intersectionNodes.add(nodes2.get(nodes2.size() - 1));
    49                         // when an intersection of two rings spans a ring's beginning
    50                         if( segments.get(i).isRing() && other.segments.get(j).isRing() && intersectionNodes.contains(nodes2.get(0)) && intersectionNodes.contains(nodes2.get(nodes2.size() - 1)) ) {
    51                             intersectionNodes.remove(0);
    52                             intersectionNodes.remove(intersectionNodes.size() - 1);
    53                             intersectionNodes.add(intersectionNodes.get(0));
    54                             intersectionNodes.remove(0);
    55                         }
    56                         System.out.print("Intersection nodes for segments " + segments.get(i) + " and " + other.segments.get(j) + ": ");
    57                         for( Node inode : intersectionNodes )
    58                             System.out.print(inode.getUniqueId() + ",");
    59                         System.out.println();
    60                         // unclosed ways produce duplicate nodes
    61                         int ni = 1;
    62                         while( ni < intersectionNodes.size() ) {
    63                             if( intersectionNodes.get(ni - 1).equals(intersectionNodes.get(ni)) )
    64                                 intersectionNodes.remove(ni - 1);
    65                             else
    66                                 ni++;
    67                         }
    68                         if( intersectionNodes.size() > 1 ) {
     54                       
     55                       
     56                        Node[] intersection = getFirstIntersection(segments.get(i), other.segments.get(j));
     57                        if( intersection.length > 1 ) {
    6958                            if( !collideNoted ) {
    7059                                System.out.println("Rings for ways " + source.getUniqueId() + " and " + other.source.getUniqueId() + " collide.");
     
    7665                                other.segments.size() == 1 && !other.segments.get(0).isRing()
    7766                            };
    78                             RingSegment segment = splitRingAt(i, intersectionNodes.get(0), intersectionNodes.get(1));
    79                             RingSegment otherSegment = other.splitRingAt(j, intersectionNodes.get(0), intersectionNodes.get(1));
     67                            RingSegment segment = splitRingAt(i, intersection[0], intersection[1]);
     68                            RingSegment otherSegment = other.splitRingAt(j, intersection[0], intersection[1]);
    8069                            if( !isarc[0] && !isarc[1] ) {
    8170                                if( segments.size() > 2 && other.segments.size() > 2 )
     
    124113                        }
    125114                    }
     115                    if( segments.get(i).isReference() )
     116                        break;
    126117                }
    127                 if( segments.get(i).isReference() )
    128                     break;
    129             }
    130         }
     118            }
     119        }
     120    }
     121   
     122    private Node[] getFirstIntersection( RingSegment seg1, RingSegment seg2 ) {
     123        List<Node> intersectionNodes = new ArrayList<Node>();
     124        boolean colliding = false;
     125        List<Node> nodes1 = seg1.getNodes();
     126        List<Node> nodes2 = seg2.getNodes();
     127        for( int ni = 0; ni < nodes2.size(); ni++ ) {
     128            if( nodes1.contains(nodes2.get(ni)) != colliding ) {
     129                intersectionNodes.add(nodes2.get(colliding ? ni - 1 : ni));
     130                colliding = !colliding;
     131            }
     132        }
     133        if( colliding )
     134            intersectionNodes.add(nodes2.get(nodes2.size() - 1));
     135        // when an intersection of two rings spans a ring's beginning
     136        if( seg1.isRing() && seg2.isRing() && intersectionNodes.contains(nodes2.get(0)) && intersectionNodes.contains(nodes2.get(nodes2.size() - 1)) ) {
     137            intersectionNodes.remove(0);
     138            intersectionNodes.remove(intersectionNodes.size() - 1);
     139            intersectionNodes.add(intersectionNodes.get(0));
     140            intersectionNodes.remove(0);
     141        }
     142        System.out.print("Intersection nodes for segments " + seg1 + " and " + seg2 + ": ");
     143        for( Node inode : intersectionNodes )
     144            System.out.print(inode.getUniqueId() + ",");
     145        System.out.println();
     146        // unclosed ways produce duplicate nodes
     147        int ni = 1;
     148        while( ni < intersectionNodes.size() ) {
     149            if( intersectionNodes.get(ni - 1).equals(intersectionNodes.get(ni)) )
     150                intersectionNodes.remove(ni - 1);
     151            else
     152                ni++;
     153        }
     154        return intersectionNodes.toArray(new Node[2]);
    131155    }
    132156   
Note: See TracChangeset for help on using the changeset viewer.