Remove extra file

This commit is contained in:
Austen Adler 2023-03-14 23:27:38 -04:00
parent 0ea0952840
commit 2158dcb96f

View File

@ -1,93 +0,0 @@
// From: https://gist.github.com/missinglink/d0a085188a8eab2ca66db385bb7c023a
unction wrap( lat, lon ){
var point = { lat: lat, lon: lon };
var quadrant = Math.floor( Math.abs( lat ) / 90) % 4;
var pole = ( lat > 0 ) ? 90 : -90;
var offset = lat % 90;
switch( quadrant ){
case 0:
point.lat = offset;
break;
case 1:
point.lat = pole - offset;
point.lon += 180;
break;
case 2:
point.lat = -offset
point.lon += 180;
break;
case 3:
point.lat = -pole + offset;
break;
}
if( point.lon > 180 || point.lon < -180 ){
point.lon -= Math.floor(( point.lon + 180 ) / 360) * 360;
}
return point;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_extract_binary() {
assert_eq!(extract_binary(0b0, 0..=0), 0b0);
assert_eq!(extract_binary(0b11_1111_11, 2..=5), 0b1111);
assert_eq!(extract_binary(0b11_0101_11, 2..=5), 0b0101);
assert_eq!(extract_binary(0b11_1100_11, 2..=5), 0b1100);
assert_eq!(extract_binary(0b111_10011_, 0..=4), 0b10011);
assert_eq!(extract_binary(0b111100_1_1, 1..=1), 0b1);
assert_eq!(extract_binary(0b111100_0_1, 1..=1), 0b0);
// A full test from the docs
let cellid = 0b0100101110101000_1011100010010011_1001001100100100_1100000000000000_u64;
assert_eq!(extract_binary(cellid, 15..=24), 0b10_01001001);
assert_eq!(extract_binary(cellid, 25..=37), 0b01001_11001001);
assert_eq!(extract_binary(cellid, 38..=50), 0b00010_11100010);
assert_eq!(extract_binary(cellid, 51..=63), 0b01001_01110101);
}
#[test]
fn test_normalize_latlon() {
let mut num_failed = 0;
for (idx, (input_lat, input_lon, expected_lat, expected_lon)) in [
// Lat
(0_f64, 0_f64, 0_f64, 0_f64),
(-89_f64, 0_f64, -89_f64, 0_f64),
(-90_f64, 0_f64, -90_f64, 0_f64),
(-91_f64, 0_f64, -89_f64, 0_f64),
(89_f64, 0_f64, 89_f64, 0_f64),
(90_f64, 0_f64, 90_f64, 0_f64),
(91_f64, 0_f64, 89_f64, 0_f64),
(180_f64, 0_f64, 0_f64, 0_f64),
// Lon
(0_f64, -179_f64, 0_f64, -179_f64),
(0_f64, -180_f64, 0_f64, -180_f64),
(0_f64, -181_f64, 0_f64, -179_f64),
(0_f64, 179_f64, 0_f64, 179_f64),
(0_f64, 180_f64, 0_f64, 180_f64),
(0_f64, 181_f64, 0_f64, 179_f64),
(0_f64, 360_f64, 0_f64, 0_f64),
]
.into_iter()
.enumerate()
{
let (lat, lon) = normalize_latlon(input_lat, input_lon).unwrap();
eprint!("Testing #{idx}:\t{input_lat},{input_lon}\t=> {expected_lat},{expected_lon} \t(=> {lat},{lon})");
if (lat, lon) != (expected_lat, expected_lon) {
eprint!("\tERROR!",);
num_failed += 1;
}
eprintln!("");
}
assert_eq!(num_failed, 0);
}
}