Continue work on docs and decoding
This commit is contained in:
parent
e2778d281c
commit
ee30d47d51
19
build.earth
19
build.earth
@ -14,21 +14,14 @@ docs-build:
|
|||||||
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install bison flex libffi-dev libxml2-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev fonts-lyx cmake
|
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install bison flex libffi-dev libxml2-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev fonts-lyx cmake
|
||||||
RUN gem install asciidoctor-mathematical
|
RUN gem install asciidoctor-mathematical
|
||||||
|
|
||||||
COPY --dir ./design-workflow .
|
COPY --dir ./docs .
|
||||||
|
|
||||||
RUN asciidoctor -r asciidoctor-mathematical -a mathematical-format=sv -a "!webfonts" -- ./design-workflow/*.adoc
|
RUN asciidoctor -r asciidoctor-mathematical -a mathematical-format=svg -a "!webfonts" -- ./docs/*.adoc
|
||||||
RUN \
|
RUN \
|
||||||
cd ./design-workflow/ && \
|
find docs -type f -not -iname '*.html' -not -iname '*.png' -not -iname '*.svg' -delete && \
|
||||||
rm -rf \
|
|
||||||
*.adoc \
|
|
||||||
*.ods \
|
|
||||||
*.csv \
|
|
||||||
*.txt.gz \
|
|
||||||
*.ipynb \
|
|
||||||
.ipynb_checkpoints \
|
|
||||||
:
|
:
|
||||||
|
|
||||||
SAVE ARTIFACT ./design-workflow
|
SAVE ARTIFACT ./docs
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
FROM golang:latest
|
FROM golang:latest
|
||||||
@ -38,9 +31,9 @@ docs:
|
|||||||
|
|
||||||
RUN cd minify && go install ./cmd/minify
|
RUN cd minify && go install ./cmd/minify
|
||||||
|
|
||||||
COPY +docs-build/./design-workflow/ ./design-workflow/
|
COPY +docs-build/docs/ ./docs/
|
||||||
RUN minify --version
|
RUN minify --version
|
||||||
RUN minify --sync --recursive --output output/ ./design-workflow/
|
RUN minify --sync --recursive --output output/ ./docs/
|
||||||
|
|
||||||
# RUN mv output/static/* output/
|
# RUN mv output/static/* output/
|
||||||
# RUN rmdir output/static
|
# RUN rmdir output/static
|
||||||
|
@ -193,19 +193,21 @@ S2 addresses map to a cell at a given level. Two cell level candidates were chos
|
|||||||
|
|
||||||
.Statistics of the two candidates for cell levels for this project. More can be seen link:https://s2geometry.io/resources/s2cell_statistics[here^]
|
.Statistics of the two candidates for cell levels for this project. More can be seen link:https://s2geometry.io/resources/s2cell_statistics[here^]
|
||||||
|===
|
|===
|
||||||
|Level |Min area |Max area |Average area |Number of cells
|
|Level |Min area |Max area |Average area |Number of cells |Bits required
|
||||||
|
|
||||||
|22
|
|22
|
||||||
|2.90m^2^
|
|2.90m^2^
|
||||||
|6.08m^2^
|
|6.08m^2^
|
||||||
|4.83m^2^
|
|4.83m^2^
|
||||||
|1.05*10^14^
|
|1.05*10^14^
|
||||||
|
|47
|
||||||
|
|
||||||
|23
|
|23
|
||||||
|0.73m^2^
|
|0.73m^2^
|
||||||
|1.52m^2^
|
|1.52m^2^
|
||||||
|1.21m^2^
|
|1.21m^2^
|
||||||
|4.22*10^14^
|
|4.22*10^14^
|
||||||
|
|49
|
||||||
|
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use std::{
|
|||||||
mod conversions;
|
mod conversions;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use s2::{cellid::CellID, latlng::LatLng, s1::Deg};
|
use s2::{cell::Cell, cellid::CellID, latlng::LatLng, s1::Deg};
|
||||||
use words::Word;
|
use words::Word;
|
||||||
|
|
||||||
pub type Number = u32;
|
pub type Number = u32;
|
||||||
@ -49,6 +49,14 @@ pub struct Address<'a> {
|
|||||||
words: [&'a Word<'a>; 3],
|
words: [&'a Word<'a>; 3],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub trait Alg {
|
||||||
|
// type Err;
|
||||||
|
|
||||||
|
// fn to_cellid(&self) -> Result<CellID, Self::Err>;
|
||||||
|
|
||||||
|
// fn from_cellid();
|
||||||
|
// }
|
||||||
|
|
||||||
impl FromStr for Address<'_> {
|
impl FromStr for Address<'_> {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
@ -88,32 +96,24 @@ impl FromStr for Address<'_> {
|
|||||||
components.into_iter().skip(1).collect::<Vec<_>>()
|
components.into_iter().skip(1).collect::<Vec<_>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
match extract_version(number) {
|
Address::from_components(number, other_components)
|
||||||
0 => Self::parse_v0(number, other_components),
|
|
||||||
ver => Err(Error::InvalidVersion(ver)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Address<'_> {
|
impl Address<'_> {
|
||||||
|
/// Converts a latitude and longitude into an encoded address
|
||||||
pub fn from_lat_lon(lat: f64, lon: f64) -> Self {
|
pub fn from_lat_lon(lat: f64, lon: f64) -> Self {
|
||||||
let cellid = conversions::lat_lon_to_cellid(lat, lon);
|
let cellid = conversions::lat_lon_to_cellid(lat, lon);
|
||||||
|
|
||||||
v0::UnpackedCellID::from(cellid).into()
|
v0::UnpackedCellID::from(cellid).into()
|
||||||
|
|
||||||
// Self::cellid_to_v0(&cellid)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn cellid_to_v0(cell_id: &CellID) -> Self {
|
// /// Decodes an address to latitude and longitude
|
||||||
// // The raw binary representation of the cellid
|
// pub fn to_lat_lon(&self) -> (f64, f64) {
|
||||||
// let raw_cellid = cell_id.0;
|
// let cellid = self.as_cell_id();
|
||||||
|
|
||||||
// // Self {
|
|
||||||
// // number,
|
|
||||||
// // words: words.into_inner().unwrap(),
|
|
||||||
// // }
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Parses an address v0 given the number and word components
|
||||||
fn parse_v0(number: Number, word_components: Vec<&str>) -> Result<Self, Error> {
|
fn parse_v0(number: Number, word_components: Vec<&str>) -> Result<Self, Error> {
|
||||||
if !(V0_MIN_NUMBER..=V0_MAX_NUMBER).contains(&number) {
|
if !(V0_MIN_NUMBER..=V0_MAX_NUMBER).contains(&number) {
|
||||||
return Err(Error::NumberOutOfRange(number));
|
return Err(Error::NumberOutOfRange(number));
|
||||||
@ -135,8 +135,36 @@ impl Address<'_> {
|
|||||||
|
|
||||||
Ok(Self { number, words })
|
Ok(Self { number, words })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds an `Address` from a number and all word components
|
||||||
|
fn from_components(number: Number, other_components: Vec<&str>) -> Result<Self, Error> {
|
||||||
|
match extract_version(number) {
|
||||||
|
0 => Self::parse_v0(number, other_components),
|
||||||
|
ver => Err(Error::InvalidVersion(ver)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_cell_id(&self) -> Result<CellID, Error> {
|
||||||
|
match extract_version(self.number) {
|
||||||
|
0 => {
|
||||||
|
let ten_bits = 0b1111_1111_11;
|
||||||
|
let thirteen_bits = 0b1111_1111_1111_1;
|
||||||
|
let mut ret = self.number as u64 & ten_bits;
|
||||||
|
for w in self.words {
|
||||||
|
ret = (ret << 13) | (w.number as u64 & thirteen_bits);
|
||||||
|
}
|
||||||
|
ret = (ret << 15) | (0x1 << 14);
|
||||||
|
|
||||||
|
Ok(CellID(ret))
|
||||||
|
}
|
||||||
|
ver => Err(Error::InvalidVersion(ver)),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extracts a version number from a number
|
||||||
|
///
|
||||||
|
/// The version number is set by the two bits 11 and 12
|
||||||
fn extract_version(number: Number) -> Version {
|
fn extract_version(number: Number) -> Version {
|
||||||
((number >> 10) & 0b11) as Version
|
((number >> 10) & 0b11) as Version
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ pub struct UnpackedCellID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<CellID> for UnpackedCellID {
|
impl From<CellID> for UnpackedCellID {
|
||||||
|
/// Convert a `CellID` to an `UnpackedCellID`
|
||||||
fn from(cell_id: CellID) -> Self {
|
fn from(cell_id: CellID) -> Self {
|
||||||
Self::from(cell_id.0)
|
Self::from(cell_id.0)
|
||||||
}
|
}
|
||||||
@ -39,3 +40,11 @@ impl From<UnpackedCellID> for Address<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl<A: AsRef<Address<'a>>> From<A> for UnpackedCellID {
|
||||||
|
// fn from(addr: A) -> Self {
|
||||||
|
// let number_bits = addr.
|
||||||
|
|
||||||
|
// CellID(ret)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user