BinghamtonBetterBus/src/stop.rs

101 lines
2.1 KiB
Rust

#[derive(Clone, PartialEq, PartialOrd)]
pub struct Stop{
pub id:u32,
pub name:String,
pub lat: f64,
pub lon: f64,
}
impl std::hash::Hash for Stop {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write_u32(self.id);
}
}
impl From<Stop> for crate::types::Coords {
fn from(value: Stop) -> Self {
crate::types::Coords {lat: value.lat, lon: value.lon}
}
}
#[derive(serde::Deserialize)]
struct OcctStop{
id:u32,
name:String,
lat: f64,
#[serde(rename(deserialize = "lng"))]
lon: f64,
}
impl From<OcctStop> for Stop{
fn from(OcctStop{id,name,lat,lon}: OcctStop) -> Self {
Self {
id,
name,
lat,
lon
}
}
}
#[derive(serde::Deserialize)]
struct BCStop{
id:u32,
name:String,
lat: f64,
lon: f64,
}
impl From<BCStop> for Stop{
fn from(BCStop{id,name,lat,lon}: BCStop) -> Self {
Self {
id,
name,
lat,
lon
}
}
}
pub async fn occt_stops_get()->anyhow::Result<Vec<Stop>>{
Ok(Vec::new())
}
pub async fn bc_stops_get()->anyhow::Result<Vec<Stop>>{
Ok(Vec::new())
}
pub fn poly_encode_stops<I:IntoIterator<Item=Stop>>(stops:I)->String{
stops.into_iter()
.map(|stop|{
enc_float(stop.lat)
})
.reduce(|s1,s2|s1+&s2).unwrap_or("".into())
}
fn enc_float(num:f64)->String{
let mut working:i32 = (num*1e5).round() as i32;
//hopethis does what's needed
working<<=1;
if num < 0.0 {
working = !working;
}
let mut bits:[bool;30] = [false;30];
for i in 0..30{
bits[i] = working % 2 == 1;
working >>=1;
}
bits.chunks(5).rev()
.map(|bools|{
let mut accu:u8 = 0;
for i in 0..5{
accu += if bools[4-i]{
1
} else {0};
accu <<=1;
}
accu |= 0x20;
accu +=63;
char::from(accu)
}).collect::<String>()
}
#[derive(serde::Serialize)]
pub struct RouteDraw{
pub color:String,
pub stops:Vec<crate::types::Coords>
}