pub struct Location {
pub latitude_deg: f64,
pub longitude_deg: f64,
pub altitude_m: f64,
}Expand description
Represents a physical observer location on Earth.
Used for computing local sidereal time, converting celestial coordinates, and modeling telescope geometry.
Fields§
§latitude_deg: f64Latitude in degrees (+N, -S)
longitude_deg: f64Longitude in degrees (+E, -W, Greenwich = 0)
altitude_m: f64Altitude above sea level in meters
Implementations§
Source§impl Location
impl Location
Sourcepub fn parse(lat_str: &str, lon_str: &str, alt_m: f64) -> Result<Self>
pub fn parse(lat_str: &str, lon_str: &str, alt_m: f64) -> Result<Self>
Parses a location from flexible coordinate strings.
Automatically detects the coordinate format and applies appropriate parsing.
§Supported Formats
§Decimal degrees
"40.7128"or"-74.0060""40.7128N"or"74.0060W""N40.7128"or"W 74.0060""40.7128 N"or"74.0060 West""north 40.7128"or"west 74.0060"
§DMS (Degrees Minutes Seconds)
"40 42 46"or"40° 42' 46\"""40d42m46s"or"40deg42min46sec""40:42:46"or"40-42-46""40°42'46.08\"N"(with decimals and direction)"40d 42' 46.08\" N"(mixed separators)"40 degrees 42 minutes 46 seconds"
§DM (Degrees Decimal Minutes)
"40° 42.767'"or"40d 42.767m""40 42.767"(assumed DM if only 2 parts)
§HMS (Hours Minutes Seconds) for longitude
"4h 56m 27s"or"4:56:27""4h56m27.5s"or"4 hours 56 minutes 27.5 seconds""4h 56' 27\""(using arcminute/arcsecond symbols)
§Special handling
- Unicode:
"40°42′46″"(proper Unicode prime/double-prime) - Compact:
"404246N"or"0740060W"(DDMMSS format) - Aviation:
"4042.767N"(DDMM.mmm format) - Fuzzy: Handles extra spaces, mixed case, common typos
§Arguments
lat_str: Latitude string in any supported formatlon_str: Longitude string in any supported formatalt_m: Altitude in meters
§Returns
Ok(Location) if parsing succeeds
§Errors
Returns Err(AstroError::InvalidDmsFormat) with helpful error messages
§Examples
use astro_math::location::Location;
// Decimal degrees with compass directions
let loc = Location::parse("40.7128 N", "74.0060 W", 10.0).unwrap();
assert!((loc.latitude_deg - 40.7128).abs() < 1e-6);
assert!((loc.longitude_deg + 74.0060).abs() < 1e-6);
// DMS with symbols
let loc = Location::parse("40°42'46.08\"N", "74°0'21.6\"W", 10.0).unwrap();
assert!((loc.latitude_deg - 40.7128).abs() < 1e-4);
// HMS for longitude
let loc = Location::parse("51.5074 N", "0h 7m 39.84s W", 0.0).unwrap();
assert!((loc.longitude_deg + 1.9166).abs() < 1e-3);
// Mixed formats and fuzzy matching
let loc = Location::parse("40d 42m 46s North", "74 deg 0 min 21.6 sec west", 10.0).unwrap();
assert!((loc.latitude_deg - 40.7128).abs() < 1e-4);Sourcepub fn from_dms(lat_str: &str, lon_str: &str, alt_m: f64) -> Result<Self>
pub fn from_dms(lat_str: &str, lon_str: &str, alt_m: f64) -> Result<Self>
Parses a Location from sexagesimal (DMS) strings for latitude and longitude.
Supports a wide range of common DMS formats:
"39 00 01.7""39:00:01.7""39°00'01.7\""
§Arguments
lat_str: Latitude string in sexagesimal formatlon_str: Longitude string in sexagesimal formatalt_m: Altitude in meters
§Returns
Ok(Location) if parsing succeeds
§Errors
Returns Err(AstroError::InvalidDmsFormat) if:
- String doesn’t match any supported DMS format
- Degrees, minutes, or seconds are out of valid ranges
§Examples
§DMS with spaces
use astro_math::location::Location;
let loc = Location::from_dms("+39 00 01.7", "-92 18 03.2", 250.0).unwrap();
assert!((loc.latitude_deg - 39.0004722).abs() < 1e-6);
assert!((loc.longitude_deg + 92.3008888).abs() < 1e-6);§DMS with colons
use astro_math::location::Location;
let loc = Location::from_dms("+39:00:01.7", "-92:18:03.2", 250.0).unwrap();
assert!((loc.latitude_deg - 39.0004722).abs() < 1e-6);§ASCII punctuation
use astro_math::location::Location;
let loc = Location::from_dms("+39°00'01.7\"", "-92°18'03.2\"", 250.0).unwrap();
assert!((loc.longitude_deg + 92.3008888).abs() < 1e-6);§Invalid input
use astro_math::location::Location;
use astro_math::error::AstroError;
match Location::from_dms("foo", "bar", 100.0) {
Err(AstroError::InvalidDmsFormat { input, .. }) => {
assert_eq!(input, "foo");
}
_ => panic!("Expected InvalidDmsFormat error"),
}pub fn latitude_dms_string(&self) -> String
pub fn longitude_dms_string(&self) -> String
Sourcepub fn local_sidereal_time(&self, datetime: DateTime<Utc>) -> f64
pub fn local_sidereal_time(&self, datetime: DateTime<Utc>) -> f64
Computes the Local Sidereal Time (LST) at this location for a given UTC timestamp.
§Arguments
datetime: UTC datetime
§Returns
Local Sidereal Time in fractional hours
§Example
use chrono::{Utc, TimeZone};
use astro_math::location::Location;
let dt = Utc.with_ymd_and_hms(1987, 4, 10, 19, 21, 0).unwrap();
let loc = Location {
latitude_deg: 32.0,
longitude_deg: -64.0,
altitude_m: 200.0,
};
let lst = loc.local_sidereal_time(dt);
assert!((lst - 4.3157).abs() < 1e-3);Sourcepub fn local_mean_sidereal_time(&self, datetime: DateTime<Utc>) -> f64
pub fn local_mean_sidereal_time(&self, datetime: DateTime<Utc>) -> f64
Local Mean Sidreal Time (LMST) is calculated using the “mean equinox,” a theoretical reference point in space that moves at a constant rate.
§Arguments
datetime: UTC datetime
§Returns
Local Sidereal Time in fractional hours
§Example
use chrono::{Utc, TimeZone};
use astro_math::location::Location;
let dt = Utc.with_ymd_and_hms(1987, 4, 10, 19, 21, 0).unwrap();
let loc = Location {
latitude_deg: 32.0,
longitude_deg: -64.0,
altitude_m: 200.0,
};
let lst = loc.local_mean_sidereal_time(dt);
assert!((lst - 4.315).abs() < 1e-3);Sourcepub fn latitude_dms(&self) -> String
pub fn latitude_dms(&self) -> String
Returns latitude formatted as ±DD° MM′ SS.sss″ (DMS)
Sourcepub fn longitude_dms(&self) -> String
pub fn longitude_dms(&self) -> String
Returns longitude formatted as ±DDD° MM′ SS.sss″ (DMS)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Location
impl RefUnwindSafe for Location
impl Send for Location
impl Sync for Location
impl Unpin for Location
impl UnsafeUnpin for Location
impl UnwindSafe for Location
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more