Changeset 19170 in josm


Ignore:
Timestamp:
2024-08-06T23:29:28+02:00 (4 months ago)
Author:
taylor.smock
Message:

Fix #23290: When an object is not in the appropriate region based off of the center of its bbox, check all the nodes.

This does not appear to have a significant performance impact; this may change as
more region specific presets are created.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r19080 r19170  
    3939import org.openstreetmap.josm.command.Command;
    4040import org.openstreetmap.josm.command.SequenceCommand;
     41import org.openstreetmap.josm.data.coor.ILatLon;
    4142import org.openstreetmap.josm.data.coor.LatLon;
    4243import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    4344import org.openstreetmap.josm.data.osm.DataSet;
     45import org.openstreetmap.josm.data.osm.INode;
     46import org.openstreetmap.josm.data.osm.IPrimitive;
     47import org.openstreetmap.josm.data.osm.IRelation;
     48import org.openstreetmap.josm.data.osm.IWay;
    4449import org.openstreetmap.josm.data.osm.Node;
    4550import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    806811    private void tagCheckReal(TaggingPreset preset, OsmPrimitive p, LatLon center, RegionSpecific data) {
    807812        // First, check if we aren't in the region for the tag
    808         if (latLonInRegions(center, data.regions()) == data.exclude_regions()) {
     813        if (latLonInRegions(center, data.regions()) == data.exclude_regions()
     814                // Check to ensure that no nodes are in the region if the center is not in the region
     815                && !primitiveInRegions(p, data.regions(), data.exclude_regions())) {
    809816            final String key;
    810817            final String value;
     
    840847
    841848    /**
     849     * Check if a primitive is in the specified regions
     850     * @param primitive The primitive to recursively check
     851     * @param regions The regions to look for
     852     * @param excludeRegions Whether or not we are looking to exclude the regions (see {@link RegionSpecific#exclude_regions()})
     853     * @return {@code true} if the primitive is in a region that it should not be
     854     */
     855    private static boolean primitiveInRegions(IPrimitive primitive, Collection<String> regions, boolean excludeRegions) {
     856        if (primitive instanceof INode) {
     857            return latLonInRegions((INode) primitive, regions) == excludeRegions;
     858        } else if (primitive instanceof IWay) {
     859            return ((IWay<?>) primitive).getNodes().stream().anyMatch(n -> primitiveInRegions(n, regions, excludeRegions));
     860        } else if (primitive instanceof IRelation) {
     861            return ((IRelation<?>) primitive).getMemberPrimitivesList().stream().anyMatch(p -> primitiveInRegions(p, regions, excludeRegions));
     862        }
     863        throw new IllegalArgumentException("Unknown primitive type: " + primitive);
     864    }
     865
     866    /**
    842867     * Check if the specified latlon is inside any of the specified regions
    843868     * @param latLon The {@link LatLon} to check
     
    845870     * @return {@code true} if the coordinate is inside any of the regions
    846871     */
    847     private static boolean latLonInRegions(LatLon latLon, Collection<String> regions) {
     872    private static boolean latLonInRegions(ILatLon latLon, Collection<String> regions) {
    848873        if (regions != null) {
    849874            for (String region : regions) {
    850                 if (Territories.isIso3166Code(region, latLon)) {
     875                if (Territories.isIso3166Code(region, latLon instanceof LatLon ? (LatLon) latLon : new LatLon(latLon))) {
    851876                    return true;
    852877                }
Note: See TracChangeset for help on using the changeset viewer.