Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Eviscerate mbgl expression to Foundation JSON object conversion #11389

Merged
merged 13 commits into from
Mar 30, 2018

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Mar 5, 2018

Piggy-back on #11156 to more robustly and succintly convert mbgl::style::expression::Expressions to JSON-style Foundation objects. Before merging this PR, I might consider merging MGLJSONObjectFromMBGLValue() with ValueEvaluator.

Fixes #11254. Depends on #11391 and #11565.

/cc @anandthakker

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS refactor macOS Mapbox Maps SDK for macOS runtime styling labels Mar 5, 2018
@1ec5 1ec5 added this to the ios-v4.0.0 milestone Mar 5, 2018
@1ec5 1ec5 self-assigned this Mar 5, 2018
@1ec5 1ec5 requested a review from anandthakker March 5, 2018 21:00
@1ec5 1ec5 added ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold and removed ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Mar 5, 2018
@1ec5
Copy link
Contributor Author

1ec5 commented Mar 6, 2018

Tests are currently failing because of an incomplete implementation of the number operator.

@1ec5 1ec5 force-pushed the 1ec5-mbgl-expression-json-foundation-11254 branch from a46f9ff to b9575c1 Compare March 6, 2018 10:14
@1ec5 1ec5 added the release blocker Blocks the next final release label Mar 6, 2018
for (NSExpression *component in components) {
if (component.expressionType != NSConstantValueExpressionType) {
return nil;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this requiring the components of an RGB(A) expression to be literals? If so, note that that isn't required by the core "rgb" / "rgba" expressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is a convenience. If it returns nil, then the caller will synthesize a colorWithRed:green:blue:alpha: function expression instead, which can take arbitrary expressions as the components.

@1ec5 1ec5 force-pushed the 1ec5-mbgl-expression-json-foundation-11254 branch from 84284ba to 2bb3b5c Compare March 8, 2018 01:50
@1ec5 1ec5 force-pushed the 1ec5-mbgl-expression-json-foundation-11254 branch from 2bb3b5c to ea4c49f Compare March 16, 2018 07:53
Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is looking good.

This is what I have reviewed so far and needs to address the missing tests.

Documentation

- [ ] Public class/methods/properties/structs are documented.
- [ ] Documentation has Jazzy friendly links.

Code readability.

- [ ] Header imports are not duplicated.

  • Method names has clear purpose.
  • Usage of appropriate data types.
    - [ ] Use of auto for C++ objects.
    - [ ] Pointer returns.

Code functionality.

- [ ] Check project files are included on both platforms (ios, macos).

  • Shared functionality is implemented on both platforms.
  • Has no retain cycles.
  • Has no side effects.
  • Test cases test each scenario.

@1ec5 1ec5 force-pushed the 1ec5-mbgl-expression-json-foundation-11254 branch from ea4c49f to bffc8e4 Compare March 27, 2018 05:58
@fabian-guerra fabian-guerra self-requested a review March 29, 2018 01:57
Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼(just need to add the tests)

@1ec5 1ec5 force-pushed the 1ec5-mbgl-expression-json-foundation-11254 branch from bffc8e4 to 6a3fd64 Compare March 29, 2018 17:49
@1ec5 1ec5 added the Core The cross-platform C++ core, aka mbgl label Mar 30, 2018
@@ -223,7 +223,11 @@ mbgl::Value Interpolate<T>::serialize() const {

interpolator.match(
[&](const ExponentialInterpolator& exponential) {
serialized.emplace_back(std::vector<mbgl::Value>{{ std::string("exponential"), exponential.base }});
if (exponential.base == 1) {
serialized.emplace_back(std::vector<mbgl::Value>{{ std::string("linear") }});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anandthakker @ChrisLoer, 02de0ce adds this special case so that ["linear"] round-trips as ["linear"] and not ["exponential", 1]. This balances out the existing special case in parseInterpolate() that converts ["linear"] to ExponentialInterpolator(1.0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a problem, actually:

  [
  "interpolate",
  [
-     "exponential",
    1
+     "linear"
    ],
  [
    "heatmap-density"
  ],
  0,
  [
    "rgba",
    0,
    0,
    0,
    1
  ],
  1,
  [
    "rgba",
    255,
    0,
    0,
    1
  ]
]
* failed heatmap-density basic

This is caused by fixtures in GL JS:

https://github.com/mapbox/mapbox-gl-js/blob/7bc23b9b9df28afc54252a2d68d450aa24580c0b/test/integration/expression-tests/heatmap-density/basic/test.json#L37

We can adjust those fixtures, but I’m not sure how feasible it is to get that into the release-boba branch in time for a beta. For now, I may need to revert 02de0ce and work around this round-tripping issue in the SDK’s unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the fixtures shouldn't take too long even though there's the annoying JS/native PR dance:

  • Checkout master in the gl-js submodule
  • run UPDATE=1 yarn run test-expressions from the native side
  • Go go back into the submodule, verify the diff is just the exponential->linear change
  • Create a GL JS PR, merge to master
  • Update the pin on native

release-boba is already on a pretty recent pin of GL JS, I don't think you should have too much trouble updating the pin.

Too bad, I thought about putting in a "linear" special case in the first place but I think we decided we didn't have a need for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I initially thought it would be OK because we weren’t trying to serialize to literally the same thing, only semantically the same thing. But this turned out to be one of the trickier things to work around in the SDK’s roundtripping unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the step-by-step explanation: #11564.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does solving this cause the opposite problem, where ["exponential", 1.0] roundtrips as ["linear"] rather than ["exponential", 1.0]?

Copy link
Contributor Author

@1ec5 1ec5 Mar 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but it’s semantically equivalent, correct? Just as ["to-rgba", ["rgba", …]] gets collapsed down to ["literal", …], I think it’d be slightly less surprising for roundtripping to introduce this syntactic sugar than for it to remove the syntactic sugar. That was my takeaway from #8457 anyways.

(This change is actually part of #11565; this PR is based on that one.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 makes sense, just wanted to make sure that this was the intent

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 30, 2018

I split out #11565 to fix the linear interpolator issue; this PR depends on it. (A bit more yarn came out than I expected there.)

#11391 is once again rearing its ugly head, failing macOS builds on CI but not locally on High Sierra:

MGLBackgroundLayerTests
  testProperties, ((layer.backgroundColor) equal to (functionExpression)) failed: ("mgl_step:from:stops:($zoomLevel, NSCalibratedRGBColorSpace 0.985948 0 0.0269506 1, {18 = NSCalibratedRGBColorSpace 0.985948 0 0.0269506 1})") is not equal to ("mgl_step:from:stops:($zoomLevel, NSCalibratedRGBColorSpace 1 0 0 1, {18 = NSCalibratedRGBColorSpace 1 0 0 1})") - backgroundColor should round-trip camera expressions.
  /Users/distiller/project/platform/darwin/test/MGLBackgroundStyleLayerTests.mm:57
  
        XCTAssertEqualObjects(layer.backgroundColor, functionExpression,
                              @"backgroundColor should round-trip camera expressions.");

  

@1ec5 1ec5 added beta blocker Blocks the next beta release and removed ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold Core The cross-platform C++ core, aka mbgl release blocker Blocks the next final release labels Mar 30, 2018
@1ec5
Copy link
Contributor Author

1ec5 commented Mar 30, 2018

All the builds now pass on CI, other than nitpick, which will pass once mapbox/mapbox-gl-js#6427 and #11565 land.

@1ec5 1ec5 removed the request for review from anandthakker March 30, 2018 11:34
@1ec5 1ec5 force-pushed the 1ec5-mbgl-expression-json-foundation-11254 branch from 605083a to 99d02d4 Compare March 30, 2018 23:14
@1ec5 1ec5 merged commit 59e9290 into release-boba Mar 30, 2018
@1ec5 1ec5 deleted the 1ec5-mbgl-expression-json-foundation-11254 branch March 30, 2018 23:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beta blocker Blocks the next beta release iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS refactor runtime styling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants