Ticket #24046: 24046.patch
| File 24046.patch, 5.7 KB (added by , 12 months ago) |
|---|
-
src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
Subject: [PATCH] 24046 --- IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
a b 3 3 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.Collections; 7 import java.util.HashMap; 6 8 import java.util.Iterator; 7 9 import java.util.List; 8 10 import java.util.Map; … … 10 12 11 13 import org.openstreetmap.josm.data.osm.DataSelectionListener; 12 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.osm.MultipolygonBuilder; 16 import org.openstreetmap.josm.data.osm.MultipolygonBuilder.JoinedPolygon; 17 import org.openstreetmap.josm.data.osm.MultipolygonBuilder.JoinedPolygonCreationException; 13 18 import org.openstreetmap.josm.data.osm.Node; 14 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 20 import org.openstreetmap.josm.data.osm.Relation; … … 34 39 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 35 40 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 36 41 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 42 import org.openstreetmap.josm.tools.Pair; 37 43 38 44 /** 39 45 * A memory cache for {@link Multipolygon} objects. … … 44 50 private static final MultipolygonCache INSTANCE = new MultipolygonCache(); 45 51 46 52 private final Map<DataSet, Map<Relation, Multipolygon>> cache = new ConcurrentHashMap<>(); // see ticket 11833 53 private final Map<DataSet, Map<Relation, Pair<List<JoinedPolygon>, List<JoinedPolygon>>>> wayCache = new HashMap<>(); 47 54 48 55 private final Collection<PolyData> selectedPolyData = new ArrayList<>(); 49 56 … … 102 109 return multipolygon; 103 110 } 104 111 112 /** 113 * Get joined ways for a relation 114 * @param r The relation to get the joined ways for 115 * @return The joined ways, see {@link MultipolygonBuilder#joinWays(Relation)} for details. 116 * @throws JoinedPolygonCreationException if the creation fails 117 * @since xxx 118 */ 119 public Pair<List<JoinedPolygon>, List<JoinedPolygon>> getWays(Relation r) throws JoinedPolygonCreationException { 120 return getWays(r, false); 121 } 122 123 /** 124 * Get joined ways for a relation 125 * @param r The relation to get the joined ways for 126 * @param forceRefresh {@code true} if a cached calculation should not be used 127 * @return The joined ways, see {@link MultipolygonBuilder#joinWays(Relation)} for details. 128 * @throws JoinedPolygonCreationException if the creation fails 129 * @since xxx 130 */ 131 public Pair<List<JoinedPolygon>, List<JoinedPolygon>> getWays(Relation r, boolean forceRefresh) throws JoinedPolygonCreationException { 132 if (r == null) { 133 return new Pair<>(Collections.emptyList(), Collections.emptyList()); 134 } else if (r.getDataSet() == null) { 135 return MultipolygonBuilder.joinWays(r); 136 } 137 Map<Relation, Pair<List<JoinedPolygon>, List<JoinedPolygon>>> tMap = wayCache.computeIfAbsent(r.getDataSet(), d -> new HashMap<>()); 138 if (forceRefresh || !tMap.containsKey(r)) { 139 Pair<List<JoinedPolygon>, List<JoinedPolygon>> outerInner = MultipolygonBuilder.joinWays(r); 140 tMap.put(r, outerInner); 141 return outerInner; 142 } 143 return tMap.get(r); 144 } 145 105 146 /** 106 147 * Clears the cache for the given dataset. 107 148 * @param ds the data set … … 111 152 if (map2 != null) { 112 153 map2.clear(); 113 154 } 155 Map<Relation, Pair<List<JoinedPolygon>, List<JoinedPolygon>>> map3 = wayCache.remove(ds); 156 if (map3 != null) { 157 map3.clear(); 158 } 114 159 } 115 160 116 161 /** … … 118 163 */ 119 164 public void clear() { 120 165 cache.clear(); 166 wayCache.clear(); 121 167 } 122 168 123 169 private Collection<Map<Relation, Multipolygon>> getMapsFor(DataSet ds) { -
src/org/openstreetmap/josm/tools/Geometry.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/tools/Geometry.java b/src/org/openstreetmap/josm/tools/Geometry.java
a b 1191 1191 if (polygonArea == null) { 1192 1192 polygonArea = getArea(polygon.getNodes()); 1193 1193 } 1194 Multipolygon mp = new Multipolygon((Relation) p);1194 Multipolygon mp = p.getDataSet() != null ? MultipolygonCache.getInstance().get((Relation) p) : new Multipolygon((Relation) p); 1195 1195 boolean inside = true; 1196 1196 // a (valid) multipolygon is inside the polygon if all outer rings are inside 1197 1197 for (PolyData outer : mp.getOuterPolygons()) { … … 1226 1226 1227 1227 final Pair<List<JoinedPolygon>, List<JoinedPolygon>> outerInner; 1228 1228 try { 1229 outerInner = Multipolygon Builder.joinWays(multiPolygon);1229 outerInner = MultipolygonCache.getInstance().getWays(multiPolygon); 1230 1230 } catch (MultipolygonBuilder.JoinedPolygonCreationException ex) { 1231 1231 Logging.trace(ex); 1232 1232 Logging.debug("Invalid multipolygon " + multiPolygon);
