use crate::proj::{BaseUnit, Unit};
use alloc::string::String;
pub fn to_camel_case(s: &str) -> String {
let mut result = String::new();
let mut capitalize_next = false;
for (i, c) in s.trim().chars().enumerate() {
if c == ' ' || c == '_' || c == '-' {
capitalize_next = true;
} else if i == 0 {
result.push(c.to_ascii_lowercase());
} else if capitalize_next {
result.push(c.to_ascii_uppercase());
capitalize_next = false;
} else {
result.push(c.to_ascii_lowercase());
}
}
result
}
pub fn to_pascal_case(s: &str) -> String {
let mut result = String::new();
let mut capitalize_next = true;
for c in s.trim().chars() {
if c == ' ' || c == '_' || c == '-' {
capitalize_next = true;
} else if capitalize_next {
result.push(c.to_ascii_uppercase());
capitalize_next = false;
} else {
result.push(c);
}
}
result
}
pub fn get_prime_meridian(name: &str) -> f64 {
match name.to_lowercase().as_str() {
"copenhagen" => 12.0, "greenwich" => 0.0, "lisbon" => -9.131906111111, "paris" => 2.337229166667, "bogota" => -74.080916666667, "madrid" => -3.687938888889, "rome" => 12.452333333333, "bern" => 7.439583333333, "jakarta" => 106.807719444444, "ferro" => -17.666666666667, "brussels" => 4.367975, "stockholm" => 18.058277777778, "athens" => 23.7163375, "budapest" => 19.040236111111, "oslo" => 10.722916666667, _ => 0.0,
}
}
pub fn linear_unit_to_meters(unit: &str) -> f64 {
match unit.trim().to_lowercase().as_str() {
"km" | "kilometer" => 1000.0,
"metre" | "meter" | "m" => 1.0,
"dm" | "decimeter" => 0.1,
"cm" | "centimeter" => 0.01,
"mm" | "millimeter" => 0.001,
"kmi" | "internationalnauticalmile" => 1852.0,
"in" | "internationalinch" => 0.0254,
"ft" | "internationalfoot" => 0.3048,
"yd" | "internationalyard" => 0.9144,
"mi" | "internationalstatutemile" => 1609.344,
"fath" | "internationalfathom" => 1.8288,
"ch" | "internationalchain" => 20.1168,
"link" | "internationallink" => 0.201168,
"us-in" | "ussurveyorinch" => 100.0 / 3937.0,
"us-ft" | "ussurveyorfoot" => 1200.0 / 3937.0,
"us-yd" | "ussurveyoryard" => 3600.0 / 3937.0,
"us-ch" | "ussurveyorchain" => 79200.0 / 3937.0,
"us-mi" | "ussurveyorstatutemile" => 6336000.0 / 3937.0,
"ind-yd" | "indianyard" => 0.91439523,
"ind-ft" | "indianfoot" => 0.30479841,
"ind-ch" | "indianchain" => 20.11669506,
_ => 0.0,
}
}
pub fn angular_unit_to_degrees(unit: &str) -> f64 {
match unit.trim().to_lowercase().as_str() {
"rad" | "radian" => 180.0 / core::f64::consts::PI,
"grad" | "grade" => 1.0 / 200.0 * 180.0,
"degree" => 1.0,
_ => 0.0,
}
}
pub fn name_to_unit(name: &str) -> Unit {
match name.to_lowercase().as_str() {
"false_easting" | "false_northing" => Unit::BaseUnit(BaseUnit::Metre),
"scale_factor" => Unit::BaseUnit(BaseUnit::Unity),
_ => Unit::BaseUnit(BaseUnit::Degree),
}
}
pub fn axis_name_to_order(name: &str) -> u8 {
match name.to_lowercase().as_str() {
"x" | "(x)" | "east" | "east (x)" | "(e)" | "easting" | "easting (x)" => 0,
"y" | "(y)" | "north" | "north (y)" | "(n)" | "northing" | "northing (y)" => 1,
"z" | "(z)" => 2,
"t" | "(t)" => 3,
_ => 0,
}
}