Changeset 9924 in josm for trunk/test


Ignore:
Timestamp:
2016-03-04T21:52:59+01:00 (4 years ago)
Author:
simon04
Message:

Add unit tests for OrthogonalizeAction - verify result

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/OrthogonalizeActionTest.java

    r9923 r9924  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions;
     3
     4import static junit.framework.Assert.assertEquals;
    35
    46import java.io.FileInputStream;
     
    911import org.openstreetmap.josm.TestUtils;
    1012import org.openstreetmap.josm.actions.search.SearchCompiler;
     13import org.openstreetmap.josm.data.coor.LatLon;
    1114import org.openstreetmap.josm.data.osm.DataSet;
     15import org.openstreetmap.josm.data.osm.Way;
    1216import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1317import org.openstreetmap.josm.io.OsmReader;
     18import org.openstreetmap.josm.tools.Geometry;
    1419import org.openstreetmap.josm.tools.Utils;
    1520
     
    3439    @Test
    3540    public void testClosedWay() throws Exception {
    36         performTest("name=ClosedWay");
     41        final DataSet ds = performTest("name=ClosedWay");
     42        final Way way = ds.getSelectedWays().iterator().next();
     43        assertEquals(new LatLon(8.538808176881814, 55.72978898396922), way.getNode(0).getCoor());
     44        assertEquals(new LatLon(8.539618224318104, 55.73039799489563), way.getNode(1).getCoor());
     45        assertEquals(new LatLon(8.538993302766201, 55.73124794515577), way.getNode(2).getCoor());
     46        assertEquals(new LatLon(8.538183254003354, 55.730638934229376), way.getNode(3).getCoor());
     47        verifyRectangleClockwise(way);
    3748    }
    3849
     
    4960    @Test
    5061    public void testClosedWayWithReferenceNodes() throws Exception {
    51         performTest("name=ClosedWayWithReferenceNodes");
     62        final DataSet ds = performTest("name=ClosedWayWithReferenceNodes");
     63        final Way way = ds.getSelectedWays().iterator().next();
     64        assertEquals(new LatLon(8.534711427, 55.73000670312), way.getNode(0).getCoor());
     65        assertEquals(new LatLon(8.53547720918594, 55.73067141759374), way.getNode(1).getCoor());
     66        assertEquals(new LatLon(8.534835495633061, 55.73142735279376), way.getNode(2).getCoor());
     67        assertEquals(new LatLon(8.53406971216, 55.73076263832), way.getNode(3).getCoor());
     68        verifyRectangleClockwise(way);
    5269    }
    5370
    54     void performTest(String search) throws Exception {
     71    DataSet performTest(String search) throws Exception {
    5572        try (FileInputStream in = new FileInputStream(TestUtils.getTestDataRoot() + "orthogonalize.osm")) {
    5673            final DataSet ds = OsmReader.parseDataSet(in, null);
    5774            ds.setSelected(Utils.filter(ds.allPrimitives(), SearchCompiler.compile(search)));
    58             OrthogonalizeAction.orthogonalize(ds.getSelected());
     75            OrthogonalizeAction.orthogonalize(ds.getSelected()).executeCommand();
     76            return ds;
     77        }
     78    }
     79
     80    void verifyRectangleClockwise(final Way way) {
     81        for (int i = 1; i < way.getNodesCount() - 1; i++) {
     82            assertEquals(-Math.PI / 2,  Geometry.getCornerAngle(
     83                    way.getNode(i - 1).getEastNorth(), way.getNode(i).getEastNorth(), way.getNode(i + 1).getEastNorth()), 1e-6);
    5984        }
    6085    }
Note: See TracChangeset for help on using the changeset viewer.