Remove duplicate values and cleanup

This commit is contained in:
Austen Adler 2023-02-25 11:14:15 -05:00
parent 879ee19a69
commit 213f7fd3e7
8 changed files with 20111 additions and 20026 deletions

88
Cargo.lock generated
View File

@ -41,6 +41,18 @@ dependencies = [
"serde",
]
[[package]]
name = "bumpalo"
version = "3.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cgmath"
version = "0.18.0"
@ -106,6 +118,15 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb"
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.5.0"
@ -142,6 +163,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
[[package]]
name = "phf"
version = "0.11.1"
@ -287,6 +314,13 @@ dependencies = [
"words",
]
[[package]]
name = "this_algorithm-wasm"
version = "0.1.0"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "thiserror"
version = "1.0.38"
@ -313,6 +347,60 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "wasm-bindgen"
version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
[[package]]
name = "words"
version = "0.1.0"

View File

@ -7,7 +7,7 @@ edition = "2021"
members = [
".",
"./words",
# "./this_algorithm",
"./this_algorithm-wasm/",
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -20,7 +20,7 @@ use words::Word;
pub type Number = u32;
/// The S2 cellid level for the entire algorithm
pub const CELLID_LEVEL: u8 = 23;
pub const CELLID_LEVEL: u64 = 23;
/// The maximum number value for V0
pub const V0_MAX_NUMBER: u32 = 1024;

View File

@ -2,12 +2,16 @@
from random import random
with open("./00-sample-latlon.csv", "w") as f:
f.write("lat,lon\n")
seen_coords = set()
# Normalized
for i in range(10000):
lat = (random() - .5) * 2 * 90
lon = (random() - .5) * 2 * 180
f.write(f"{lat},{lon}\n")
s = f"{lat},{lon}\n"
if s not in seen_coords:
seen_coords.add(s)
f.write(s)
# Edge cases
# Do both positive and negative
@ -21,10 +25,16 @@ with open("./00-sample-latlon.csv", "w") as f:
lat = neg * (lat_i - dec)
lon = neg * (lon_i - dec)
f.write(f"{lat:f},{lon:f}\n")
s = f"{lat:f},{lon:f}\n"
if s not in seen_coords:
seen_coords.add(s)
f.write(s)
# # Non-normalized
# for i in range(10000):
# lat = (random() - .5) * 2 * 1000
# lon = (random() - .5) * 2 * 1000
# f.write(f"{lat},{lon}\n")
# s = f"{lat},{lon}\n"
# if s not in seen_coords:
# seen_coords.add(s)
# f.write(s)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -24,20 +24,17 @@ fn test_cellid_translation() {
assert_eq!(entry.cell_id, CellID(entry.cell_id).0);
assert_eq!(
(entry.cell_id & CELLID_LEVEL_23_BITMASK) | CELLID_LEVEL_23_END_BIT,
CellID(entry.cell_id).parent(CELLID_LEVEL as u64).0
CellID(entry.cell_id).parent(CELLID_LEVEL).0
);
// Make sure the address is at the right level
assert_eq!(addr_cellid.level(), CELLID_LEVEL as u64);
assert_eq!(addr_cellid.level(), CELLID_LEVEL);
// Next, check if creating an address from a cellid matches itself
assert_eq!(addr, Address::from_cellid_u64(entry.cell_id));
// Now check if the actual cell id matches
assert_eq_u64!(
addr_cellid.0,
CellID(entry.cell_id).parent(CELLID_LEVEL as u64).0
);
assert_eq_u64!(addr_cellid.0, CellID(entry.cell_id).parent(CELLID_LEVEL).0);
}
}
@ -45,11 +42,7 @@ fn test_cellid_translation() {
fn test_encoding() {
for (_idx, entry) in test_events().iter().enumerate() {
let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap();
eprintln!("Entry:");
eprintln!("\t({}, {})", entry.lat, entry.lon);
eprintln!("\t{:0>64b}", entry.cell_id);
eprintln!("\t{:0>64b}", addr.as_cell_id().0);
eprintln!("\t{addr:?}");
eprintln!("({}, {}) => {addr}", entry.lat, entry.lon);
}
assert!(false);
}

View File

@ -41,7 +41,11 @@ pub struct TestEntry {
pub lon: f64,
pub cell_id: u64,
}
/// Bitmask to preserve all data bits at level 23
pub const CELLID_LEVEL_23_BITMASK: u64 =
0b11111111_11111111_11111111_11111111_11111111_11111111_10000000_00000000;
/// The single 1 bit at the end of level 23
pub const CELLID_LEVEL_23_END_BIT: u64 =
0b00000000_00000000_00000000_00000000_00000000_00000000_01000000_00000000;