From ff3cc9b4d0c9384e8afb51b069d4d9d6dbc2af53 Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Fri, 25 Oct 2019 14:09:32 +0200 Subject: [PATCH] Expressions / renamed operator pow to ^ To be more in line with Mapbox style spec --- examples/filter-points-webgl.js | 2 +- src/ol/style/expressions.js | 4 ++-- test/spec/ol/style/expressions.test.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/filter-points-webgl.js b/examples/filter-points-webgl.js index 706f489004..3c36fc973a 100644 --- a/examples/filter-points-webgl.js +++ b/examples/filter-points-webgl.js @@ -16,7 +16,7 @@ const oldColor = 'rgba(242,56,22,0.61)'; const newColor = '#ffe52c'; const period = 12; // animation period in seconds const animRatio = - ['pow', + ['^', ['/', ['mod', ['+', diff --git a/src/ol/style/expressions.js b/src/ol/style/expressions.js index 11df01fcc8..8000271db5 100644 --- a/src/ol/style/expressions.js +++ b/src/ol/style/expressions.js @@ -24,7 +24,7 @@ import {asArray, isStringColor} from '../color.js'; * * `['-', value1, value1]` subtracts `value2` from `value1` * * `['clamp', value, low, high]` clamps `value` between `low` and `high` * * `['mod', value1, value1]` returns the result of `value1 % value2` (modulo) - * * `['pow', value1, value1]` returns the value of `value1` raised to the `value2` power + * * `['^', value1, value1]` returns the value of `value1` raised to the `value2` power * * * Transform operators: * * `['match', input, match1, output1, ...matchN, outputN, fallback]` compares the `input` value against all @@ -401,7 +401,7 @@ Operators['mod'] = { return `mod(${expressionToGlsl(context, args[0])}, ${expressionToGlsl(context, args[1])})`; } }; -Operators['pow'] = { +Operators['^'] = { getReturnType: function(args) { return ValueTypes.NUMBER; }, diff --git a/test/spec/ol/style/expressions.test.js b/test/spec/ol/style/expressions.test.js index e34a037adf..9a0519d9b8 100644 --- a/test/spec/ol/style/expressions.test.js +++ b/test/spec/ol/style/expressions.test.js @@ -129,7 +129,7 @@ describe('ol.style.expressions', function() { expect(getValueType(['/', ['get', 'size'], 12])).to.eql(ValueTypes.NUMBER); expect(getValueType(['*', ['get', 'size'], 12])).to.eql(ValueTypes.NUMBER); expect(getValueType(['clamp', ['get', 'attr2'], ['get', 'attr3'], 20])).to.eql(ValueTypes.NUMBER); - expect(getValueType(['pow', 10, 2])).to.eql(ValueTypes.NUMBER); + expect(getValueType(['^', 10, 2])).to.eql(ValueTypes.NUMBER); expect(getValueType(['mod', ['time'], 10])).to.eql(ValueTypes.NUMBER); expect(getValueType(['>', 10, ['get', 'attr4']])).to.eql(ValueTypes.BOOLEAN); expect(getValueType(['>=', 10, ['get', 'attr4']])).to.eql(ValueTypes.BOOLEAN); @@ -163,7 +163,7 @@ describe('ol.style.expressions', function() { expect(expressionToGlsl(context, ['+', ['*', ['get', 'size'], 0.001], 12])).to.eql('((a_size * 0.001) + 12.0)'); expect(expressionToGlsl(context, ['/', ['-', ['get', 'size'], 20], 100])).to.eql('((a_size - 20.0) / 100.0)'); expect(expressionToGlsl(context, ['clamp', ['get', 'attr2'], ['get', 'attr3'], 20])).to.eql('clamp(a_attr2, a_attr3, 20.0)'); - expect(expressionToGlsl(context, ['pow', ['mod', ['time'], 10], 2])).to.eql('pow(mod(u_time, 10.0), 2.0)'); + expect(expressionToGlsl(context, ['^', ['mod', ['time'], 10], 2])).to.eql('pow(mod(u_time, 10.0), 2.0)'); expect(expressionToGlsl(context, ['>', 10, ['get', 'attr4']])).to.eql('(10.0 > a_attr4)'); expect(expressionToGlsl(context, ['>=', 10, ['get', 'attr4']])).to.eql('(10.0 >= a_attr4)'); expect(expressionToGlsl(context, ['<', 10, ['get', 'attr4']])).to.eql('(10.0 < a_attr4)'); @@ -490,7 +490,7 @@ describe('ol.style.expressions', function() { it('correctly parses a combination of interpolate, match, color and number', function() { const expression = ['interpolate', ['linear'], - ['pow', + ['^', ['/', ['mod', ['+',