Struct cheap_ruler::CheapRuler[][src]

pub struct CheapRuler { /* fields omitted */ }

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 - y
  • z - z
  • distance_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 point
  • b - 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 point
  • b - 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 point
  • b - 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]

Returns a new point given distance and bearing from the starting point

Arguments

  • origin - origin point
  • dist - distance
  • bearing - 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 - point
  • dx - easting
  • dy - 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 - Line
  • dist - Distance along the line

pub fn point_to_segment_distance(
    &self,
    p: &Point<f64>,
    start: &Point<f64>,
    end: &Point<f64>
) -> f64
[src]

Returns the shortest distance between a point and a line segment given with two points.

Arguments

  • p - Point to calculate the distance from
  • start - Start point of line segment
  • end - End point of line segment

pub fn point_on_line(
    &self,
    line: &LineString<f64>,
    point: &Point<f64>
) -> Option<PointOnLine<f64>>
[src]

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 point
  • point - 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]

Returns a part of the given line between the start and the stop points (or their closest points on the line)

Arguments

  • start - Start point
  • stop - Stop point
  • line - Line string

pub fn line_slice_along(
    &self,
    start: f64,
    stop: f64,
    line: &LineString<f64>
) -> LineString<f64>
[src]

Returns a part of the given line between the start and the stop points indicated by distance along the line

  • start - Start distance
  • stop - Stop distance
  • line - 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 - Point
  • buffer - 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 box
  • buffer - 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 - Point
  • bbox - Bounding box

Trait Implementations

impl Clone for CheapRuler[src]

impl Debug for CheapRuler[src]

impl PartialEq<CheapRuler> for CheapRuler[src]

impl StructuralPartialEq for CheapRuler[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.