Changeset 11264 in josm for trunk


Ignore:
Timestamp:
2016-11-16T17:07:03+01:00 (8 years ago)
Author:
bastiK
Message:

refactor GeoProperty implementation of RightAndLefthandTraffic to generic separate class DefaultGeoProperty (see #10387)

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/GeoPropertyIndex.java

    r11259 r11264  
    1919 */
    2020public class GeoPropertyIndex<T> {
    21 
    22     /**
    23      * A method to look up a property of the earth surface.
    24      * (User input for the index.)
    25      * @param <T> the property
    26      */
    27     public interface GeoProperty<T> {
    28         /**
    29          * Look up the property for a point.
    30          * @param ll the point coordinates
    31          * @return property value at that point. Must not be null.
    32          */
    33         T get(LatLon ll);
    34 
    35         /**
    36          * Look up the property for a coordinate rectangle.
    37          * @param box the rectangle
    38          * @return the property, if it is the same in the entire rectangle;
    39          * null otherwise
    40          */
    41         T get(BBox box);
    42     }
    4321
    4422    private final int maxLevel;
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r11259 r11264  
    22package org.openstreetmap.josm.tools;
    33
    4 import java.awt.geom.Area;
    54import java.io.File;
    65import java.io.FileInputStream;
     
    2423import org.openstreetmap.josm.actions.PurgeAction;
    2524import org.openstreetmap.josm.data.coor.LatLon;
    26 import org.openstreetmap.josm.data.osm.BBox;
    2725import org.openstreetmap.josm.data.osm.DataSet;
    2826import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3432import org.openstreetmap.josm.io.OsmWriter;
    3533import org.openstreetmap.josm.io.OsmWriterFactory;
    36 import org.openstreetmap.josm.tools.GeoPropertyIndex.GeoProperty;
    37 import org.openstreetmap.josm.tools.Geometry.PolygonIntersection;
    3834
    3935/**
     
    4642    private static final String RIGHT = "right";
    4743
    48     private static class RLTrafficGeoProperty implements GeoProperty<Boolean> {
    49 
    50         @Override
    51         public Boolean get(LatLon ll) {
    52             for (Area a : leftHandTrafficPolygons) {
    53                 if (a.contains(ll.lon(), ll.lat()))
    54                     return Boolean.TRUE;
    55             }
    56             return Boolean.FALSE;
    57         }
    58 
    59         @Override
    60         public Boolean get(BBox box) {
    61             Area abox = new Area(box.toRectangle());
    62             for (Area a : leftHandTrafficPolygons) {
    63                 PolygonIntersection is = Geometry.polygonIntersection(abox, a, 1e-10 /* using deg and not meters */);
    64                 if (is == PolygonIntersection.FIRST_INSIDE_SECOND)
    65                     return Boolean.TRUE;
    66                 if (is != PolygonIntersection.OUTSIDE)
    67                     return null;
    68             }
    69             return Boolean.FALSE;
    70         }
    71     }
    72 
    73     static volatile Collection<Area> leftHandTrafficPolygons;
    74     static volatile GeoPropertyIndex<Boolean> rlCache;
     44    private static volatile GeoPropertyIndex<Boolean> rlCache;
    7545
    7646    private RightAndLefthandTraffic() {
     
    9363     */
    9464    public static synchronized void initialize() {
    95         leftHandTrafficPolygons = new ArrayList<>();
    9665        Collection<Way> optimizedWays = loadOptimizedBoundaries();
    9766        if (optimizedWays.isEmpty()) {
     
    9968            saveOptimizedBoundaries(optimizedWays);
    10069        }
    101         for (Way w : optimizedWays) {
    102             leftHandTrafficPolygons.add(Geometry.getAreaLatLon(w.getNodes()));
    103         }
    104         rlCache = new GeoPropertyIndex<>(new RLTrafficGeoProperty(), 24);
     70        rlCache = new GeoPropertyIndex<>(new DefaultGeoProperty(optimizedWays), 24);
    10571    }
    10672
Note: See TracChangeset for help on using the changeset viewer.