-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add abs, round, floor, ceil operators #6496
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2490,6 +2490,42 @@ | |
} | ||
} | ||
}, | ||
"round": { | ||
"doc": "Rounds the input to the nearest integer. Halflway values are rounded away from zero. E.g., `[\"round\", -1.5]` evaluates to -2.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Halflway → Halfway There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: It’s somewhat unusual to begin a sentence with “E.g.” “For example” is more easily understood. |
||
"group": "Math", | ||
"sdk-support": { | ||
"basic functionality": { | ||
"js": "0.45.0" | ||
} | ||
} | ||
}, | ||
"abs": { | ||
"doc": "Returns the absolute value of the input.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when implementing I noticed abs on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. capturing from chat that above assumption was invalid |
||
"group": "Math", | ||
"sdk-support": { | ||
"basic functionality": { | ||
"js": "0.45.0" | ||
} | ||
} | ||
}, | ||
"ceil": { | ||
"doc": "Returns the smallest integer that is greater than or equal to the input.", | ||
"group": "Math", | ||
"sdk-support": { | ||
"basic functionality": { | ||
"js": "0.45.0" | ||
} | ||
} | ||
}, | ||
"floor": { | ||
"doc": "Returns the largest integer that is less than or equal to the input.", | ||
"group": "Math", | ||
"sdk-support": { | ||
"basic functionality": { | ||
"js": "0.45.0" | ||
} | ||
} | ||
}, | ||
"==": { | ||
"doc": "Returns `true` if the input values are equal, `false` otherwise. Equality is strictly typed: values of different types are always considered not equal.", | ||
"group": "Decision", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"expression": ["abs", ["get", "x"]], | ||
"inputs": [ | ||
[{}, {"properties": {"x": -2}}], | ||
[{}, {"properties": {"x": 2}}] | ||
], | ||
"expected": { | ||
"compiled": { | ||
"result": "success", | ||
"isFeatureConstant": false, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"outputs": [2, 2], | ||
"serialized": ["abs", ["number", ["get", "x"]]] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"expression": ["ceil", ["get", "x"]], | ||
"inputs": [ | ||
[{}, {"properties": {"x": -2.6}}], | ||
[{}, {"properties": {"x": -2.5}}], | ||
[{}, {"properties": {"x": -2.4}}], | ||
[{}, {"properties": {"x": -2}}], | ||
[{}, {"properties": {"x": 2.6}}], | ||
[{}, {"properties": {"x": 2.5}}], | ||
[{}, {"properties": {"x": 2.4}}], | ||
[{}, {"properties": {"x": 2}}] | ||
], | ||
"expected": { | ||
"compiled": { | ||
"result": "success", | ||
"isFeatureConstant": false, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"outputs": [ -2, -2, -2, -2, 3, 3, 3, 2 ], | ||
"serialized": ["ceil", ["number", ["get", "x"]]] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"expression": ["floor", ["get", "x"]], | ||
"inputs": [ | ||
[{}, {"properties": {"x": -2.6}}], | ||
[{}, {"properties": {"x": -2.5}}], | ||
[{}, {"properties": {"x": -2.4}}], | ||
[{}, {"properties": {"x": -2}}], | ||
[{}, {"properties": {"x": 2.6}}], | ||
[{}, {"properties": {"x": 2.5}}], | ||
[{}, {"properties": {"x": 2.4}}], | ||
[{}, {"properties": {"x": 2}}] | ||
], | ||
"expected": { | ||
"compiled": { | ||
"result": "success", | ||
"isFeatureConstant": false, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"outputs": [ -3, -3, -3, -2, 2, 2, 2, 2 ], | ||
"serialized": ["floor", ["number", ["get", "x"]]] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"expression": ["round", ["get", "x"]], | ||
"inputs": [ | ||
[{}, {"properties": {"x": -2.6}}], | ||
[{}, {"properties": {"x": -2.5}}], | ||
[{}, {"properties": {"x": -2.4}}], | ||
[{}, {"properties": {"x": -2}}], | ||
[{}, {"properties": {"x": 2.6}}], | ||
[{}, {"properties": {"x": 2.5}}], | ||
[{}, {"properties": {"x": 2.4}}], | ||
[{}, {"properties": {"x": 2}}] | ||
], | ||
"expected": { | ||
"compiled": { | ||
"result": "success", | ||
"isFeatureConstant": false, | ||
"isZoomConstant": true, | ||
"type": "number" | ||
}, | ||
"outputs": [ -3, -3, -2, -2, 3, 3, 2, 2 ], | ||
"serialized": ["round", ["number", ["get", "x"]]] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer argument destructuring as in the other definitions, i.e.
(ctx, [n]) => ...
.