Giter Club home page Giter Club logo

Comments (6)

juliohm avatar juliohm commented on June 14, 2024 1

@ettersi , regarding the first conversion, you can convert to LatLonAlt first and then convert to Cartesian since these two methods are already implemented. Would you like to submit a PR?

The second conversion should be trivial to add as well in a second PR.

from coordrefsystems.jl.

ettersi avatar ettersi commented on June 14, 2024

I've added the Cartesian <> Projected conversion in #52. Regarding the LatLon <> LatLonAlt conversion, I've since come to realise that implementing this as a Base.convert() method might be dangerous.

julia> Base.convert(::Type{LatLon}, coords::LatLonAlt{Datum}) where {Datum} = convert(LatLon{Datum}, coords)
       Base.convert(::Type{LatLon{Datum}}, coords::LatLonAlt{Datum}) where {Datum} = LatLon(coords.lat, coords.lon)

julia> a = Ref{LatLon}(LatLon(0,0))
       a[] = LatLonAlt(0,0,1e10)
       a[] 
# Where did my Alt go?!
GeodeticLatLon{WGS84Latest} coordinates
├─ lat: 0.0°
└─ lon: 0.0°

Of course, one could argue that the user asked for this since they explicitly requested a Ref{LatLon}, but I'm not sure whether this argument strikes the right balance between supporting power users and protecting mere mortals from silly mistakes. Also, just for reference, the Julia docs say this about convert():

[convert()] is also usually lossless; converting a value to a different type and back again should result in the exact same value.

from coordrefsystems.jl.

juliohm avatar juliohm commented on June 14, 2024

Yes, we saw this pattern before, and decided that the feature is good enough to ignore the convert footnote. The problem with convert is that it was designed with very strict computer-science use cases in mind. We could have used a different function name to avoid these pedantic footnotes, but then we would loose the nice syntax

Mercator[LatLon(0,0), LatLon(0,90), ...]

and all the nice automatic conversions that Julia does when it encounters two CRS of different type.

from coordrefsystems.jl.

ettersi avatar ettersi commented on June 14, 2024

We could have used a different function name to avoid these pedantic footnotes, but then we would loose the nice syntax

Mercator[LatLon(0,0), LatLon(0,90), ...]

and all the nice automatic conversions that Julia does when it encounters two CRS of different type.

You can always have a separate conversion mechanism (e.g. constructors) which is free to add or remove information, and then make convert() dispatch to this mechanism whenever the conversion is lossless.

from coordrefsystems.jl.

juliohm avatar juliohm commented on June 14, 2024

I don't remember out of my head now, but I think Julia works in the opposite direction, it uses convert as a fallback to construct a type to another. In any case, I believe that we are fine with adopting convert between LatLon and LatLonAlt.

Feel free to submit a PR for it. We can review and merge today, together with the other PR, and then release a patch.

from coordrefsystems.jl.

juliohm avatar juliohm commented on June 14, 2024

Fixed on master.

from coordrefsystems.jl.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.