From ba5c9fdba9fcbf8cfe4b5424366f191e7d81d1fd Mon Sep 17 00:00:00 2001
Date: Wed, 1 Feb 2023 01:24:32 +0100
Subject: [PATCH 2/2] Add parent_way_angle mapcss function

---
 .../gui/mappaint/mapcss/ExpressionFactory.java  |  1 +
 .../josm/gui/mappaint/mapcss/Functions.java     | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
index 72056434f..73e3066e1 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
@@ -216,6 +216,7 @@ public final class ExpressionFactory {
         FACTORY_MAP.put("parent_osm_id", Factory.ofEnv(Functions::parent_osm_id));
         FACTORY_MAP.put("parent_tag", Factory.ofEnv(String.class, Functions::parent_tag));
         FACTORY_MAP.put("parent_tags", Factory.ofEnv(String.class, Functions::parent_tags));
+        FACTORY_MAP.put("parent_way_angle", Factory.ofEnv(Functions::parent_way_angle));
         FACTORY_MAP.put("plus", Factory.ofNumberVarArgs(0.0, DoubleUnaryOperator.identity(), Functions::plus));
         FACTORY_MAP.put("print", Factory.of(Object.class, Functions::print));
         FACTORY_MAP.put("println", Factory.of(Object.class, Functions::println));
diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
index d45be5389..173814f6e 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
@@ -41,6 +41,7 @@ import org.openstreetmap.josm.tools.RotationAngle;
 import org.openstreetmap.josm.tools.StreamUtils;
 import org.openstreetmap.josm.tools.Territories;
 import org.openstreetmap.josm.tools.Utils;
+import org.openstreetmap.josm.tools.RotationAngle.WayDirectionRotationAngle;
 
 /**
  * List of functions that can be used in MapCSS expressions.
@@ -477,6 +478,22 @@ public final class Functions {
         return Collections.singletonList(env.parent.get(key));
     }
 
+    /**
+     * Get the rotation angle of the preceding parent way segment at the node location.
+     * If there is no preceding parent way segment, the following way segment is used instead.
+     * Requires a parent way object matched via <a href="https://josm.openstreetmap.de/wiki/Help/Styles/MapCSSImplementation#LinkSelector">child selector</a>.
+     * 
+     * @param env the environment
+     * @return the rotation angle of the parent way segment at the node in radians, otherwise null if there is no matching parent way or the object is not a node
+     * @since xxx
+     */
+    public static Double parent_way_angle(final Environment env) {
+        if (env.osm instanceof Node && env.parent instanceof Way) {
+            return WayDirectionRotationAngle.getRotationAngleForNodeOnWay((Node)env.osm, (Way)env.parent);
+        }
+        return null;
+    }
+
     /**
      * Gets the value of the key {@code key} from the object's child.
      * @param env the environment
-- 
2.39.1

