Changeset 8251 in josm


Ignore:
Timestamp:
2015-04-23T19:06:39+02:00 (5 years ago)
Author:
simon04
Message:

see #10217 - MapCSS rotation: add grad and turn units

Location:
trunk
Files:
2 edited

Legend:

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

    r8238 r8251  
    4343        final Pattern radiansPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(rad)?");
    4444        final Pattern degreesPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(deg|°)");
     45        final Pattern gradianPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(grad)");
     46        final Pattern turnPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(turn)");
    4547        final double value;
    4648        Matcher matcher;
     
    4951        } else if ((matcher = degreesPattern.matcher(string)).matches()) {
    5052            value = Math.toRadians(Double.parseDouble(matcher.group(1)));
     53        } else if ((matcher = gradianPattern.matcher(string)).matches()) {
     54            value = Double.parseDouble(matcher.group(1)) / 200 * Math.PI;
     55        } else if ((matcher = turnPattern.matcher(string)).matches()) {
     56            value = Double.parseDouble(matcher.group(1)) * 2 * Math.PI;
    5157        } else {
    5258            try {
  • trunk/test/unit/org/openstreetmap/josm/gui/util/RotationAngleTest.java

    r8199 r8251  
    2121
    2222    @Test
     23    public void testParseGrad() throws Exception {
     24        assertThat(RotationAngle.buildStaticRotation("200grad").getRotationAngle(null), is(Math.PI));
     25        assertThat(RotationAngle.buildStaticRotation("100grad").getRotationAngle(null), is(Math.PI / 2));
     26        assertThat(RotationAngle.buildStaticRotation("400grad").getRotationAngle(null), is(Math.PI * 2));
     27    }
     28
     29    @Test
     30    public void testParseTurn() throws Exception {
     31        assertThat(RotationAngle.buildStaticRotation("0.5turn").getRotationAngle(null), is(Math.PI));
     32        assertThat(RotationAngle.buildStaticRotation("0.25turn").getRotationAngle(null), is(Math.PI / 2));
     33        assertThat(RotationAngle.buildStaticRotation("1turn").getRotationAngle(null), is(Math.PI * 2));
     34    }
     35
     36    @Test
    2337    public void testParseCardinal() throws Exception {
    2438        assertThat(RotationAngle.buildStaticRotation("south").getRotationAngle(null), is(Math.PI));
Note: See TracChangeset for help on using the changeset viewer.