georust / geographiclib-rs

A port of geographiclib in Rust.
MIT License
41 stars 9 forks source link

make geomath::norm use &mut arguments #36

Closed stonylohr closed 3 years ago

stonylohr commented 3 years ago

Currently, geomath::norm passes its 2 arguments by value and returns a size 2 tuple. Every caller then turns around and assigns the returned values back to the inputs or variables that shadow the inputs. Both the C++ and Java versions use in-out arguments to achieve this affect more smoothly. I think the Python doesn't because it's more difficult to achieve that in-out effect with a non-object type in Python.

I think we should change the function to use in-out arguments (&mut f64), like the C++ and Java versions. My main reason for this is that it will make all my subsequent code comparisons easier by removing one type of possible copy/paste or typo error in this often-used function, where a result value could accidentally be assigned to the wrong variable. Secondarily, it makes the code cleaner, and probably just a little bit faster (though probably not enough to be reliably noticeable in benches).

michaelkirk commented 3 years ago

SGTM