Ignore:
Timestamp:
2015-04-25T14:00:05+02:00 (10 years ago)
Author:
bastiK
Message:

see #10217 - move unit handling to parser
adds support for negative angles
new: length units px,cm,mm,in,q,pc,pt as in CSS (immediately converted to px)

File:
1 edited

Legend:

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

    r8251 r8260  
    4141     */
    4242    public static RotationAngle buildStaticRotation(final String string) {
    43         final Pattern radiansPattern = Pattern.compile("(\\d+\\.?\\d*)\\s*(rad)?");
    44         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)");
    4743        final double value;
    48         Matcher matcher;
    49         if ((matcher = radiansPattern.matcher(string)).matches()) {
    50             value = Double.parseDouble(matcher.group(1));
    51         } else if ((matcher = degreesPattern.matcher(string)).matches()) {
    52             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;
    57         } else {
    58             try {
    59                 value = parseCardinalRotation(string);
    60             } catch (IllegalArgumentException ignore) {
    61                 throw new IllegalArgumentException("Invalid string: " + string);
    62             }
     44        try {
     45            value = parseCardinalRotation(string);
     46        } catch (IllegalArgumentException ignore) {
     47            throw new IllegalArgumentException("Invalid string: " + string);
    6348        }
    6449        return buildStaticRotation(value);
Note: See TracChangeset for help on using the changeset viewer.