geo/algorithm/line_measures/destination.rs
1use geo_types::{CoordFloat, Point};
2
3/// Calculate the destination point from an origin point, given a bearing and a distance.
4pub trait Destination<F: CoordFloat> {
5 /// Returns a new point having travelled the `distance` along a line
6 /// from the `origin` point with the given `bearing`.
7 ///
8 /// See [specific implementations](#implementors) for details.
9 ///
10 /// # Units
11 ///
12 /// - `origin`: Point where the units of x/y depend on the [trait implementation](#implementors).
13 /// - `bearing`: degrees, where: North: 0°, East: 90°, South: 180°, West: 270°
14 /// - `distance`: depends on the [trait implementation](#implementors).
15 /// - returns: Point where the units of x/y depend on the [trait implementation](#implementors).
16 ///
17 /// # Examples
18 ///
19 /// ```
20 /// # use approx::assert_relative_eq;
21 /// use geo::{Haversine, Rhumb, Geodesic, Destination, Point};
22 ///
23 /// let point = Point::new(0.0, 0.0);
24 ///
25 /// assert_relative_eq!(Haversine.destination(point, 45.0, 111_111.0), Point::new(0.706607921147679, 0.7065541919063233));
26 /// assert_relative_eq!(Geodesic.destination(point, 45.0, 111_111.0), Point::new(0.7058183774535367, 0.7105205988658333));
27 /// assert_relative_eq!(Rhumb.destination(point, 45.0, 111_111.0), Point::new(0.706590011673029, 0.7065721019258285));
28 /// ```
29 ///
30 /// [`metric_spaces`]: super::metric_spaces
31 fn destination(&self, origin: Point<F>, bearing: F, distance: F) -> Point<F>;
32}