-
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
Changes from 8 commits
77685cd
52553ca
33eeb97
ad2dfed
3f11946
15831b4
ee42858
8cd36b6
e25df37
655ff46
464ecef
37b2c36
904c44b
c0fa5de
2ab0872
c6ecb22
019f8b4
5e8614b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "olc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". |
||
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 commentThe 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? |
||
repository = "https://github.com/JamesFysh/open-location-code" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to point to this repo |
||
keywords = ["geography", "geospatial", "gis", "gps", "olc"] | ||
|
||
[dependencies] | ||
geo = "^0.4.3" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use geo::{Point}; | ||
|
||
pub struct CodeArea { | ||
pub south: f64, | ||
pub west: f64, | ||
pub north: f64, | ||
pub east: f64, | ||
pub center: Point<f64>, | ||
pub code_length: usize, | ||
} | ||
|
||
impl CodeArea { | ||
pub fn new(south: f64, west: f64, north: f64, east: f64, code_length: usize) -> CodeArea { | ||
CodeArea { | ||
south: south, west: west, north: north, east: east, | ||
center: Point::new((west + east) / 2f64, (south + north) / 2f64), | ||
code_length: code_length | ||
} | ||
} | ||
|
||
pub fn merge(self, other: CodeArea) -> CodeArea { | ||
CodeArea::new( | ||
self.south + other.south, | ||
self.west + other.west, | ||
self.north + other.north, | ||
self.east + other.east, | ||
self.code_length + other.code_length | ||
) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add newline. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// A separator used to break the code into two parts to aid memorability. | ||
pub const SEPARATOR: char = '+'; | ||
|
||
// The number of characters to place before the separator. | ||
pub const SEPARATOR_POSITION: usize = 8; | ||
|
||
// The character used to pad codes. | ||
pub const PADDING_CHAR: char = '0'; | ||
pub const PADDING_CHAR_STR: &'static str = "0"; | ||
|
||
// The character set used to encode the values. | ||
pub const CODE_ALPHABET: [char; 20] = [ | ||
'2', '3', '4', '5', '6', | ||
'7', '8', '9', 'C', 'F', | ||
'G', 'H', 'J', 'M', 'P', | ||
'Q', 'R', 'V', 'W', 'X', | ||
]; | ||
|
||
// The base to use to convert numbers to/from. | ||
pub const ENCODING_BASE: f64 = 20f64; | ||
|
||
// The maximum value for latitude in degrees. | ||
pub const LATITUDE_MAX: f64 = 90f64; | ||
|
||
// The maximum value for longitude in degrees. | ||
pub const LONGITUDE_MAX: f64 = 180f64; | ||
|
||
// Maxiumum code length using lat/lng pair encoding. The area of such a | ||
// code is approximately 13x13 meters (at the equator), and should be suitable | ||
// for identifying buildings. This excludes prefix and separator characters. | ||
pub const PAIR_CODE_LENGTH: usize = 10; | ||
|
||
// The resolution values in degrees for each position in the lat/lng pair | ||
// encoding. These give the place value of each position, and therefore the | ||
// dimensions of the resulting area. | ||
pub const PAIR_RESOLUTIONS: [f64; 5] = [ | ||
20.0f64, 1.0f64, 0.05f64, 0.0025f64, 0.000125f64 | ||
]; | ||
|
||
// Number of columns in the grid refinement method. | ||
pub const GRID_COLUMNS: f64 = 4f64; | ||
|
||
// Number of rows in the grid refinement method. | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Add newline. |
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?
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.