Changeset 13670 in josm


Ignore:
Timestamp:
2018-04-23T23:13:03+02:00 (4 weeks ago)
Author:
Don-vip
Message:

fix #16189 - Add "almost square check" for buildings (patch by marxin, modified)

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r13434 r13670  
    188188     * @return a rectifying command
    189189     * @throws InvalidUserInputException if the selection is invalid
    190      */
    191     static SequenceCommand orthogonalize(Iterable<OsmPrimitive> selection) throws InvalidUserInputException {
     190     * @since 13670
     191     */
     192    public static SequenceCommand orthogonalize(Iterable<OsmPrimitive> selection) throws InvalidUserInputException {
    192193        final List<Node> nodeList = new ArrayList<>();
    193194        final List<WayData> wayDataList = new ArrayList<>();
     
    619620    /**
    620621     * Exception: unsuited user input
    621      */
    622     protected static class InvalidUserInputException extends Exception {
     622     * @since 13670
     623     */
     624    public static final class InvalidUserInputException extends Exception {
    623625        InvalidUserInputException(String message) {
    624626            super(message);
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r13665 r13670  
    1616import org.openstreetmap.josm.spi.preferences.Config;
    1717import org.openstreetmap.josm.tools.CopyList;
     18import org.openstreetmap.josm.tools.Geometry;
    1819import org.openstreetmap.josm.tools.Pair;
    1920import org.openstreetmap.josm.tools.Utils;
     
    780781        }
    781782    }
     783
     784    /**
     785     * Returns angles of vertices.
     786     * @return angles of the way
     787     * @since 13670
     788     */
     789    public synchronized List<Pair<Double, Node>> getAngles() {
     790        List<Pair<Double, Node>> angles = new ArrayList<>();
     791
     792        for (int i = 1; i < nodes.length - 1; i++) {
     793            Node n0 = nodes[i - 1];
     794            Node n1 = nodes[i];
     795            Node n2 = nodes[i + 1];
     796
     797            double angle = Geometry.getNormalizedAngleInDegrees(Geometry.getCornerAngle(
     798                    n0.getEastNorth(), n1.getEastNorth(), n2.getEastNorth()));
     799            angles.add(new Pair<>(angle, n1));
     800        }
     801
     802        angles.add(new Pair<>(Geometry.getNormalizedAngleInDegrees(Geometry.getCornerAngle(
     803                nodes[nodes.length - 2].getEastNorth(),
     804                nodes[0].getEastNorth(),
     805                nodes[1].getEastNorth())), nodes[0]));
     806
     807        return angles;
     808    }
    782809}
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r13647 r13670  
    5353import org.openstreetmap.josm.data.validation.tests.PublicTransportRouteTest;
    5454import org.openstreetmap.josm.data.validation.tests.RelationChecker;
     55import org.openstreetmap.josm.data.validation.tests.RightAngleBuildingTest;
    5556import org.openstreetmap.josm.data.validation.tests.SelfIntersectingWay;
    5657import org.openstreetmap.josm.data.validation.tests.SimilarNamedWays;
     
    141142        LongSegment.class, // 3500 .. 3599
    142143        PublicTransportRouteTest.class, // 3600 .. 3699
     144        RightAngleBuildingTest.class, // 3700 .. 3799
    143145    };
    144146
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r13638 r13670  
    794794
    795795        return result;
     796    }
     797
     798    /**
     799     * Get angles in radians and return it's value in range [0, 180].
     800     *
     801     * @param angle the angle in radians
     802     * @return normalized angle in degrees
     803     * @since 13670
     804     */
     805    public static double getNormalizedAngleInDegrees(double angle) {
     806        return Math.abs(180 * angle / Math.PI);
    796807    }
    797808
  • trunk/test/unit/org/openstreetmap/josm/tools/GeometryTest.java

    r12656 r13670  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import static org.junit.Assert.assertEquals;
    35
    46import java.io.FileInputStream;
     
    1012import org.openstreetmap.josm.TestUtils;
    1113import org.openstreetmap.josm.data.coor.EastNorth;
     14import org.openstreetmap.josm.data.coor.LatLon;
    1215import org.openstreetmap.josm.data.osm.DataSet;
     16import org.openstreetmap.josm.data.osm.Node;
    1317import org.openstreetmap.josm.data.osm.Relation;
    1418import org.openstreetmap.josm.data.osm.Way;
     
    109113        }
    110114    }
     115
     116    /**
     117     * Test of {@link Geometry#getNormalizedAngleInDegrees(double)} method.
     118     */
     119    @Test
     120    public void testRightAngle() {
     121        Node n1 = new Node(1);
     122        Node n2 = new Node(2);
     123        Node n3 = new Node(3);
     124        n1.setCoor(new LatLon(10.22873540462851, 6.169719398316592));
     125        n2.setCoor(new LatLon(10.229332494162811, 6.16978130985785));
     126        n3.setCoor(new LatLon(10.22924937004949, 6.17060908367496));
     127
     128        double angle = Geometry.getNormalizedAngleInDegrees(Geometry.getCornerAngle(n1.getEastNorth(),
     129                n2.getEastNorth(), n3.getEastNorth()));
     130        assertEquals(90, angle, 1e-8);
     131        angle = Geometry.getNormalizedAngleInDegrees(Geometry.getCornerAngle(n1.getEastNorth(),
     132                n2.getEastNorth(), n1.getEastNorth()));
     133        assertEquals(0, angle, 1e-8);
     134
     135        n1.setCoor(new LatLon(10.2295011, 6.1693106));
     136        n2.setCoor(new LatLon(10.2294958, 6.16930635));
     137        n3.setCoor(new LatLon(10.2294895, 6.1693039));
     138
     139        angle = Geometry.getNormalizedAngleInDegrees(Geometry.getCornerAngle(n1.getEastNorth(),
     140                n2.getEastNorth(), n3.getEastNorth()));
     141        assertEquals(162.66381817961337, angle, 1e-5);
     142
     143        angle = Geometry.getNormalizedAngleInDegrees(Geometry.getCornerAngle(n3.getEastNorth(),
     144                n2.getEastNorth(), n1.getEastNorth()));
     145        assertEquals(162.66381817961337, angle, 1e-5);
     146    }
    111147}
Note: See TracChangeset for help on using the changeset viewer.