Changeset 9878 in josm for trunk


Ignore:
Timestamp:
2016-02-24T23:24:31+01:00 (9 years ago)
Author:
simon04
Message:

see #11516 - Add Geometry unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/GeometryTest.java

    r8876 r9878  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import java.io.FileInputStream;
     5import java.util.List;
    36
    47import org.junit.Assert;
     
    69import org.junit.Test;
    710import org.openstreetmap.josm.JOSMFixture;
     11import org.openstreetmap.josm.TestUtils;
     12import org.openstreetmap.josm.actions.search.SearchCompiler;
    813import org.openstreetmap.josm.data.coor.EastNorth;
     14import org.openstreetmap.josm.data.osm.DataSet;
     15import org.openstreetmap.josm.data.osm.Way;
     16import org.openstreetmap.josm.io.OsmReader;
    917
    1018/**
     
    5260                Math.abs(scalarProduct/len1/len2) < 1e-10);
    5361    }
     62
     63    /**
     64     * Test of {@link Geometry#closedWayArea(org.openstreetmap.josm.data.osm.Way)} method.
     65     *
     66     * @throws Exception if an error occurs
     67     */
     68    @Test
     69    public void testClosedWayArea() throws Exception {
     70        try (FileInputStream in = new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm")) {
     71            DataSet ds = OsmReader.parseDataSet(in, null);
     72            Way closedWay = (Way) Utils.filter(ds.allPrimitives(), SearchCompiler.compile("landuse=forest")).iterator().next();
     73            Assert.assertEquals(5721923.660644531, Geometry.closedWayArea(closedWay), 1e-3);
     74        }
     75    }
     76
     77    /**
     78     * Test of {@link Geometry#getAreaAndPerimeter(List)} method.
     79     *
     80     * @throws Exception if an error occurs
     81     */
     82    @Test
     83    public void testAreaAndPerimeter() throws Exception {
     84        try (FileInputStream in = new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm")) {
     85            DataSet ds = OsmReader.parseDataSet(in, null);
     86            Way closedWay = (Way) Utils.filter(ds.allPrimitives(), SearchCompiler.compile("landuse=forest")).iterator().next();
     87            Geometry.AreaAndPerimeter areaAndPerimeter = Geometry.getAreaAndPerimeter(closedWay.getNodes());
     88            Assert.assertEquals(12495000., areaAndPerimeter.getArea(), 1e-3);
     89            Assert.assertEquals(15093.201209424187, areaAndPerimeter.getPerimeter(), 1e-3);
     90        }
     91    }
    5492}
Note: See TracChangeset for help on using the changeset viewer.