Ignore:
Timestamp:
2011-10-12T09:22:23+02:00 (14 years ago)
Author:
zverik
Message:

Refactor, new splitting option

File:
1 edited

Legend:

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

    r26834 r26837  
    88import org.openstreetmap.josm.data.osm.*;
    99import org.openstreetmap.josm.tools.Geometry;
     10import org.openstreetmap.josm.tools.Geometry.PolygonIntersection;
    1011
    1112/**
     
    2829    }
    2930   
     31    public static boolean areAllOfThoseRings( Collection<Way> ways ) {
     32        List<Way> rings = new ArrayList<Way>();
     33        for( Way way : ways ) {
     34            if( way.isClosed() )
     35                rings.add(way);
     36            else
     37                return false;
     38        }
     39        if( rings.isEmpty() || ways.size() == 1 )
     40            return false;
     41
     42        // check for non-containment of rings
     43        for( int i = 0; i < rings.size() - 1; i++ ) {
     44            for( int j = i + 1; j < rings.size(); j++ ) {
     45                PolygonIntersection intersection = Geometry.polygonIntersection(rings.get(i).getNodes(), rings.get(j).getNodes());
     46                if( intersection == PolygonIntersection.FIRST_INSIDE_SECOND || intersection == PolygonIntersection.SECOND_INSIDE_FIRST )
     47                    return false;
     48            }
     49        }
     50
     51        return true;
     52    }
     53
     54    /**
     55     * Creates ALOT of Multipolygons and pets him gently.
     56     * @return list of new relations.
     57     */
     58    public static List<Relation> makeManySimpleMultipolygons( Collection<Way> selection, List<Command> commands ) {
     59        System.out.println("---------------------------------------");
     60        List<TheRing> rings = new ArrayList<TheRing>(selection.size());
     61        for( Way w : selection )
     62            rings.add(new TheRing(w));
     63        for( int i = 0; i < rings.size() - 1; i++ )
     64            for( int j = i + 1; j < rings.size(); j++ )
     65                rings.get(i).collide(rings.get(j));
     66        redistributeSegments(rings);
     67        List<Relation> relations = new ArrayList<Relation>();
     68        for( TheRing r : rings ) {
     69            commands.addAll(r.getCommands());
     70            relations.add(r.getRelation());
     71        }
     72        return relations;
     73    }
     74
    3075    public void collide( TheRing other ) {
    3176        boolean collideNoted = false;
Note: See TracChangeset for help on using the changeset viewer.