-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial rust implementation #71
Conversation
working implementation (passes all validation, enc/dec, shorten/recover unit-tests); probably room for improvement wrt comments, layout.
Correct the 'repository' field, since I decided to implement this as part of Google' open-location-code repository.
Take all lng/lat coordinates as Point<f64>, rather than as two f64 values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi James, thanks for this. I've reviewed and added some comments. Some of them are pretty minor (newlines & formatting), and some are jut shuffling code around. Hopefully not too much!
rust/Cargo.toml
Outdated
description = "Library for translating between GPS coordinates (WGS84) and Open Location Code" | ||
version = "0.1.0" | ||
authors = ["James Fysh <james.fysh@gmail.com>"] | ||
license = "MIT/Apache-2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the license to just Apache-2.0, so it matches the rest of the project?
rust/Cargo.toml
Outdated
version = "0.1.0" | ||
authors = ["James Fysh <james.fysh@gmail.com>"] | ||
license = "MIT/Apache-2.0" | ||
repository = "https://github.com/JamesFysh/open-location-code" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to point to this repo
rust/Cargo.toml
Outdated
@@ -0,0 +1,11 @@ | |||
[package] | |||
name = "olc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a longer package name that more clearly indicates what it is, e.g., "open-location-code".
@@ -32,4 +32,12 @@ if [ "$TEST_DIR" == "ruby" ]; then | |||
exit | |||
fi | |||
|
|||
if [ "$TEST_DIR" == "rust" ]; then | |||
curl https://sh.rustup.rs -sSf | sh -s -- -y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT most other travis configs are using apt-get to fetch and install rust-nightly. Is this possible?
before_install:
- yes | sudo add-apt-repository ppa:hansjorg/rust
- sudo apt-get update
install:
- sudo apt-get install rust-nightly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that was painful to implement! I'll have to invest a bit of time in a local setup of TravisCI so I can verify it works before pushing changes, going forward!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I know, Travis changes can be painful.
rust/src/interface.rs
Outdated
|
||
// Latitude 90 needs to be adjusted to be just less, so the returned code | ||
// can also be decoded. | ||
if lat == LATITUDE_MAX { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using == to compare floats can be optimistic. Maybe use a comparison that the difference between them is very, very small, or that lat is > LATITUDE_MAX? e.g.
if lat > LATITUDE_MAX || (LATITUDE_MAX - lat) < 0.0000000001f64 {
self.code_length + other.code_length | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline.
pub const GRID_ROWS: f64 = 5f64; | ||
|
||
// Minimum length of a code that can be shortened. | ||
pub const MIN_TRIMMABLE_CODE_LEN: usize = 6; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline.
longitude += area_range; | ||
} | ||
Ok(encode(Point::new(longitude, latitude), code_area.code_length)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline.
} | ||
None | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline.
|
||
tested += 1; | ||
} | ||
assert!(tested > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice check ;-)
- Project name, licensing, repository location - Newlines - Code-style - Corrections to unit-tests - Safer approach to floating-point comparison - Use of constants rather than magic numbers
Having a proper look at this; The rust-nightly package is only build for 14.04. Travis (by default) uses 12.04 (Precise), but has a 14.04 image which you can opt for. Hopefully this doesn't break anything else!
The PPA doesn't have a rust-nightly. It does have a rustc package, and also a separate cargo package. Let's try those!
Not sure why the choice here by apt-get is to fail, rather than pull in the missing dependent package. Oh well
.. Not excited to be putting specific version numbers in. Starting to wish I'd stuck with the rustup approach; it's a little more predicatable!
I think I've covered off all the changes you asked for, and (finally) managed to get Travis CI working correctly. Do I need to do anything to confirm that the requested changes have been made? |
Thanks @JamesFysh, you don't have to do anything, I don't have time today but I'll merge it early next week. Thanks! |
working implementation (passes all validation, enc/dec, shorten/recover unit-tests); probably room for improvement wrt comments, layout.