Skip to content
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 distance expression support #642

Merged
merged 10 commits into from
May 4, 2024
Merged

Add distance expression support #642

merged 10 commits into from
May 4, 2024

Conversation

HarelM
Copy link
Collaborator

@HarelM HarelM commented May 2, 2024

Launch Checklist

This allows the ability to use distance expression in web.

This is heavily based on the c++ native implementation:
https://github.com/maplibre/maplibre-native/blob/cd6a0ab11fcd9b5bbfee87896a14159d0ed56256/src/mbgl/style/expression/distance.cpp
https://github.com/maplibre/maplibre-native/blob/cd6a0ab11fcd9b5bbfee87896a14159d0ed56256/src/mbgl/tile/geometry_tile_data.cpp
https://github.com/maplibre/maplibre-native/blob/cd6a0ab11fcd9b5bbfee87896a14159d0ed56256/src/mbgl/util/geometry_util.cpp

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented May 2, 2024

Codecov Report

Attention: Patch coverage is 93.32162% with 38 lines in your changes are missing coverage. Please review.

Project coverage is 92.45%. Comparing base (e7b5c2b) to head (c733677).

Files Patch % Lines
src/expression/definitions/distance.ts 91.30% 30 Missing ⚠️
test/lib/geometry.ts 86.48% 5 Missing ⚠️
src/util/geometry_util.ts 97.67% 2 Missing ⚠️
src/feature_filter/index.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #642      +/-   ##
==========================================
+ Coverage   92.23%   92.45%   +0.22%     
==========================================
  Files         100      104       +4     
  Lines        4196     4624     +428     
  Branches     1203     1303     +100     
==========================================
+ Hits         3870     4275     +405     
- Misses        326      349      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HarelM
Copy link
Collaborator Author

HarelM commented May 2, 2024

FYI: @louwers, thanks for the pointers!

@HarelM HarelM marked this pull request as ready for review May 3, 2024 07:19
@HarelM HarelM requested review from birkskyum, louwers and neodescis May 3, 2024 07:19
@@ -187,6 +188,7 @@ export {
format,
validate,
migrate,
classifyRings,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is exported here in order to remove it from maplibre-gl code base.

@HarelM
Copy link
Collaborator Author

HarelM commented May 3, 2024

I'm happy with the tests coverage and the implementation, it found some bugs I needed to fix from wrong conversion of code and differences between c++ and javascript (integer division).
Overall the tests cover the scenarios that I wanted to check (points, polygons with holes, lines etc).
This is good to go from my point of view.

@HarelM
Copy link
Collaborator Author

HarelM commented May 3, 2024

Also @louwers I think the following line should use the point constant and not the line constant:
https://github.com/maplibre/maplibre-native/blob/cd6a0ab11fcd9b5bbfee87896a14159d0ed56256/src/mbgl/style/expression/distance.cpp#L373

I don't think it will dramatically affect the algorithm, but when I looked at the code and converted it, I came across this.

Copy link
Collaborator

@neodescis neodescis left a comment

Choose a reason for hiding this comment

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

I'm not familiar enough with the math to check it, but it looks good to me in general. Certainly great job on improving typings, and the tests look comprehensive.

@HarelM
Copy link
Collaborator Author

HarelM commented May 4, 2024

This adds about 7k unzipped to the bundle size (~1%). It's not negligible but it's part of the spec, so I don't see a way around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants