pub struct OSI { /* private fields */ }
Expand description
Type representing a valid Irish National Grid Reference. Can be instantiated either by parsing from a string or through a valid set of eastings and northings as coordinates.
Provides functionality to convert between strings and coordinates, as well as re-mapping to a new precision.
Implementations§
Source§impl OSI
impl OSI
Sourcepub fn new(
eastings: u32,
northings: u32,
precision: Precision,
) -> Result<Self, Error>
pub fn new( eastings: u32, northings: u32, precision: Precision, ) -> Result<Self, Error>
Creates a new grid reference from the given coordinates and precision.
§Errors
Returns an error if the given coordinates are out of bounds.
§Example
use gridish::{OSI, Precision};
let gridref = OSI::new(
389_200,
243_700,
Precision::_100M
).unwrap();
assert_eq!(gridref.to_string(), "O892437".to_string());
Sourcepub fn recalculate(&self, precision: Precision) -> Self
pub fn recalculate(&self, precision: Precision) -> Self
Recalculates the grid reference to a new precision.
§Example
use gridish::{OSI, Precision};
let gridref_100m: OSI = "O892437".parse().unwrap();
let gridref_10k = gridref_100m.recalculate(Precision::_10Km);
assert_eq!("O84".to_string(), gridref_10k.to_string());
Sourcepub fn sw(&self) -> Point
pub fn sw(&self) -> Point
Returns the point at the OSI’s ‘South West’ corner - its origin.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.sw(), coord! {x: 389_200.0, y: 243_700.0 }.into());
Sourcepub fn nw(&self) -> Point
pub fn nw(&self) -> Point
Returns the point at the OSI’s ‘North West’ corner.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.nw(), coord! {x: 389_200.0, y: 243_800.0 }.into());
Sourcepub fn ne(&self) -> Point
pub fn ne(&self) -> Point
Returns the point at the OSI’s ‘North East’ corner.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.ne(), coord! {x: 389_300.0, y: 243_800.0 }.into());
Sourcepub fn se(&self) -> Point
pub fn se(&self) -> Point
Returns the point at the OSI’s ‘South East’ corner.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.se(), coord! {x: 389_300.0, y: 243_700.0 }.into());
Sourcepub fn centre(&self) -> Point
pub fn centre(&self) -> Point
Returns the point at the OSI’s centre.
§Example
use gridish::OSI;
use geo_types::coord;
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(gridref.centre(), coord! {x: 389_250.0, y: 243_750.0 }.into());
Sourcepub fn perimeter(&self) -> Polygon
pub fn perimeter(&self) -> Polygon
Returns the OSI’s perimeter.
§Example
use gridish::OSI;
use geo_types::{LineString, Point, Polygon};
let gridref: OSI = "O892437".parse().unwrap();
assert_eq!(
gridref.perimeter(),
Polygon::new(
LineString::from(
vec![
Point::new(389_200.0, 243_700.0),
Point::new(389_200.0, 243_800.0),
Point::new(389_300.0, 243_800.0),
Point::new(389_300.0, 243_700.0)
]
),
vec![]
)
);
Trait Implementations§
impl Eq for OSI
impl StructuralPartialEq for OSI
Auto Trait Implementations§
impl Freeze for OSI
impl RefUnwindSafe for OSI
impl Send for OSI
impl Sync for OSI
impl Unpin for OSI
impl UnwindSafe for OSI
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
Mutably borrows from an owned value. Read more