Changeset 18661 in josm for trunk


Ignore:
Timestamp:
2023-02-13T21:53:05+01:00 (14 months ago)
Author:
taylor.smock
Message:

Fix #22703, see #22695, #22704: 90° offset of icon-rotation: way; in mapcss (patch by Woazboat, modified)

This is due to Geometry.getSegmentAngle getting the rotation from the positive
x-axis instead of the positive y-axis, but this is easily corrected by
subtracting 90 degrees (pi/2) from the calculation.

The previous behavior differed from the static rotation angle behavior, which
uses the positive y-axis.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r17333 r18661  
    3333            }
    3434            final Way w = ways.iterator().next();
     35            Double angle = getRotationAngleForNodeOnWay(n, w);
     36            return angle != null ? angle : 0;
     37        }
     38
     39        /**
     40         * Calculates the rotation angle of a node in a way based on the preceding way segment.
     41         * If the node is the first node in the given way, the angle of the following way segment is used instead.
     42         * @param n the node to get the rotation angle for
     43         * @param w the way containing the node
     44         * @return the rotation angle in radians or null if the way does not contain the node
     45         * @since 18661
     46         */
     47        public static Double getRotationAngleForNodeOnWay(Node n, Way w) {
    3548            final int idx = w.getNodes().indexOf(n);
     49            if (idx == -1) {
     50                return null;
     51            }
    3652            if (idx == 0) {
    37                 return -Geometry.getSegmentAngle(n.getEastNorth(), w.getNode(idx + 1).getEastNorth());
     53                return -(Geometry.getSegmentAngle(n.getEastNorth(), w.getNode(idx + 1).getEastNorth()) - Math.PI/2);
    3854            } else {
    39                 return -Geometry.getSegmentAngle(w.getNode(idx - 1).getEastNorth(), n.getEastNorth());
     55                return -(Geometry.getSegmentAngle(w.getNode(idx - 1).getEastNorth(), n.getEastNorth()) - Math.PI/2);
    4056            }
    4157        }
     
    107123     * Calculates the rotation angle depending on the primitive to be displayed.
    108124     * @param p primitive
    109      * @return rotation angle
     125     * @return rotation angle in radians, clockwise starting from up/north
    110126     * @since 13623 (signature)
    111127     */
Note: See TracChangeset for help on using the changeset viewer.