Changeset 18664 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r17916 r18664 217 217 FACTORY_MAP.put("parent_tag", Factory.ofEnv(String.class, Functions::parent_tag)); 218 218 FACTORY_MAP.put("parent_tags", Factory.ofEnv(String.class, Functions::parent_tags)); 219 FACTORY_MAP.put("parent_way_angle", Factory.ofEnv(Functions::parent_way_angle)); 219 220 FACTORY_MAP.put("plus", Factory.ofNumberVarArgs(0.0, DoubleUnaryOperator.identity(), Functions::plus)); 220 221 FACTORY_MAP.put("print", Factory.of(Object.class, Functions::print)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
r18489 r18664 42 42 import org.openstreetmap.josm.tools.Territories; 43 43 import org.openstreetmap.josm.tools.Utils; 44 import org.openstreetmap.josm.tools.RotationAngle.WayDirectionRotationAngle; 44 45 45 46 /** … … 479 480 480 481 /** 482 * Get the rotation angle of the preceding parent way segment at the node location. 483 * If there is no preceding parent way segment, the following way segment is used instead. 484 * Requires a parent way object matched via 485 * <a href="https://josm.openstreetmap.de/wiki/Help/Styles/MapCSSImplementation#LinkSelector">child selector</a>. 486 * 487 * @param env the environment 488 * @return the rotation angle of the parent way segment at the node in radians, 489 * otherwise null if there is no matching parent way or the object is not a node 490 * @since 18664 491 */ 492 public static Double parent_way_angle(final Environment env) { 493 if (env.osm instanceof Node && env.parent instanceof Way) { 494 return WayDirectionRotationAngle.getRotationAngleForNodeOnWay((Node) env.osm, (Way) env.parent); 495 } 496 return null; 497 } 498 499 /** 481 500 * Gets the value of the key {@code key} from the object's child. 482 501 * @param env the environment -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/FunctionsTest.java
r17613 r18664 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertNotNull; 5 6 import static org.junit.jupiter.api.Assertions.assertNull; 6 7 import static org.junit.jupiter.api.Assertions.assertTrue; … … 8 9 9 10 import java.util.Collections; 11 import java.util.Objects; 10 12 11 import org.junit.jupiter.api.extension.RegisterExtension;12 13 import org.junit.jupiter.api.Test; 13 14 import org.openstreetmap.josm.TestUtils; 15 import org.openstreetmap.josm.data.coor.LatLon; 16 import org.openstreetmap.josm.data.osm.Node; 14 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 19 import org.openstreetmap.josm.data.osm.User; 20 import org.openstreetmap.josm.data.osm.Way; 17 21 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 18 22 import org.openstreetmap.josm.gui.mappaint.Environment; 19 23 import org.openstreetmap.josm.gui.util.GuiHelper; 20 24 import org.openstreetmap.josm.spi.preferences.Config; 21 import org.openstreetmap.josm.testutils.JOSMTestRules; 22 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 25 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 26 import org.openstreetmap.josm.testutils.annotations.Projection; 24 27 25 28 /** 26 29 * Unit tests of {@link Functions}. 27 30 */ 31 @BasicPreferences 32 @Projection 28 33 class FunctionsTest { 29 30 /**31 * Setup rule32 */33 @RegisterExtension34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")35 public JOSMTestRules test = new JOSMTestRules();36 37 34 private static class EnvBuilder { 38 35 private final OsmPrimitive osm; … … 108 105 109 106 /** 107 * Test for {@link Functions#parent_way_angle(Environment)} 108 */ 109 @Test 110 void testParentWayAngle() { 111 assertNull(Functions.parent_way_angle(new EnvBuilder(NODE).build())); 112 final Environment environment = new EnvBuilder(NODE).build(); 113 ((Node) environment.osm).setCoor(LatLon.ZERO); 114 final Way parent = TestUtils.newWay("", new Node(new LatLon(-.1, 0)), (Node) environment.osm, new Node(new LatLon(.1, 0))); 115 environment.parent = parent; 116 Double actual = Functions.parent_way_angle(environment); 117 assertNotNull(actual); 118 assertEquals(Math.toRadians(0), actual, 1e-9); 119 // Reverse node order 120 Objects.requireNonNull(parent.firstNode()).setCoor(LatLon.NORTH_POLE); 121 Objects.requireNonNull(parent.lastNode()).setCoor(LatLon.SOUTH_POLE); 122 actual = Functions.parent_way_angle(environment); 123 assertNotNull(actual); 124 assertEquals(Math.toRadians(180), actual, 1e-9); 125 } 126 127 /** 110 128 * Unit test of {@code Functions#to_xxx} 111 129 */ … … 163 181 Config.getPref().put(colorKey, null); 164 182 } 165 166 183 }
Note:
See TracChangeset
for help on using the changeset viewer.