Changeset 15730 in josm


Ignore:
Timestamp:
2020-01-19T14:14:46+01:00 (4 years ago)
Author:
simon04
Message:

fix #18561 - Add Geometry.filterInsideAnyPolygon (patch by taylor.smock, modified)

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r15717 r15730  
    343343                if (toCheck == null || toCheck.isEmpty())
    344344                    return;
    345 
    346                 if (e.osm instanceof IWay) {
    347                     for (IPrimitive p : Geometry.filterInsidePolygon(toCheck, (IWay<?>) e.osm)) {
    348                         addToChildren(e, p);
    349                     }
    350                 } else if (e.osm instanceof Relation && e.osm.isMultipolygon()) {
    351                     for (IPrimitive p : Geometry.filterInsideMultipolygon(toCheck, (Relation) e.osm)) {
    352                         addToChildren(e, p);
    353                     }
     345                for (IPrimitive p : Geometry.filterInsideAnyPolygon(toCheck, e.osm)) {
     346                    addToChildren(e, p);
    354347                }
    355348            }
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r15586 r15730  
    10431043    /**
    10441044     * Find all primitives in the given collection which are inside the given polygon.
     1045     *
     1046     * @param primitives the primitives
     1047     * @param polygon the closed way or multipolygon relation
     1048     * @return a new list containing the found primitives, empty if polygon is invalid or nothing was found.
     1049     * @see Geometry#filterInsidePolygon
     1050     * @see Geometry#filterInsideMultipolygon
     1051     * @since 15730
     1052     */
     1053    public static List<IPrimitive> filterInsideAnyPolygon(Collection<IPrimitive> primitives, IPrimitive polygon) {
     1054        if (polygon instanceof IWay<?>) {
     1055            return filterInsidePolygon(primitives, (IWay<?>) polygon);
     1056        } else if (polygon instanceof Relation && polygon.isMultipolygon()) {
     1057            return filterInsideMultipolygon(primitives, (Relation) polygon);
     1058        }
     1059        return Collections.emptyList();
     1060    }
     1061
     1062    /**
     1063     * Find all primitives in the given collection which are inside the given polygon.
    10451064     * Unclosed ways and multipolygon relations with unclosed outer rings are ignored.
     1065     *
    10461066     * @param primitives the primitives
    10471067     * @param polygon the polygon
    10481068     * @return a new list containing the found primitives, empty if polygon is invalid or nothing was found.
    1049      * @since 15069
    1050      */
    1051 
    1052     public static List<IPrimitive> filterInsidePolygon(List<IPrimitive> primitives, IWay<?> polygon) {
     1069     * @since 15069 (for {@link List} of {@code primitives}, 15730 for a {@link Collection} of {@code primitives})
     1070     */
     1071    public static List<IPrimitive> filterInsidePolygon(Collection<IPrimitive> primitives, IWay<?> polygon) {
    10531072        List<IPrimitive> res = new ArrayList<>();
    10541073        if (!polygon.isClosed() || polygon.getNodesCount() <= 3)
Note: See TracChangeset for help on using the changeset viewer.