-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from JamesFysh/master
Initial rust implementation
- Loading branch information
Showing
10 changed files
with
633 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
sudo: false | ||
# Travis only supports one language per project, so we need to put something | ||
# here. node_js is as good as any other I suppose. | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
|
||
# For rust, we need to install cargo, rustc. In order to do that, we'll use | ||
# apt-get, which requires sudo. | ||
sudo: true | ||
|
||
# The rust-nightly package is only built for 14.04 (Trusty) and 16.04 (Xenial), | ||
# so we cannot use the default Travis ubuntu image (Precise) for these tests. | ||
dist: trusty | ||
|
||
# Install package dependencies. See | ||
# http://docs.travis-ci.com/user/installing-dependencies/ | ||
# gulp: required for JS testing | ||
before_install: | ||
- npm install -g gulp | ||
- yes | sudo add-apt-repository ppa:jonathonf/rustlang | ||
- yes | sudo add-apt-repository ppa:jonathonf/llvm | ||
- yes | sudo add-apt-repository ppa:jonathonf/gcc | ||
- sudo apt-get update | ||
|
||
install: | ||
sudo apt-get -y install libstd-rust-1.16 libstd-rust-dev rustc cargo | ||
|
||
# Define the list of directories to execute tests in. | ||
env: | ||
- TEST_DIR=js | ||
- TEST_DIR=go | ||
- TEST_DIR=ruby | ||
- TEST_DIR=rust | ||
|
||
# Test script to run. This is called once for each TEST_DIR value above. | ||
script: ./run_tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "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 = "Apache-2.0" | ||
repository = "https://github.com/google/open-location-code" | ||
keywords = ["geography", "geospatial", "gis", "gps", "olc"] | ||
exclude = ["rust.iml"] | ||
|
||
[dependencies] | ||
geo = "^0.4.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 | ||
) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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; | ||
|
Oops, something went wrong.