Skip to content

Commit 8315940

Browse files
authored
Merge branch 'master' into master
2 parents 9b548ec + ee7425e commit 8315940

File tree

10 files changed

+633
-1
lines changed

10 files changed

+633
-1
lines changed

.travis.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
sudo: false
21
# Travis only supports one language per project, so we need to put something
32
# here. node_js is as good as any other I suppose.
43
language: node_js
54
node_js:
65
- "0.10"
76

7+
# For rust, we need to install cargo, rustc. In order to do that, we'll use
8+
# apt-get, which requires sudo.
9+
sudo: true
10+
11+
# The rust-nightly package is only built for 14.04 (Trusty) and 16.04 (Xenial),
12+
# so we cannot use the default Travis ubuntu image (Precise) for these tests.
13+
dist: trusty
814

915
# Install package dependencies. See
1016
# http://docs.travis-ci.com/user/installing-dependencies/
1117
# gulp: required for JS testing
1218
before_install:
1319
- npm install -g gulp
20+
- yes | sudo add-apt-repository ppa:jonathonf/rustlang
21+
- yes | sudo add-apt-repository ppa:jonathonf/llvm
22+
- yes | sudo add-apt-repository ppa:jonathonf/gcc
23+
- sudo apt-get update
24+
25+
install:
26+
sudo apt-get -y install libstd-rust-1.16 libstd-rust-dev rustc cargo
1427

1528
# Define the list of directories to execute tests in.
1629
env:
1730
- TEST_DIR=js
1831
- TEST_DIR=go
1932
- TEST_DIR=ruby
2033
- TEST_DIR=python
34+
- TEST_DIR=rust
2135

2236
# Test script to run. This is called once for each TEST_DIR value above.
2337
script: ./run_tests.sh

run_tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ if [ "$TEST_DIR" == "python" ]; then
3737
exit
3838
fi
3939

40+
if [ "$TEST_DIR" == "rust" ]; then
41+
curl https://sh.rustup.rs -sSf | sh -s -- -y
42+
export PATH=$PATH:$HOME/.cargo/bin
43+
rustup update stable
44+
cd rust && rustup run stable cargo test
45+
exit
46+
fi
47+
4048
echo "Unknown test directory: $TEST_DIR"

rust/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "open-location-code"
3+
description = "Library for translating between GPS coordinates (WGS84) and Open Location Code"
4+
version = "0.1.0"
5+
authors = ["James Fysh <james.fysh@gmail.com>"]
6+
license = "Apache-2.0"
7+
repository = "https://github.com/google/open-location-code"
8+
keywords = ["geography", "geospatial", "gis", "gps", "olc"]
9+
exclude = ["rust.iml"]
10+
11+
[dependencies]
12+
geo = "^0.4.3"

rust/src/codearea.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use geo::{Point};
2+
3+
pub struct CodeArea {
4+
pub south: f64,
5+
pub west: f64,
6+
pub north: f64,
7+
pub east: f64,
8+
pub center: Point<f64>,
9+
pub code_length: usize,
10+
}
11+
12+
impl CodeArea {
13+
pub fn new(south: f64, west: f64, north: f64, east: f64, code_length: usize) -> CodeArea {
14+
CodeArea {
15+
south: south, west: west, north: north, east: east,
16+
center: Point::new((west + east) / 2f64, (south + north) / 2f64),
17+
code_length: code_length
18+
}
19+
}
20+
21+
pub fn merge(self, other: CodeArea) -> CodeArea {
22+
CodeArea::new(
23+
self.south + other.south,
24+
self.west + other.west,
25+
self.north + other.north,
26+
self.east + other.east,
27+
self.code_length + other.code_length
28+
)
29+
}
30+
}
31+

rust/src/consts.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// A separator used to break the code into two parts to aid memorability.
2+
pub const SEPARATOR: char = '+';
3+
4+
// The number of characters to place before the separator.
5+
pub const SEPARATOR_POSITION: usize = 8;
6+
7+
// The character used to pad codes.
8+
pub const PADDING_CHAR: char = '0';
9+
pub const PADDING_CHAR_STR: &'static str = "0";
10+
11+
// The character set used to encode the values.
12+
pub const CODE_ALPHABET: [char; 20] = [
13+
'2', '3', '4', '5', '6',
14+
'7', '8', '9', 'C', 'F',
15+
'G', 'H', 'J', 'M', 'P',
16+
'Q', 'R', 'V', 'W', 'X',
17+
];
18+
19+
// The base to use to convert numbers to/from.
20+
pub const ENCODING_BASE: f64 = 20f64;
21+
22+
// The maximum value for latitude in degrees.
23+
pub const LATITUDE_MAX: f64 = 90f64;
24+
25+
// The maximum value for longitude in degrees.
26+
pub const LONGITUDE_MAX: f64 = 180f64;
27+
28+
// Maxiumum code length using lat/lng pair encoding. The area of such a
29+
// code is approximately 13x13 meters (at the equator), and should be suitable
30+
// for identifying buildings. This excludes prefix and separator characters.
31+
pub const PAIR_CODE_LENGTH: usize = 10;
32+
33+
// The resolution values in degrees for each position in the lat/lng pair
34+
// encoding. These give the place value of each position, and therefore the
35+
// dimensions of the resulting area.
36+
pub const PAIR_RESOLUTIONS: [f64; 5] = [
37+
20.0f64, 1.0f64, 0.05f64, 0.0025f64, 0.000125f64
38+
];
39+
40+
// Number of columns in the grid refinement method.
41+
pub const GRID_COLUMNS: f64 = 4f64;
42+
43+
// Number of rows in the grid refinement method.
44+
pub const GRID_ROWS: f64 = 5f64;
45+
46+
// Minimum length of a code that can be shortened.
47+
pub const MIN_TRIMMABLE_CODE_LEN: usize = 6;
48+

0 commit comments

Comments
 (0)