Changeset 15069 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2019-05-11T11:15:49+02:00 (6 years ago)
Author:
GerdP
Message:

fix #17695

  • add support to find multipolygon inside polygon or multipolygon with ContainsFinder
  • add some unit tests
  • performance_1: improve isPolygonInsideMultiPolygon() by using the areas calculated

in MultipolygonBuilder.joinWays() instead of calling getArea() again.

  • performance_2: improve isPolygonInsideMultiPolygon() by first checking bounding boxes (helps with complex MP containing many inners as it avoids the Area.intersect() method)
  • performance_3: implement new methods to reuse result of complex method MultipolygonBuilder.joinWays() in ContainsFinder
Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r15064 r15069  
    339339        assertEquals(1, errors.size());
    340340    }
     341
     342    /**
     343     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/17695">Bug #17695</a>.
     344     * @throws Exception if an error occurs
     345     */
     346    @Test
     347    public void testTicket17695() throws Exception {
     348        final MapCSSTagChecker test = buildTagChecker(
     349                "*[building] ∈  *[building] {" +
     350                "throwWarning: tr(\"Building inside building\");" +
     351                "}");
     352        try (InputStream is = TestUtils.getRegressionDataStream(17695, "bib2.osm")) {
     353            test.visit(OsmReader.parseDataSet(is, null).allPrimitives());
     354            List<TestError> errors = test.getErrors();
     355            assertEquals(6, errors.size());
     356        }
     357    }
     358
    341359}
  • trunk/test/unit/org/openstreetmap/josm/tools/GeometryTest.java

    r15035 r15069  
    265265
    266266    /**
     267     * Test of {@link Geometry#filterInsideMultipolygon}
     268     */
     269    @Test
     270    public void testFilterInsideMultiPolygon() {
     271        Node node1 = new Node(new LatLon(1.01, 1.0));
     272        Node node2 = new Node(new LatLon(1.01, 1.1));
     273        Node node3 = new Node(new LatLon(1.02, 1.05));
     274        Way w1 = new Way();
     275        w1.setNodes(Arrays.asList(node1, node2, node3, node1));
     276        w1.put("building", "yes");
     277        Relation mp1 = new Relation();
     278        mp1.addMember(new RelationMember("outer", w1));
     279        mp1.put("type", "multipolygon");
     280
     281        Node node4 = new Node(new LatLon(1.0, 1.09));
     282        Node node5 = new Node(new LatLon(1.0, 1.12));
     283        Node node6 = new Node(new LatLon(1.1, 1.12));
     284        Node node7 = new Node(new LatLon(1.1, 1.09));
     285        Way outer = new Way();
     286        outer.setNodes(Arrays.asList(node4, node5, node6, node7, node4));
     287        Node node8 = new Node(new LatLon(1.04, 1.1));
     288        Node node9 = new Node(new LatLon(1.04, 1.11));
     289        Node node10 = new Node(new LatLon(1.06, 1.105));
     290        Way inner = new Way();
     291        inner.setNodes(Arrays.asList(node8, node9, node10, node8));
     292        Relation mp2 = new Relation();
     293        mp2.addMember(new RelationMember("outer", outer));
     294        mp2.addMember(new RelationMember("inner", inner));
     295        mp2.put("type", "multipolygon");
     296        assertFalse(Geometry.isPolygonInsideMultiPolygon(w1.getNodes(), mp2, null));
     297        assertFalse(Geometry.filterInsideMultipolygon(Arrays.asList(w1), mp2).contains(w1));
     298
     299        node4.setCoor(new LatLon(1.006, 0.99));
     300        // now w1 is inside
     301        assertTrue(Geometry.isPolygonInsideMultiPolygon(w1.getNodes(), mp2, null));
     302        assertTrue(Geometry.filterInsideMultipolygon(Arrays.asList(w1), mp2).contains(w1));
     303        assertTrue(Geometry.filterInsideMultipolygon(Arrays.asList(mp1), mp2).contains(mp1));
     304        assertTrue(Geometry.filterInsideMultipolygon(Arrays.asList(w1, mp1), mp2).contains(w1));
     305        assertTrue(Geometry.filterInsideMultipolygon(Arrays.asList(w1, mp1), mp2).contains(mp1));
     306    }
     307
     308    /**
    267309     * Test of {@link Geometry#getDistance} method.
    268310     */
Note: See TracChangeset for help on using the changeset viewer.