Changeset 17769 in josm for trunk/src/org


Ignore:
Timestamp:
2021-04-13T21:12:08+02:00 (3 years ago)
Author:
simon04
Message:

see #20744 - MapCSS: fix unary minus

Regression of r17758.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r17764 r17769  
    5555        }
    5656
    57         static Factory ofNumberVarArgs(DoubleBinaryOperator operator) {
    58             return args -> env -> args.stream()
     57        static Factory ofNumberVarArgs(double identity, DoubleUnaryOperator unaryOperator, DoubleBinaryOperator operator) {
     58            return args -> env -> args.isEmpty()
     59                    ? identity
     60                    : args.size() == 1
     61                    ? unaryOperator.applyAsDouble(Cascade.convertTo(args.get(0).evaluate(env), Double.class))
     62                    : args.stream()
    5963                    .map(arg -> Cascade.convertTo(arg.evaluate(env), Double.class))
    6064                    .filter(Objects::nonNull)
     
    162166        FACTORY_MAP.put("count_roles", Factory.ofStringVarargs(Functions::count_roles));
    163167        FACTORY_MAP.put("degree_to_radians", Factory.of(Functions::degree_to_radians));
    164         FACTORY_MAP.put("divided_by", Factory.ofNumberVarArgs(Functions::divided_by));
     168        FACTORY_MAP.put("divided_by", Factory.ofNumberVarArgs(1.0, DoubleUnaryOperator.identity(), Functions::divided_by));
    165169        FACTORY_MAP.put("equal", Factory.of(Object.class, Object.class, Functions::equal));
    166170        FACTORY_MAP.put("eval", Factory.of(Object.class, Functions::eval));
     
    189193        FACTORY_MAP.put("log", Factory.of(Math::log));
    190194        FACTORY_MAP.put("lower", Factory.of(String.class, Functions::lower));
    191         FACTORY_MAP.put("minus", Factory.ofNumberVarArgs(Functions::minus));
     195        FACTORY_MAP.put("minus", Factory.ofNumberVarArgs(0.0, v -> -v, Functions::minus));
    192196        FACTORY_MAP.put("mod", Factory.of(float.class, float.class, Functions::mod));
    193197        FACTORY_MAP.put("not", Factory.of(boolean.class, Functions::not));
     
    204208        FACTORY_MAP.put("parent_tag", Factory.ofEnv(String.class, Functions::parent_tag));
    205209        FACTORY_MAP.put("parent_tags", Factory.ofEnv(String.class, Functions::parent_tags));
    206         FACTORY_MAP.put("plus", Factory.ofNumberVarArgs(Functions::plus));
     210        FACTORY_MAP.put("plus", Factory.ofNumberVarArgs(0.0, DoubleUnaryOperator.identity(), Functions::plus));
    207211        FACTORY_MAP.put("print", Factory.of(Object.class, Functions::print));
    208212        FACTORY_MAP.put("println", Factory.of(Object.class, Functions::println));
     
    229233        FACTORY_MAP.put("tan", Factory.of(Math::tan));
    230234        FACTORY_MAP.put("tanh", Factory.of(Math::tanh));
    231         FACTORY_MAP.put("times", Factory.ofNumberVarArgs(Functions::times));
     235        FACTORY_MAP.put("times", Factory.ofNumberVarArgs(1.0, DoubleUnaryOperator.identity(), Functions::times));
    232236        FACTORY_MAP.put("title", Factory.of(String.class, Functions::title));
    233237        FACTORY_MAP.put("to_boolean", Factory.of(String.class, Functions::to_boolean));
Note: See TracChangeset for help on using the changeset viewer.