Struct cheap_ruler::CheapRuler [−][src]
A collection of very fast approximations to common geodesic measurements. Useful for performance-sensitive code that measures things on a city scale. Point coordinates are in the [x = longitude, y = latitude] form.
Implementations
impl CheapRuler
[src]
pub fn new(latitude: f64, distance_unit: DistanceUnit) -> Self
[src]
pub fn from_tile(y: u32, z: u32, distance_unit: DistanceUnit) -> Self
[src]
Creates a ruler object from tile coordinates (y and z). Convenient in tile-reduce scripts
Arguments
y
- yz
- zdistance_unit
- Unit to express distances in
Examples
use cheap_ruler::{CheapRuler, DistanceUnit}; let cr = CheapRuler::from_tile(1567, 12, DistanceUnit::Meters);
pub fn change_unit(&mut self, distance_unit: DistanceUnit)
[src]
Changes the ruler’s unit to the given one
Arguments
distance_unit
- New distance unit to express distances in
pub fn clone_with_unit(&self, distance_unit: DistanceUnit) -> Self
[src]
Clones the ruler to a new one with the given unit
Arguments
distance_unit
- Distance unit to express distances in the new ruler
pub fn distance_unit(&self) -> DistanceUnit
[src]
Gets the distance unit that the ruler was instantiated with
pub fn square_distance(&self, a: &Point<f64>, b: &Point<f64>) -> f64
[src]
Calculates the square of the approximate distance between two geographical points
Arguments
a
- First pointb
- Second point
pub fn distance(&self, a: &Point<f64>, b: &Point<f64>) -> f64
[src]
Calculates the approximate distance between two geographical points
Arguments
a
- First pointb
- Second point
Examples
use cheap_ruler::{CheapRuler, DistanceUnit}; let cr = CheapRuler::new(44.7192003, DistanceUnit::Meters); let dist = cr.distance( &(14.8901816, 44.7209699).into(), &(14.8905188, 44.7209699).into() ); assert!(dist < 38.0);
pub fn bearing(&self, a: &Point<f64>, b: &Point<f64>) -> f64
[src]
Returns the bearing between two points in angles
Arguments
a
- First pointb
- Second point
Examples
use cheap_ruler::{CheapRuler, DistanceUnit}; let cr = CheapRuler::new(44.7192003, DistanceUnit::Meters); let bearing = cr.bearing( &(14.8901816, 44.7209699).into(), &(14.8905188, 44.7209699).into() ); assert_eq!(bearing, 90.0);
pub fn destination(
&self,
origin: &Point<f64>,
dist: f64,
bearing: f64
) -> Point<f64>
[src]
&self,
origin: &Point<f64>,
dist: f64,
bearing: f64
) -> Point<f64>
Returns a new point given distance and bearing from the starting point
Arguments
origin
- origin pointdist
- distancebearing
- bearing
Examples
use cheap_ruler::{CheapRuler, DistanceUnit}; let cr = CheapRuler::new(44.7192003, DistanceUnit::Meters); let p1 = (14.8901816, 44.7209699).into(); let p2 = (14.8905188, 44.7209699).into(); let dist = cr.distance(&p1, &p2); let bearing = cr.bearing(&p1, &p2); let destination = cr.destination(&p1, dist, bearing); assert_eq!(destination.lng(), p2.lng()); assert_eq!(destination.lat(), p2.lat());
pub fn offset(&self, origin: &Point<f64>, dx: f64, dy: f64) -> Point<f64>
[src]
Returns a new point given easting and northing offsets (in ruler units) from the starting point
Arguments
origin
- pointdx
- eastingdy
- northing
pub fn line_distance(&self, points: &LineString<f64>) -> f64
[src]
Given a line (an array of points), returns the total line distance.
Arguments
points
- line of points
Example
use cheap_ruler::{CheapRuler, DistanceUnit}; use geo_types::LineString; let cr = CheapRuler::new(50.458, DistanceUnit::Meters); let line_string: LineString<f64> = vec![ (-67.031, 50.458), (-67.031, 50.534), (-66.929, 50.534), (-66.929, 50.458) ].into(); let length = cr.line_distance(&line_string);
pub fn area(&self, polygon: &Polygon<f64>) -> f64
[src]
Given a polygon returns the area
polygon
- Polygon
pub fn along(&self, line: &LineString<f64>, dist: f64) -> Option<Point<f64>>
[src]
Returns the point at a specified distance along the line
Arguments
line
- Linedist
- Distance along the line
pub fn point_to_segment_distance(
&self,
p: &Point<f64>,
start: &Point<f64>,
end: &Point<f64>
) -> f64
[src]
&self,
p: &Point<f64>,
start: &Point<f64>,
end: &Point<f64>
) -> f64
Returns the shortest distance between a point and a line segment given with two points.
Arguments
p
- Point to calculate the distance fromstart
- Start point of line segmentend
- End point of line segment
pub fn point_on_line(
&self,
line: &LineString<f64>,
point: &Point<f64>
) -> Option<PointOnLine<f64>>
[src]
&self,
line: &LineString<f64>,
point: &Point<f64>
) -> Option<PointOnLine<f64>>
Returns a tuple of the form (point, index, t) where point is closest point on the line from the given point, index is the start index of the segment with the closest point, and t is a parameter from 0 to 1 that indicates where the closest point is on that segment
Arguments
line
- Line to compare with pointpoint
- Point to calculate the closest point on the line
pub fn line_slice(
&self,
start: &Point<f64>,
stop: &Point<f64>,
line: &LineString<f64>
) -> LineString<f64>
[src]
&self,
start: &Point<f64>,
stop: &Point<f64>,
line: &LineString<f64>
) -> LineString<f64>
Returns a part of the given line between the start and the stop points (or their closest points on the line)
Arguments
start
- Start pointstop
- Stop pointline
- Line string
pub fn line_slice_along(
&self,
start: f64,
stop: f64,
line: &LineString<f64>
) -> LineString<f64>
[src]
&self,
start: f64,
stop: f64,
line: &LineString<f64>
) -> LineString<f64>
Returns a part of the given line between the start and the stop points indicated by distance along the line
start
- Start distancestop
- Stop distanceline
- Line string
pub fn buffer_point(&self, p: &Point<f64>, buffer: f64) -> Rect<f64>
[src]
Given a point, returns a bounding rectangle created from the given point buffered by a given distance
Arguments
p
- Pointbuffer
- Buffer distance
pub fn buffer_bbox(&self, bbox: &Rect<f64>, buffer: f64) -> Rect<f64>
[src]
Given a bounding box, returns the box buffered by a given distance
Arguments
bbox
- Bounding boxbuffer
- Buffer distance
pub fn inside_bbox(&self, p: &Point<f64>, bbox: &Rect<f64>) -> bool
[src]
Returns true if the given point is inside in the given bounding box, otherwise false.
Arguments
p
- Pointbbox
- Bounding box
Trait Implementations
impl Clone for CheapRuler
[src]
fn clone(&self) -> CheapRuler
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for CheapRuler
[src]
impl PartialEq<CheapRuler> for CheapRuler
[src]
fn eq(&self, other: &CheapRuler) -> bool
[src]
fn ne(&self, other: &CheapRuler) -> bool
[src]
impl StructuralPartialEq for CheapRuler
[src]
Auto Trait Implementations
impl RefUnwindSafe for CheapRuler
impl Send for CheapRuler
impl Sync for CheapRuler
impl Unpin for CheapRuler
impl UnwindSafe for CheapRuler
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,