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

LatLng and LatLngBounds should enforce invariants #3802

Closed
2 tasks done
jfirebaugh opened this issue Feb 3, 2016 · 2 comments
Closed
2 tasks done

LatLng and LatLngBounds should enforce invariants #3802

jfirebaugh opened this issue Feb 3, 2016 · 2 comments
Labels
Core The cross-platform C++ core, aka mbgl

Comments

@jfirebaugh
Copy link
Contributor

jfirebaugh commented Feb 3, 2016

Remove operator bool() from both classes and enforce the following invariants.

  • LatLng constructor throws if any of the following are violated:
    • std::isfinite(latitude)
    • std::isfinite(longitude)
    • -90 <= latitude <= 90
  • LatLngBounds constructor swaps coordinates as necessary to enforce:
    • sw.latitude <= ne.latitude
    • sw.longitude <= ne.longitude
@jfirebaugh
Copy link
Contributor Author

It's useful to have an "empty" state for LatLngBounds: #3803. We can relax the invariant slightly and keep a bool empty() const method around for that.

@jfirebaugh
Copy link
Contributor Author

Just discovered an example of how dangerous a non-explicit operator bool can be: currently LatLng(a, b) == LatLng(c, d) is true for any non-NaN a, b, c, d.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

No branches or pull requests

2 participants