Update to use four digits and 4k wordlist size
This commit is contained in:
parent
9aa6a68de0
commit
db83a68923
@ -19,14 +19,14 @@ If you want to see the steps to get to this definition, go to link:DESIGN.html[D
|
|||||||
[source,title='xpin and S2 CellID Format']
|
[source,title='xpin and S2 CellID Format']
|
||||||
----
|
----
|
||||||
=== xpin Format ===
|
=== xpin Format ===
|
||||||
WORD2 (13 bits) : vvvvvvvvvvvvv
|
WORD2 (12 bits) [52, 63] : vvvvvvvvvvvv
|
||||||
WORD1 (13 bits) : | |vvv vvvvvvvvvv
|
WORD1 (12 bits) [40, 51] : | |vvvv vvvvvvvv
|
||||||
WORD0 (13 bits) : | | |vvvvvv vvvvvvv
|
WORD0 (12 bits) [28, 39] : | | |vvvvvvvv vvvv
|
||||||
0000 (10 bits) : | | | |vvvvvvvvv v
|
0000 (13 bits) [15, 27] : | | | |vvvvvvvvvvvv v
|
||||||
Not represented : | | | | |
|
Not represented : | | | | |
|
||||||
: | | | | |
|
: | | | | |
|
||||||
Bit : 63 51 48 38 32 25 16| 0
|
Bit : 63 52 48 40 32 28 16| 0
|
||||||
: | | | | | | | | |
|
: | | | | | | | | |
|
||||||
: 0100101110101000 1011100010010011 1001001100100100 1100000000000000
|
: 0100101110101000 1011100010010011 1001001100100100 1100000000000000
|
||||||
=== S2 CellID Format === | | || |
|
=== S2 CellID Format === | | || |
|
||||||
Face number : ^^^ || |
|
Face number : ^^^ || |
|
||||||
|
17
justfile
17
justfile
@ -1,6 +1,6 @@
|
|||||||
build: fmt rust-build build-wasm js-build
|
build: fmt rust-build wasm-build js-build
|
||||||
|
|
||||||
all: clean fmt build build-docs # rust-test
|
all: clean fmt build docs-build # rust-test
|
||||||
rsync -ha ./web-frontend/build/ build/
|
rsync -ha ./web-frontend/build/ build/
|
||||||
du -shc build/* | sort -h
|
du -shc build/* | sort -h
|
||||||
|
|
||||||
@ -11,16 +11,21 @@ rust-test:
|
|||||||
rust-build:
|
rust-build:
|
||||||
cargo build --all
|
cargo build --all
|
||||||
|
|
||||||
build-wasm:
|
wasm-build:
|
||||||
wasm-pack build --target web xpin-wasm
|
wasm-pack build --target web xpin-wasm
|
||||||
|
|
||||||
js-build: build-wasm
|
wordlist-build:
|
||||||
|
. wordlist/venv/bin/activate && cd wordlist && for i in *.py; do "./${i}"; done
|
||||||
|
|
||||||
|
js-build: wasm-build docs-build
|
||||||
|
# mkdir -p ./web-frontend/static/docs/
|
||||||
|
# rsync -ha ./build/docs/ ./web-frontend/static/docs/
|
||||||
yarn --cwd ./web-frontend/ build
|
yarn --cwd ./web-frontend/ build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -vrf build
|
rm -vrf build
|
||||||
|
|
||||||
build-docs:
|
docs-build:
|
||||||
earthly +docs
|
earthly +docs
|
||||||
cargo doc --all
|
cargo doc --all
|
||||||
|
|
||||||
@ -43,3 +48,5 @@ init:
|
|||||||
yarn --cwd ./web-frontend/
|
yarn --cwd ./web-frontend/
|
||||||
cargo fetch
|
cargo fetch
|
||||||
cargo install wasm-pack
|
cargo install wasm-pack
|
||||||
|
if [ ! -d "wordlist/venv" ]; then python3 -m virtualenv wordlist/venv -p "$(which python3)"; fi; export OSTYPE=linux-gnu && . wordlist/venv/bin/activate
|
||||||
|
export OSTYPE=linux-gnu && . wordlist/venv/bin/activate && pip install -r wordlist/requirements.txt && python -c 'import nltk; nltk.download('wordnet')'
|
||||||
|
@ -2,6 +2,9 @@ use std::ops::RangeInclusive;
|
|||||||
|
|
||||||
use s2::{cellid::CellID, latlng::LatLng};
|
use s2::{cellid::CellID, latlng::LatLng};
|
||||||
|
|
||||||
|
pub(crate) const TWELVE_BITS: u64 = 0b1111_1111_1111;
|
||||||
|
pub(crate) const TEN_BITS: u64 = 0b1111_1111_11;
|
||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
pub fn lat_lon_to_cellid(lat: f64, lon: f64) -> Result<CellID, Error> {
|
pub fn lat_lon_to_cellid(lat: f64, lon: f64) -> Result<CellID, Error> {
|
||||||
|
23
src/lib.rs
23
src/lib.rs
@ -23,9 +23,9 @@ pub type Number = u32;
|
|||||||
pub const CELLID_LEVEL: u64 = 23;
|
pub const CELLID_LEVEL: u64 = 23;
|
||||||
|
|
||||||
/// The maximum number value for V0
|
/// The maximum number value for V0
|
||||||
pub const V0_MAX_NUMBER: u32 = 1024;
|
pub const V0_MAX_NUMBER: u32 = 9120;
|
||||||
/// The minimum number value for V0
|
/// The minimum number value for V0
|
||||||
pub const V0_MIN_NUMBER: u32 = 1;
|
pub const V0_MIN_NUMBER: u32 = 1024;
|
||||||
|
|
||||||
// Any encoding or decoding error
|
// Any encoding or decoding error
|
||||||
#[derive(Error, Debug, Eq, PartialEq)]
|
#[derive(Error, Debug, Eq, PartialEq)]
|
||||||
@ -186,9 +186,10 @@ impl Address<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_components(number: Number, other_components: &[&str]) -> Result<Self, Error> {
|
fn from_components(number: Number, other_components: &[&str]) -> Result<Self, Error> {
|
||||||
match extract_version(number)? {
|
// match extract_version(number)? {
|
||||||
Version::V0 => Self::parse_v0(number, other_components),
|
// Version::V0 => Self::parse_v0(number, other_components),
|
||||||
}
|
// }
|
||||||
|
Self::parse_v0(number, other_components)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the address as a [`CellID`] value
|
/// Get the address as a [`CellID`] value
|
||||||
@ -211,12 +212,12 @@ impl Address<'_> {
|
|||||||
///
|
///
|
||||||
/// The version number is set by the two bits 11 and 12
|
/// The version number is set by the two bits 11 and 12
|
||||||
// TODO: impl TryFrom ?
|
// TODO: impl TryFrom ?
|
||||||
const fn extract_version(number: Number) -> Result<Version, Error> {
|
// const fn extract_version(number: Number) -> Result<Version, Error> {
|
||||||
match ((number >> 10) & 0b11) as u8 {
|
// match ((number >> 10) & 0b11) as u8 {
|
||||||
0 => Ok(Version::V0),
|
// 0 => Ok(Version::V0),
|
||||||
v => Err(Error::UnimplementedVersion(v)),
|
// v => Err(Error::UnimplementedVersion(v)),
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl Display for Address<'_> {
|
impl Display for Address<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
32
src/v0.rs
32
src/v0.rs
@ -2,6 +2,8 @@ use crate::{conversions, Address, Version, CELLID_LEVEL};
|
|||||||
use std::ops::{Add, RangeInclusive};
|
use std::ops::{Add, RangeInclusive};
|
||||||
use words::NUMBER_TO_WORDS;
|
use words::NUMBER_TO_WORDS;
|
||||||
|
|
||||||
|
use conversions::TEN_BITS;
|
||||||
|
use conversions::TWELVE_BITS;
|
||||||
use s2::{cell::Cell, cellid::CellID};
|
use s2::{cell::Cell, cellid::CellID};
|
||||||
|
|
||||||
pub struct UnpackedCellID {
|
pub struct UnpackedCellID {
|
||||||
@ -21,10 +23,10 @@ impl From<CellID> for UnpackedCellID {
|
|||||||
impl From<u64> for UnpackedCellID {
|
impl From<u64> for UnpackedCellID {
|
||||||
fn from(cellid: u64) -> Self {
|
fn from(cellid: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
number_bits: conversions::extract_binary(cellid, 15..=24) as u16,
|
number_bits: conversions::extract_binary(cellid, 15..=27) as u16,
|
||||||
word0_bits: conversions::extract_binary(cellid, 25..=37) as u16,
|
word0_bits: conversions::extract_binary(cellid, 28..=39) as u16,
|
||||||
word1_bits: conversions::extract_binary(cellid, 38..=50) as u16,
|
word1_bits: conversions::extract_binary(cellid, 40..=51) as u16,
|
||||||
word2_bits: conversions::extract_binary(cellid, 51..=63) as u16,
|
word2_bits: conversions::extract_binary(cellid, 52..=63) as u16,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +38,7 @@ impl From<UnpackedCellID> for Address<'_> {
|
|||||||
let word2 = words::NUMBER_TO_WORDS[unpacked_cellid.word2_bits as usize][0];
|
let word2 = words::NUMBER_TO_WORDS[unpacked_cellid.word2_bits as usize][0];
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
number: u32::from(unpacked_cellid.number_bits),
|
number: u32::from(unpacked_cellid.number_bits) + 1024,
|
||||||
words: [word0, word1, word2],
|
words: [word0, word1, word2],
|
||||||
version: Version::V0,
|
version: Version::V0,
|
||||||
}
|
}
|
||||||
@ -46,7 +48,7 @@ impl From<UnpackedCellID> for Address<'_> {
|
|||||||
impl From<&Address<'_>> for UnpackedCellID {
|
impl From<&Address<'_>> for UnpackedCellID {
|
||||||
fn from(value: &Address) -> Self {
|
fn from(value: &Address) -> Self {
|
||||||
Self {
|
Self {
|
||||||
number_bits: value.number as u16,
|
number_bits: value.number as u16 - 1024,
|
||||||
word0_bits: value.words[0].number,
|
word0_bits: value.words[0].number,
|
||||||
word1_bits: value.words[1].number,
|
word1_bits: value.words[1].number,
|
||||||
word2_bits: value.words[2].number,
|
word2_bits: value.words[2].number,
|
||||||
@ -57,17 +59,15 @@ impl From<&Address<'_>> for UnpackedCellID {
|
|||||||
#[allow(clippy::use_self)]
|
#[allow(clippy::use_self)]
|
||||||
impl From<UnpackedCellID> for u64 {
|
impl From<UnpackedCellID> for u64 {
|
||||||
fn from(value: UnpackedCellID) -> Self {
|
fn from(value: UnpackedCellID) -> Self {
|
||||||
let ten_bits = 0b1111_1111_11;
|
|
||||||
let thirteen_bits = 0b1_1111_1111_1111;
|
|
||||||
let mut ret = 0b0;
|
let mut ret = 0b0;
|
||||||
|
|
||||||
// Add words in reverse order
|
// Add words in reverse order
|
||||||
ret = (ret << 13) | (u64::from(value.word2_bits) & thirteen_bits);
|
ret = (ret << 12) | (u64::from(value.word2_bits) & TWELVE_BITS);
|
||||||
ret = (ret << 13) | (u64::from(value.word1_bits) & thirteen_bits);
|
ret = (ret << 12) | (u64::from(value.word1_bits) & TWELVE_BITS);
|
||||||
ret = (ret << 13) | (u64::from(value.word0_bits) & thirteen_bits);
|
ret = (ret << 12) | (u64::from(value.word0_bits) & TWELVE_BITS);
|
||||||
|
|
||||||
// Add the number
|
// Add the number
|
||||||
ret = (ret << 10) | (u64::from(value.number_bits) & ten_bits);
|
ret = (ret << 13) | (u64::from(value.number_bits) & TEN_BITS);
|
||||||
|
|
||||||
// Add the final bit
|
// Add the final bit
|
||||||
ret = (ret << 1) | 0b1;
|
ret = (ret << 1) | 0b1;
|
||||||
@ -84,11 +84,3 @@ impl From<UnpackedCellID> for CellID {
|
|||||||
Self(value.into())
|
Self(value.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<A: AsRef<Address<'a>>> From<A> for UnpackedCellID {
|
|
||||||
// fn from(addr: A) -> Self {
|
|
||||||
// let number_bits = addr.
|
|
||||||
|
|
||||||
// CellID(ret)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
@ -79,6 +79,7 @@ ALBERTA
|
|||||||
ALBION
|
ALBION
|
||||||
ALBUMIN
|
ALBUMIN
|
||||||
ALBUQUERQUE
|
ALBUQUERQUE
|
||||||
|
ALCOHOL
|
||||||
ALCOHOLISM
|
ALCOHOLISM
|
||||||
ALDER
|
ALDER
|
||||||
ALDERMAN
|
ALDERMAN
|
||||||
@ -382,6 +383,8 @@ BLEED
|
|||||||
BLEEDING
|
BLEEDING
|
||||||
BLEST
|
BLEST
|
||||||
BLEW
|
BLEW
|
||||||
|
BLOWING
|
||||||
|
BLUE
|
||||||
BLUNT
|
BLUNT
|
||||||
BO
|
BO
|
||||||
BOB
|
BOB
|
||||||
@ -880,6 +883,7 @@ DENMARK
|
|||||||
DENNIS
|
DENNIS
|
||||||
DENT
|
DENT
|
||||||
DENVER
|
DENVER
|
||||||
|
DEPRESSION
|
||||||
DEPRESSIVE
|
DEPRESSIVE
|
||||||
DERBY
|
DERBY
|
||||||
DERBYSHIRE
|
DERBYSHIRE
|
||||||
@ -1120,6 +1124,7 @@ FAHRENHEIT
|
|||||||
FAIL
|
FAIL
|
||||||
FAILING
|
FAILING
|
||||||
FAILURE
|
FAILURE
|
||||||
|
FAINT
|
||||||
FAIRBANKS
|
FAIRBANKS
|
||||||
FAIRFAX
|
FAIRFAX
|
||||||
FAKE
|
FAKE
|
||||||
@ -3333,7 +3338,3 @@ ZOOLOGICAL
|
|||||||
ZOOLOGY
|
ZOOLOGY
|
||||||
ZULU
|
ZULU
|
||||||
ZURICH
|
ZURICH
|
||||||
ALCOHOL
|
|
||||||
DEPRESSION
|
|
||||||
FAINT
|
|
||||||
BLOWING
|
|
||||||
|
|
@ -98,10 +98,12 @@ pub static NUMBER_TO_WORDS: &[&[&Word]] = &["#
|
|||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Word {
|
pub struct Word {
|
||||||
/// The word itself
|
/// The word itself
|
||||||
|
#[serde(rename = "WORD")]
|
||||||
pub word: String,
|
pub word: String,
|
||||||
|
|
||||||
/// The binary representation of this number
|
/// The binary representation of this number
|
||||||
///
|
///
|
||||||
/// The words are responsible for 13 bits of data, so this is fine to fit in a u16
|
/// The words are responsible for 13 bits of data, so this is fine to fit in a u16
|
||||||
|
#[serde(rename = "NUMBER")]
|
||||||
pub number: u16,
|
pub number: u16,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user