Ignore:
Timestamp:
2015-05-01T21:33:01+02:00 (10 years ago)
Author:
Balaitous
Message:

fix #7421 - Circle created from way heads always clockwise

  • If 3 nodes closed way is selected, keep way direction when creating circle;
  • Otherwise use left- and right-hand traffic database (r7193) to determine way direction;
  • Add a Geometry.isClockwise(List<Node>) method;
  • Fix some sonar issue
  • Add test case
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r8127 r8303  
    688688     */
    689689    public static boolean isClockwise(Way w) {
    690         if (!w.isClosed()) {
     690        return isClockwise(w.getNodes());
     691    }
     692
     693    /**
     694     * Determines whether path from nodes list is oriented clockwise.
     695     * @see #isClockwise(Way)
     696     * @param nodes Nodes list to be checked.
     697     * @return true if and only if way is oriented clockwise.
     698     * @throws IllegalArgumentException if way is not closed (see {@link Way#isClosed}).
     699     */
     700    public static boolean isClockwise(List<Node> nodes) {
     701        double area2 = 0.;
     702        int nodesCount = nodes.size();
     703        if (nodesCount < 3 || nodes.get(0) != nodes.get(nodesCount - 1)) {
    691704            throw new IllegalArgumentException("Way must be closed to check orientation.");
    692705        }
    693706
    694         double area2 = 0.;
    695         int nodesCount = w.getNodesCount();
    696 
    697707        for (int node = 1; node <= /*sic! consider last-first as well*/ nodesCount; node++) {
    698             LatLon coorPrev = w.getNode(node - 1).getCoor();
    699             LatLon coorCurr = w.getNode(node % nodesCount).getCoor();
     708            LatLon coorPrev = nodes.get(node - 1).getCoor();
     709            LatLon coorCurr = nodes.get(node % nodesCount).getCoor();
    700710            area2 += coorPrev.lon() * coorCurr.lat();
    701711            area2 -= coorCurr.lon() * coorPrev.lat();
Note: See TracChangeset for help on using the changeset viewer.