Ticket #22695: 0001-Fix-mapcss-rotation-offset-for-rotation-way.patch

File 0001-Fix-mapcss-rotation-offset-for-rotation-way.patch, 2.4 KB (added by Woazboat, 3 years ago)
  • src/org/openstreetmap/josm/tools/RotationAngle.java

    From e75752ef381ec50368ddb6ca6f64261204563bb0 Mon Sep 17 00:00:00 2001
    Date: Wed, 1 Feb 2023 01:22:56 +0100
    Subject: [PATCH 1/2] Fix mapcss rotation offset for *-rotation: way
    
    ---
     .../josm/tools/RotationAngle.java             | 22 ++++++++++++++++---
     1 file changed, 19 insertions(+), 3 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/tools/RotationAngle.java b/src/org/openstreetmap/josm/tools/RotationAngle.java
    index 491891276..3a9cb02d8 100644
    a b public interface RotationAngle {  
    3232                return 0;
    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 xxx
     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        }
    4258
    public interface RotationAngle {  
    106122    /**
    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     */
    112128    double getRotationAngle(IPrimitive p);