Ticket #17616: projectionTests.patch

File projectionTests.patch, 5.6 KB (added by taylor.smock, 6 years ago)

Additional tests in different projections (3 projections + default projection, if different). Two tests currently fail.

  • test/unit/org/openstreetmap/josm/tools/GeometryTest.java

     
    2626import org.openstreetmap.josm.data.osm.RelationMember;
    2727import org.openstreetmap.josm.data.osm.Way;
    2828import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     29import org.openstreetmap.josm.data.projection.Projection;
     30import org.openstreetmap.josm.data.projection.ProjectionRegistry;
     31import org.openstreetmap.josm.data.projection.Projections;
    2932import org.openstreetmap.josm.io.OsmReader;
    3033import org.openstreetmap.josm.testutils.JOSMTestRules;
    3134
     
    265268
    266269    /**
    267270     * Test of {@link Geometry#getDistance} method.
     271     * TODO Replace with @ParameterizedTest and @ValueSource when we switch to
     272     * JUnit 5
    268273     */
    269274    @Test
    270     public void testGetDistance() {
     275    public void testGetDistanceProjection() {
     276        testGetDistance(ProjectionRegistry.getProjection());
     277        testGetDistance(Projections.getProjectionByCode("EPSG:3857"));
     278        testGetDistance(Projections.getProjectionByCode("EPSG:4326"));
     279        testGetClosestPrimitive(Projections.getProjectionByCode("EPSG:3395"));
     280    }
     281
     282    private void testGetDistance(Projection projection) throws AssertionError {
     283        ProjectionRegistry.setProjection(projection);
    271284        Node node1 = new Node(new LatLon(0, 0));
    272285        Node node2 = new Node(new LatLon(0.1, 1));
    273286        Node node3 = new Node(new LatLon(1.1, 0.1));
     
    316329
    317330    /**
    318331     * Test of {@link Geometry#getClosestPrimitive} method
     332     * TODO Replace with @ParameterizedTest and @ValueSource when we switch to
     333     * JUnit 5
    319334     */
    320335    @Test
    321     public void testGetClosestPrimitive() {
     336    public void testGetClosestPrimitiveProjections() {
     337        testGetClosestPrimitive(ProjectionRegistry.getProjection());
     338        testGetClosestPrimitive(Projections.getProjectionByCode("EPSG:3857"));
     339        testGetClosestPrimitive(Projections.getProjectionByCode("EPSG:4326"));
     340        testGetClosestPrimitive(Projections.getProjectionByCode("EPSG:3395"));
     341    }
     342
     343    private void testGetClosestPrimitive(Projection projection) throws AssertionError {
     344        ProjectionRegistry.setProjection(projection);
    322345        Node node1 = new Node(new LatLon(0, 0));
    323346        Node node2 = new Node(new LatLon(0.1, 1));
    324347        Node node3 = new Node(new LatLon(1.1, 0.1));
     
    335358
    336359    /**
    337360     * Test of {@link Geometry#getFurthestPrimitive} method
     361     * TODO Replace with @ParameterizedTest and @ValueSource when we switch to
     362     * JUnit 5
    338363     */
    339364    @Test
    340     public void testGetFurthestPrimitive() {
     365    public void testGetFurthestPrimitiveProjections() {
     366        testGetFurthestPrimitive(ProjectionRegistry.getProjection());
     367        testGetFurthestPrimitive(Projections.getProjectionByCode("EPSG:3857"));
     368        testGetFurthestPrimitive(Projections.getProjectionByCode("EPSG:4326"));
     369        testGetFurthestPrimitive(Projections.getProjectionByCode("EPSG:3395"));
     370    }
     371
     372    private void testGetFurthestPrimitive(Projection projection) throws AssertionError {
     373        ProjectionRegistry.setProjection(projection);
    341374        Node node1 = new Node(new LatLon(0, 0));
    342375        Node node2 = new Node(new LatLon(0, 1.1));
    343376        Node node3 = new Node(new LatLon(1, 0.1));
     
    350383        List<OsmPrimitive> primitives = new ArrayList<>();
    351384        primitives.add(way1);
    352385        OsmPrimitive furthest = Geometry.getFurthestPrimitive(new Node(new LatLon(0, 0.75)), primitives);
     386
    353387        assertEquals(way1, furthest);
    354388        primitives.add(way2);
    355389        primitives.add(way3);
     
    378412
    379413    /**
    380414     * Test of {@link Geometry#getDistanceSegmentSegment} method
     415     * TODO Replace with @ParameterizedTest and @ValueSource when we switch to
     416     * JUnit 5
    381417     */
    382418    @Test
    383     public void testGetDistanceSegmentSegment() {
     419    public void testGetDistanceSegmentSegmentProjections() {
     420        testGetDistanceSegmentSegment(ProjectionRegistry.getProjection());
     421        testGetDistanceSegmentSegment(Projections.getProjectionByCode("EPSG:3857"));
     422        testGetDistanceSegmentSegment(Projections.getProjectionByCode("EPSG:4326"));
     423        testGetDistanceSegmentSegment(Projections.getProjectionByCode("EPSG:3395"));
     424    }
     425
     426    private void testGetDistanceSegmentSegment(Projection projection) throws AssertionError {
     427        ProjectionRegistry.setProjection(projection);
    384428        Node node1 = new Node(new LatLon(2.0, 2.0));
    385429        Node node2 = new Node(new LatLon(2.0, 3.0));
    386430        Node node3 = new Node(new LatLon(2.3, 2.5));
     
    390434        assertEquals(0.0, Geometry.getDistanceSegmentSegment(node1, node2, node3, node1), 0.000001);
    391435
    392436        // distance between node 1 and node4 is the shortest
    393         double expected = node1.getEastNorth().distance(node4.getEastNorth());
     437        double expected = node1.getCoor().distance(node4.getCoor());
    394438        assertEquals(expected, Geometry.getDistanceSegmentSegment(node1, node2, node3, node4), 0.000001);
    395439
    396440        // crossing segments
     
    414458        // parallel segments, n1 and n3 at same longitude
    415459        node3.setCoor(new LatLon(2.1, 2.0));
    416460        node4.setCoor(new LatLon(2.1, 2.3));
    417         expected = node1.getEastNorth().distance(node3.getEastNorth());
     461        expected = node1.getCoor().distance(node3.getCoor());
    418462        assertEquals(expected, Geometry.getDistanceSegmentSegment(node1, node2, node3, node4), 0.000001);
    419463
    420464        // parallel segments