Add spatial-coordinate-systems to wasm

This commit is contained in:
Austen Adler 2023-03-20 00:19:18 -04:00
parent 670fbf31cb
commit 97814e390a
10 changed files with 134 additions and 444 deletions

338
Cargo.lock generated
View File

@ -2,21 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "addr2line"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]] [[package]]
name = "aead" name = "aead"
version = "0.5.1" version = "0.5.1"
@ -85,12 +70,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "assert_approx_eq"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c07dab4369547dbe5114677b33fbbf724971019f3818172d59a97a61c774ffd"
[[package]] [[package]]
name = "async-stream" name = "async-stream"
version = "0.3.4" version = "0.3.4"
@ -150,21 +129,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.20.0" version = "0.20.0"
@ -177,7 +141,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aaf33151a6429fe9211d1b276eafdf70cdff28b071e76c0b0e1503221ea3744" checksum = "6aaf33151a6429fe9211d1b276eafdf70cdff28b071e76c0b0e1503221ea3744"
dependencies = [ dependencies = [
"num-bigint 0.4.3", "num-bigint",
"num-integer", "num-integer",
"num-traits", "num-traits",
] ]
@ -194,16 +158,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
version = "0.17.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c"
dependencies = [
"either",
"radium",
]
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.4" version = "0.10.4"
@ -283,7 +237,7 @@ dependencies = [
"hkdf", "hkdf",
"hmac", "hmac",
"percent-encoding", "percent-encoding",
"rand 0.8.5", "rand",
"sha2", "sha2",
"subtle", "subtle",
"time", "time",
@ -306,7 +260,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [ dependencies = [
"generic-array", "generic-array",
"rand_core 0.6.4", "rand_core",
"typenum", "typenum",
] ]
@ -384,22 +338,6 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "dms-coordinates"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec6b438cc34e673063a715ff761392e195278759fa5d882d6bc6b78e2e30d90d"
dependencies = [
"geo-types",
"gpx",
"initial_conditions",
"map_3d",
"rust-3d",
"serde",
"serde_derive",
"thiserror",
]
[[package]] [[package]]
name = "either" name = "either"
version = "1.8.1" version = "1.8.1"
@ -436,16 +374,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "error-chain"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc"
dependencies = [
"backtrace",
"version_check",
]
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "1.9.0" version = "1.9.0"
@ -475,12 +403,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.27" version = "0.3.27"
@ -569,17 +491,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "geo-types"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5f0b3068e1537a4b861ec3734f4aa9c317d537cf0845bf6fb6221973499d26c"
dependencies = [
"approx",
"num-traits",
"serde",
]
[[package]] [[package]]
name = "geoutils" name = "geoutils"
version = "0.5.1" version = "0.5.1"
@ -607,32 +518,12 @@ dependencies = [
"polyval", "polyval",
] ]
[[package]]
name = "gimli"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
[[package]] [[package]]
name = "glob" name = "glob"
version = "0.3.1" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "gpx"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b03599b85866c88fd0125db7ca7a683be1550724918682c736c7893a399dc5e"
dependencies = [
"assert_approx_eq",
"error-chain",
"geo-types",
"thiserror",
"time",
"xml-rs",
]
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.16" version = "0.3.16"
@ -778,15 +669,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "initial_conditions"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ddf16659f435e5c98d948694a97c33b6660c35adad199ab10362092a45ce921"
dependencies = [
"num 0.1.42",
]
[[package]] [[package]]
name = "inlinable_string" name = "inlinable_string"
version = "0.1.15" version = "0.1.15"
@ -886,12 +768,6 @@ dependencies = [
"tracing-subscriber", "tracing-subscriber",
] ]
[[package]]
name = "map_3d"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fc1b6107fbd06c96e5e481fcf3e6575b873eb84f5b68f1f5706cde0fed42c4"
[[package]] [[package]]
name = "matchers" name = "matchers"
version = "0.1.0" version = "0.1.0"
@ -919,15 +795,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
dependencies = [
"adler",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.6" version = "0.8.6"
@ -980,57 +847,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "num"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
dependencies = [
"num-bigint 0.1.44",
"num-complex 0.1.43",
"num-integer",
"num-iter",
"num-rational 0.1.42",
"num-traits",
]
[[package]]
name = "num"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36"
dependencies = [
"num-bigint 0.2.6",
"num-complex 0.2.4",
"num-integer",
"num-iter",
"num-rational 0.2.4",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1"
dependencies = [
"num-integer",
"num-traits",
"rand 0.4.6",
"rustc-serialize",
]
[[package]]
name = "num-bigint"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-bigint" name = "num-bigint"
version = "0.4.3" version = "0.4.3"
@ -1042,26 +858,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-complex"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b288631d7878aaf59442cffd36910ea604ecd7745c36054328595114001c9656"
dependencies = [
"num-traits",
"rustc-serialize",
]
[[package]]
name = "num-complex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"
dependencies = [
"autocfg",
"num-traits",
]
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.45" version = "0.1.45"
@ -1072,41 +868,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-iter"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e"
dependencies = [
"num-bigint 0.1.44",
"num-integer",
"num-traits",
"rustc-serialize",
]
[[package]]
name = "num-rational"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"
dependencies = [
"autocfg",
"num-bigint 0.2.6",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.15" version = "0.2.15"
@ -1114,7 +875,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm",
] ]
[[package]] [[package]]
@ -1127,15 +887,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "object"
version = "0.30.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.17.1" version = "1.17.1"
@ -1232,7 +983,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf"
dependencies = [ dependencies = [
"phf_shared", "phf_shared",
"rand 0.8.5", "rand",
] ]
[[package]] [[package]]
@ -1340,25 +1091,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "radium"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac"
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.8.5" version = "0.8.5"
@ -1367,7 +1099,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [ dependencies = [
"libc", "libc",
"rand_chacha", "rand_chacha",
"rand_core 0.6.4", "rand_core",
] ]
[[package]] [[package]]
@ -1377,24 +1109,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [ dependencies = [
"ppv-lite86", "ppv-lite86",
"rand_core 0.6.4", "rand_core",
] ]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]] [[package]]
name = "rand_core" name = "rand_core"
version = "0.6.4" version = "0.6.4"
@ -1404,15 +1121,6 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.16" version = "0.2.16"
@ -1490,7 +1198,7 @@ dependencies = [
"num_cpus", "num_cpus",
"parking_lot", "parking_lot",
"pin-project-lite", "pin-project-lite",
"rand 0.8.5", "rand",
"ref-cast", "ref-cast",
"rocket_codegen", "rocket_codegen",
"rocket_http", "rocket_http",
@ -1550,17 +1258,6 @@ dependencies = [
"uncased", "uncased",
] ]
[[package]]
name = "rust-3d"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce1e81ec1eec57188d13fdeb9fcdf961914eb0f57e3b40c723be3b9245de9bb"
dependencies = [
"bitvec",
"fnv",
"num 0.2.1",
]
[[package]] [[package]]
name = "rust-embed" name = "rust-embed"
version = "6.6.0" version = "6.6.0"
@ -1596,18 +1293,6 @@ dependencies = [
"walkdir", "walkdir",
] ]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-serialize"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.36.10" version = "0.36.10"
@ -1762,10 +1447,8 @@ dependencies = [
name = "spatial-coordinate-systems" name = "spatial-coordinate-systems"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dms-coordinates",
"nom", "nom",
"pluscodes", "pluscodes",
"thiserror",
"utm", "utm",
] ]
@ -2411,12 +2094,6 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "xml-rs"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
[[package]] [[package]]
name = "xpin" name = "xpin"
version = "0.1.0" version = "0.1.0"
@ -2433,6 +2110,7 @@ dependencies = [
name = "xpin-wasm" name = "xpin-wasm"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"spatial-coordinate-systems",
"wasm-bindgen", "wasm-bindgen",
"xpin", "xpin",
] ]

View File

@ -6,8 +6,18 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
dms-coordinates = "1.1.0" # Excluding because rustc-serialize does not work with wasm
# dms-coordinates v1.1.0
# └── initial_conditions v0.4.0
# └── num v0.1.42
# ├── num-bigint v0.1.44
# │ └── rustc-serialize v0.3.24 <==
# ├── num-complex v0.1.43
# │ └── rustc-serialize v0.3.24 <==
# └── num-rational v0.1.42
# └── rustc-serialize v0.3.24 <==
# dms-coordinates = "1.1.0"
nom = "7.1.3" nom = "7.1.3"
pluscodes = "0.5.0" pluscodes = "0.5.0"
thiserror = "1.0.40"
utm = "0.1.6" utm = "0.1.6"

View File

@ -1,13 +1,6 @@
use crate::{ use crate::common::optional_separator;
common::{optional_separator}, use nom::{combinator::map_opt, number::complete::double, sequence::tuple, IResult};
}; use std::{fmt, str::FromStr};
use nom::{
combinator::{map_opt},
number::complete::double,
sequence::{tuple},
IResult,
};
use std::str::FromStr;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub struct Coordinate { pub struct Coordinate {
@ -35,6 +28,12 @@ impl Coordinate {
} }
} }
impl fmt::Display for Coordinate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}, {}", self.lat, self.lon)
}
}
impl TryFrom<(f64, f64)> for Coordinate { impl TryFrom<(f64, f64)> for Coordinate {
type Error = (); type Error = ();

View File

@ -9,7 +9,7 @@ use nom::{
sequence::tuple, sequence::tuple,
IResult, IResult,
}; };
use std::{convert::Infallible, str::FromStr}; use std::{convert::Infallible, fmt, str::FromStr};
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub struct Coordinate(pub DMM, pub DMM); pub struct Coordinate(pub DMM, pub DMM);
@ -67,6 +67,18 @@ impl DMM {
} }
} }
impl fmt::Display for DMM {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}° {}'", self.degrees, self.minutes)
}
}
impl fmt::Display for Coordinate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}, {}", self.0, self.1)
}
}
impl TryInto<LatLon> for Coordinate { impl TryInto<LatLon> for Coordinate {
type Error = (); type Error = ();

View File

@ -7,10 +7,10 @@ pub use dms_coordinates::DMS;
use nom::{ use nom::{
character::complete::{self}, character::complete::{self},
combinator::{map, map_opt}, combinator::{map, map_opt},
sequence::{tuple}, sequence::tuple,
IResult, IResult,
}; };
use std::str::FromStr; use std::{fmt, str::FromStr};
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub struct Coordinate(pub DMS, pub DMS); pub struct Coordinate(pub DMS, pub DMS);
@ -73,60 +73,22 @@ impl FromStr for Coordinate {
} }
} }
// pub fn parse(i: &str) -> IResult<&str, DMS> { impl fmt::Display for Coordinate {
// map( fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// tuple(( write!(
// // Degrees f,
// complete::i16, "{}° {}' {}\"",
// optional_separator('°'), self.0.degrees, self.0.minutes, self.0.seconds
// // Minutes )?;
// complete::i16, write!(f, ", ")?;
// optional_separator('\''), write!(
// // Seconds f,
// double, "{}° {}' {}\"",
// optional_separator('"'), self.1.degrees, self.1.minutes, self.1.seconds
// // Direction )?;
// parse_direction, Ok(())
// )), }
// |(degrees, (), minutes, (), seconds, (), direction)| DMS { }
// degrees,
// minutes,
// seconds,
// direction,
// },
// )(i)
// }
// impl FromStr for DMS {
// type Err = ();
// /// Recognizes DMS in the formats:
// ///
// /// * `40° 31' 21" N, 105° 5' 39" W`
// /// * `40 31 21 N, 105 5 39 W`
// ///
// /// ```rust
// /// use spatial_coordinate_systems::dms::DMS;
// /// use spatial_coordinate_systems::Direction;
// /// use std::str::FromStr;
// ///
// /// assert_eq!(DMS::from_str("40 31 21 N").unwrap(), DMS {
// /// degrees: 40,
// /// minutes: 31,
// /// seconds: 21_f64,
// /// direction: Direction::North,
// /// });
// /// assert_eq!(DMS::from_str("40°31' 21 \" N").unwrap(), DMS {
// /// degrees: 40,
// /// minutes: 31,
// /// seconds: 21_f64,
// /// direction: Direction::North,
// /// });
// /// ```
// fn from_str(i: &str) -> Result<Self, Self::Err> {
// DMS::parse(i).map_err(|_| ()).map(|(_, ret)| ret)
// }
// }
impl TryInto<LatLon> for Coordinate { impl TryInto<LatLon> for Coordinate {
type Error = (); type Error = ();

View File

@ -1,8 +1,8 @@
use std::str::FromStr; use std::{fmt, str::FromStr};
mod common; mod common;
pub mod dd; pub mod dd;
pub mod dmm; // pub mod dmm;
pub mod dms; // pub mod dms;
pub mod plus; pub mod plus;
pub mod utm; pub mod utm;
@ -38,8 +38,8 @@ impl Direction {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Coordinate { pub enum Coordinate {
DD(dd::Coordinate), DD(dd::Coordinate),
DMS(dms::Coordinate), // DMS(dms::Coordinate),
DMM(dmm::Coordinate), // DMM(dmm::Coordinate),
UTM(utm::Coordinate), UTM(utm::Coordinate),
Plus(plus::Coordinate), Plus(plus::Coordinate),
} }
@ -51,8 +51,8 @@ impl Coordinate {
space0, space0,
alt(( alt((
map(dd::Coordinate::parse, Coordinate::DD), map(dd::Coordinate::parse, Coordinate::DD),
map(dms::Coordinate::parse, Coordinate::DMS), // map(dms::Coordinate::parse, Coordinate::DMS),
map(dmm::Coordinate::parse, Coordinate::DMM), // map(dmm::Coordinate::parse, Coordinate::DMM),
map(utm::Coordinate::parse, Coordinate::UTM), map(utm::Coordinate::parse, Coordinate::UTM),
map(plus::Coordinate::parse, Coordinate::Plus), map(plus::Coordinate::parse, Coordinate::Plus),
)), )),
@ -70,8 +70,8 @@ impl TryFrom<Coordinate> for LatLon {
fn try_from(value: Coordinate) -> Result<LatLon, Self::Error> { fn try_from(value: Coordinate) -> Result<LatLon, Self::Error> {
match value { match value {
Coordinate::DD(dd) => dd.try_into().or(Err(())), Coordinate::DD(dd) => dd.try_into().or(Err(())),
Coordinate::DMM(dm) => dm.try_into(), // Coordinate::DMM(dmm) => dmm.try_into(),
Coordinate::DMS(dms) => dms.try_into(), // Coordinate::DMS(dms) => dms.try_into(),
Coordinate::UTM(utm) => utm.try_into(), Coordinate::UTM(utm) => utm.try_into(),
Coordinate::Plus(plus) => plus.try_into(), Coordinate::Plus(plus) => plus.try_into(),
} }
@ -83,16 +83,16 @@ impl From<dd::Coordinate> for Coordinate {
Self::DD(c) Self::DD(c)
} }
} }
impl From<dms::Coordinate> for Coordinate { // impl From<dms::Coordinate> for Coordinate {
fn from(c: dms::Coordinate) -> Self { // fn from(c: dms::Coordinate) -> Self {
Self::DMS(c) // Self::DMS(c)
} // }
} // }
impl From<dmm::Coordinate> for Coordinate { // impl From<dmm::Coordinate> for Coordinate {
fn from(c: dmm::Coordinate) -> Self { // fn from(c: dmm::Coordinate) -> Self {
Self::DMM(c) // Self::DMM(c)
} // }
} // }
impl From<utm::Coordinate> for Coordinate { impl From<utm::Coordinate> for Coordinate {
fn from(c: utm::Coordinate) -> Self { fn from(c: utm::Coordinate) -> Self {
Self::UTM(c) Self::UTM(c)
@ -104,18 +104,18 @@ impl From<plus::Coordinate> for Coordinate {
} }
} }
impl TryFrom<Coordinate> for dms::Coordinate { // impl TryFrom<Coordinate> for dms::Coordinate {
type Error = (); // type Error = ();
fn try_from(c: Coordinate) -> Result<Self, Self::Error> { // fn try_from(c: Coordinate) -> Result<Self, Self::Error> {
dms::Coordinate::try_from(LatLon::try_from(c)?) // dms::Coordinate::try_from(LatLon::try_from(c)?)
} // }
} // }
impl TryFrom<Coordinate> for dmm::Coordinate { // impl TryFrom<Coordinate> for dmm::Coordinate {
type Error = (); // type Error = ();
fn try_from(c: Coordinate) -> Result<Self, Self::Error> { // fn try_from(c: Coordinate) -> Result<Self, Self::Error> {
dmm::Coordinate::try_from(LatLon::try_from(c)?).or(Err(())) // dmm::Coordinate::try_from(LatLon::try_from(c)?).or(Err(()))
} // }
} // }
impl TryFrom<Coordinate> for utm::Coordinate { impl TryFrom<Coordinate> for utm::Coordinate {
type Error = (); type Error = ();
fn try_from(c: Coordinate) -> Result<Self, Self::Error> { fn try_from(c: Coordinate) -> Result<Self, Self::Error> {
@ -129,6 +129,17 @@ impl TryFrom<Coordinate> for plus::Coordinate {
} }
} }
impl fmt::Display for Coordinate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Coordinate::DD(dd) => write!(f, "{}", dd),
// Coordinate::DMM(dmm) => write!(f, "{}", dmm),
// Coordinate::DMS(dms) => write!(f, "{}", dms),
Coordinate::UTM(utm) => write!(f, "{}", utm),
Coordinate::Plus(plus) => write!(f, "{}", plus),
}
}
}
impl FromStr for Coordinate { impl FromStr for Coordinate {
type Err = (); type Err = ();
@ -161,10 +172,10 @@ mod tests {
})) }))
); );
assert_eq!( // assert_eq!(
dms::Coordinate::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()), // dms::Coordinate::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()),
dms::Coordinate::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()) // dms::Coordinate::try_from(Coordinate::from_str("0.000000 100.500278").unwrap())
) // )
// assert_eq!( // assert_eq!(
// LatLon::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()), // LatLon::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()),

View File

@ -1,12 +1,6 @@
use crate::{ use crate::LatLon;
LatLon, use nom::{bytes::complete::take_while, combinator::map_opt, IResult};
}; use std::{fmt, str::FromStr};
use nom::{
bytes::complete::take_while,
combinator::{map_opt},
IResult,
};
use std::str::FromStr;
// TODO: Pick an approprite length // TODO: Pick an approprite length
const PLUSCODE_LENGTH: usize = 8; const PLUSCODE_LENGTH: usize = 8;
@ -42,6 +36,12 @@ fn pluscode_chars(i: &str) -> IResult<&str, &str> {
take_while(|c| PLUSCODE_CHARS.contains(&c))(i) take_while(|c| PLUSCODE_CHARS.contains(&c))(i)
} }
impl fmt::Display for Coordinate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl TryInto<LatLon> for Coordinate { impl TryInto<LatLon> for Coordinate {
type Error = (); type Error = ();

View File

@ -9,7 +9,7 @@ use nom::{
sequence::tuple, sequence::tuple,
IResult, IResult,
}; };
use std::str::FromStr; use std::{fmt, str::FromStr};
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub struct Coordinate { pub struct Coordinate {
@ -83,6 +83,16 @@ impl FromStr for Coordinate {
} }
} }
impl fmt::Display for Coordinate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}{} {} {}",
self.zone_num, self.zone_letter, self.easting, self.northing,
)
}
}
impl TryInto<LatLon> for Coordinate { impl TryInto<LatLon> for Coordinate {
type Error = (); type Error = ();

View File

@ -11,3 +11,4 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
xpin = {path=".."} xpin = {path=".."}
spatial-coordinate-systems = {path="../spatial-coordinate-systems/"}

View File

@ -46,6 +46,13 @@ impl EncodedAddress {
} }
} }
#[wasm_bindgen]
pub fn parse(i: &str) -> Result<String, String> {
spatial_coordinate_systems::Coordinate::from_str(i)
.map(|c| format!("{c:?}"))
.map_err(|()| format!("Could not parse str as a coordinate {i:?}"))
}
impl From<&'_ Address<'_>> for EncodedAddress { impl From<&'_ Address<'_>> for EncodedAddress {
fn from(addr: &Address) -> Self { fn from(addr: &Address) -> Self {
let (lat, lon) = addr.as_lat_lon(); let (lat, lon) = addr.as_lat_lon();