From c1ab5c8e6c899c40fddcb7e3a90053dacc25d99b Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Mon, 1 Aug 2016 12:42:57 +0000 Subject: [PATCH] add support for natural logarithm function in expressions --- include/mapnik/expression_grammar_impl.hpp | 1 + include/mapnik/function_call.hpp | 11 +++++++++++ test/unit/core/expressions_test.cpp | 3 +++ 3 files changed, 15 insertions(+) diff --git a/include/mapnik/expression_grammar_impl.hpp b/include/mapnik/expression_grammar_impl.hpp index 40be6b995..ad28f0135 100644 --- a/include/mapnik/expression_grammar_impl.hpp +++ b/include/mapnik/expression_grammar_impl.hpp @@ -102,6 +102,7 @@ unary_function_types::unary_function_types() ("tan", tan_impl()) ("atan", atan_impl()) ("exp", exp_impl()) + ("log", log_impl()) ("abs", abs_impl()) ("length",length_impl()) ; diff --git a/include/mapnik/function_call.hpp b/include/mapnik/function_call.hpp index efbaa5f28..f50829bd6 100644 --- a/include/mapnik/function_call.hpp +++ b/include/mapnik/function_call.hpp @@ -50,6 +50,17 @@ struct exp_impl }; +// log +struct log_impl +{ + //using type = T; + value_type operator() (value_type const& val) const + { + return std::log(val.to_double()); + } + +}; + // sin struct sin_impl { diff --git a/test/unit/core/expressions_test.cpp b/test/unit/core/expressions_test.cpp index 64cdd9ecf..e60d6127b 100644 --- a/test/unit/core/expressions_test.cpp +++ b/test/unit/core/expressions_test.cpp @@ -108,6 +108,9 @@ TEST_CASE("expressions") TRY_CHECK(eval(" rad_to_deg * atan(1.0) ").to_double() == approx(45.0)); // exp TRY_CHECK(eval(" exp(0.0) ") == 1.0); + // log + TRY_CHECK(eval(" log(1.0) ") == 0.0); + TRY_CHECK(eval(" log(exp(1.0)) ") == 1.0); // abs TRY_CHECK(eval(" abs(cos(-pi)) ") == 1.0); // length (string)