Changeset 18477 in josm


Ignore:
Timestamp:
2022-06-08T20:21:41+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix tests broken in r18473, see #22032

This was caused by vector tiles not always having points,
then ways, then polygons. The code now ensures that we
add points first, followed by ways, and finally by polygons.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/vector/VectorDataStore.java

    r18473 r18477  
    1717import java.util.Map;
    1818import java.util.Objects;
     19import java.util.stream.Collectors;
    1920
    2021import org.openstreetmap.gui.jmapviewer.Tile;
     
    2526import org.openstreetmap.josm.data.imagery.vectortile.VectorTile;
    2627import org.openstreetmap.josm.data.imagery.vectortile.mapbox.Feature;
     28import org.openstreetmap.josm.data.imagery.vectortile.mapbox.GeometryTypes;
    2729import org.openstreetmap.josm.data.imagery.vectortile.mapbox.Layer;
    2830import org.openstreetmap.josm.data.osm.BBox;
     
    294296        final Map<ILatLon, VectorNode> nodeMap = new HashMap<>();
    295297        for (Layer layer : tile.getLayers()) {
    296             for (Feature feature : layer.getFeatures()) {
    297                 try {
    298                     addFeatureData(tile, layer, feature, nodeMap);
    299                 } catch (IllegalArgumentException e) {
    300                     Logging.error("Cannot add vector data for feature {0} of tile {1}: {2}", feature, tile, e.getMessage());
    301                     Logging.error(e);
     298            Map<GeometryTypes, List<Feature>> grouped = layer.getFeatures().stream().collect(Collectors.groupingBy(Feature::getGeometryType));
     299            // Unknown -> Point -> LineString -> Polygon
     300            for (GeometryTypes type : GeometryTypes.values()) {
     301                if (grouped.containsKey(type)) {
     302                    addFeatureData(tile, layer, grouped.get(type), nodeMap);
    302303                }
    303304            }
     
    312313    }
    313314
     315    private <T extends Tile & VectorTile> void addFeatureData(T tile, Layer layer, Collection<Feature> features, Map<ILatLon, VectorNode> nodeMap) {
     316        for (Feature feature : features) {
     317            try {
     318                addFeatureData(tile, layer, feature, nodeMap);
     319            } catch (IllegalArgumentException e) {
     320                Logging.error("Cannot add vector data for feature {0} of tile {1}: {2}", feature, tile, e.getMessage());
     321                Logging.error(e);
     322            }
     323        }
     324    }
     325
    314326    private <T extends Tile & VectorTile> void addFeatureData(T tile, Layer layer, Feature feature, Map<ILatLon, VectorNode> nodeMap) {
    315327        // This will typically be larger than primaryFeatureObjects, but this at least avoids quite a few ArrayList#grow calls
    316328        List<VectorPrimitive> featureObjects = new ArrayList<>(feature.getGeometryObject().getShapes().size());
    317         List<VectorPrimitive> primaryFeatureObjects = new ArrayList<>(featureObjects.size());
     329        List<VectorPrimitive> primaryFeatureObjects = new ArrayList<>(feature.getGeometryObject().getShapes().size());
    318330        for (Shape shape : feature.getGeometryObject().getShapes()) {
    319331            primaryFeatureObjects.add(shapeToPrimaryFeatureObject(tile, layer, shape, featureObjects, nodeMap));
  • trunk/test/unit/org/openstreetmap/josm/data/vector/VectorDataSetTest.java

    r17862 r18477  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.vector;
     3
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertTrue;
     6
     7import java.nio.file.Paths;
     8import java.util.ArrayList;
     9import java.util.Collection;
     10import java.util.Collections;
     11import java.util.HashSet;
    312
    413import org.awaitility.Awaitility;
     
    1423import org.openstreetmap.josm.gui.layer.imagery.MVTLayer;
    1524import org.openstreetmap.josm.testutils.JOSMTestRules;
    16 
    17 import java.nio.file.Paths;
    18 import java.util.ArrayList;
    19 import java.util.Collection;
    20 import java.util.Collections;
    21 import java.util.HashSet;
    22 
    23 import static org.junit.jupiter.api.Assertions.assertEquals;
    24 import static org.junit.jupiter.api.Assertions.assertTrue;
    2525
    2626/**
  • trunk/test/unit/org/openstreetmap/josm/data/vector/VectorNodeTest.java

    r17867 r18477  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.vector;
     3
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertFalse;
     6import static org.junit.jupiter.api.Assertions.assertNotNull;
     7import static org.junit.jupiter.api.Assertions.assertSame;
     8import static org.junit.jupiter.api.Assertions.assertTrue;
     9import static org.junit.jupiter.api.Assertions.fail;
     10
     11import java.util.ArrayList;
     12import java.util.Collections;
     13import java.util.List;
    314
    415import org.junit.jupiter.api.Test;
     
    1526import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1627import org.openstreetmap.josm.testutils.JOSMTestRules;
    17 
    18 import java.util.ArrayList;
    19 import java.util.Collections;
    20 import java.util.List;
    21 
    22 import static org.junit.jupiter.api.Assertions.assertEquals;
    23 import static org.junit.jupiter.api.Assertions.assertFalse;
    24 import static org.junit.jupiter.api.Assertions.assertNotNull;
    25 import static org.junit.jupiter.api.Assertions.assertSame;
    26 import static org.junit.jupiter.api.Assertions.assertTrue;
    27 import static org.junit.jupiter.api.Assertions.fail;
    2828
    2929/**
     
    144144        assertSame(way, node.getReferrers(true).get(0));
    145145        // No dataset yet
     146        assertTrue(node.isReferredByWays(1));
     147        VectorDataSet dataSet = new VectorDataSet();
     148        dataSet.addPrimitive(node);
     149        // Way is not yet in dataset
    146150        assertFalse(node.isReferredByWays(1));
    147         VectorDataSet dataSet = new VectorDataSet();
    148151        dataSet.addPrimitive(way);
    149         dataSet.addPrimitive(node);
    150152        assertTrue(node.isReferredByWays(1));
    151153        assertFalse(node.isReferredByWays(2));
Note: See TracChangeset for help on using the changeset viewer.