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

Introduce distance expression - #16397

Merged
zmiao merged 8 commits into
masterfrom
zmiao-distance-expression
Apr 22, 2020
Merged

zmiao merged 8 commits into
masterfrom
zmiao-distance-expression

Conversation

@zmiao

@zmiao zmiao commented Apr 15, 2020 •

Copy link
Copy Markdown
Contributor

Launch Checklist

This pr introduces a new expression called distance. It calculates the shortest distance between the geoObject input and the feature geometry. The expression will return. distance in the unit that is provided inside the expression as an argument. If the Unit is not provided, the default unit type Meters will be taken into use.
The format of this expression is as following:

["distance",  GeoJSONObject, "Unit"]

The first version of this expression will support Geometry type : Point, MultiPoint, LineString and MultiLineString.

One example of using expression with filter would have following effects :

'filter': ['<', ['distance','userPosition', 'meters'], 200]

Screen Shot 2020-03-24 at 5 50 39 PM

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • write tests for all new functionality
  • tagged @mapbox/maps-android @mapbox/maps-ios @mapbox/core-sdk if this PR adds or updates a public API
  • tagged @mapbox/gl-js if this PR includes shader changes or needs a js port @mapbox/gl-js
  • apply needs changelog label if a changelog is needed (remove label when added)

expression-tests and render-tests: mapbox/mapbox-gl-js#9602

@zmiao zmiao self-assigned this Apr 15, 2020
@zmiao zmiao added the needs changelog Indicates PR needs a changelog entry prior to merging. label Apr 15, 2020
@zmiao
zmiao force-pushed the zmiao-distance-expression branch 2 times, most recently from 48cedce to 3fe3a32 Compare April 15, 2020 12:28
@zmiao
zmiao force-pushed the zmiao-distance-expression branch 4 times, most recently from 1192b49 to 21e3c22 Compare April 19, 2020 18:20
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Outdated

// <distance, range1, range2>
using DistPair = std::tuple<double, IndexRange, IndexRange>;
class Comparator {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could be free function (in a nameless namespace)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I use this customer class as the comparator of priority_queue, I tried to use lambda, but it does not work with alias-declaration.

Comment thread src/mbgl/util/geometry_util.hpp Resolved
@zmiao
zmiao marked this pull request as ready for review April 20, 2020 09:22
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Resolved
Comment thread src/mbgl/style/expression/distance.cpp Resolved
@zmiao
zmiao force-pushed the zmiao-distance-expression branch 2 times, most recently from dd9c186 to 8a655e3 Compare April 20, 2020 09:58

@tmpsantos tmpsantos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please rebase the branch, the new clang-tidy checks have landed.

@zmiao
zmiao force-pushed the zmiao-distance-expression branch 3 times, most recently from 9db4c43 to 7a64458 Compare April 20, 2020 13:45
@zmiao
zmiao force-pushed the zmiao-distance-expression branch from d445ea5 to 19f794a Compare April 21, 2020 14:31

@alexshalamov alexshalamov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit + changelog

Comment thread src/mbgl/style/expression/within.cpp Resolved
zmiao added 4 commits April 22, 2020 11:10
Add distance unit choices

Fix cmake and add license

Add support for LineString Features

Add template to geometry helper function

Only support line and point

Rename geometry_within.cpp hpp file to geometry_util.cpp .hpp

Remove incorrect indexFilter, fix pointSetsDistance

Fix distance expression
…ion in geometry_util, add range assertion for distance contaniner IndexRange

Change distance units to small letters, update tests accordingly
@zmiao
zmiao force-pushed the zmiao-distance-expression branch from 7f669f7 to d2c08b8 Compare April 22, 2020 08:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants