Mange / googleprojection-rs

Project world- or screen-space coordinates for use in Google Maps tiles
https://mange.github.io/googleprojection-rs/
Apache License 2.0
4 stars 0 forks source link

When calling from_ll_to_pixel, results are rounded #4

Closed stefan2718 closed 5 years ago

stefan2718 commented 5 years ago

In the from_ll_to_pixel function, the returned values are rounded:

let e = (... + 0.5).floor();
...
let g = (... + 0.5).floor();
Some(T::with_xy(e, g))

This differs from the functionality of the Google Maps API function OverlayView.getProjection().fromLatLngToDivPixel() which returns fractional pixel values. All browsers accept fractional pixel values (but will usually round them when rendering). screenshot of googlemaps code

The purpose of non-rounding (as you might figure out from the screenshot) would be to increase accuracy. For example, I am extending a pixel-based area around a coord or bounds, then converting back to coords, so I can calculate if coordinates are in pixel-based bounds near other coordinates.

In order to prevent breaking changes, I would recommend creating a new function from_ll_to_pixel_no_rounding (or something similar) that contains the calculations without rounding. Then the original from_ll_to_pixel can call this new function and return the rounded results.

If you think this is a reasonable feature to add, I'd be willing to put together the PR. Let me know, thanks!

Mange commented 5 years ago

Excellent idea! I like it.

Perhaps from_ll_to_subpixel would be a good name?

[EDIT]: PR is very welcome. :heart:

Mange commented 5 years ago

Version 1.2.0 is now released on Crates.io. Thank you for your contribution!

stefan2718 commented 5 years ago

Thanks for your responsiveness and quick release time!