Skip to content

Commit f57f8a2

Browse files
authored
Merge pull request #63 from JMdoubleU/pub-geodesic-line
Make `GeodesicLine` public
2 parents dec5cd7 + 7ea1374 commit f57f8a2

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

src/geodesic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,10 +912,10 @@ impl Geodesic {
912912
/// Place a second point, given the first point, an azimuth, and a distance.
913913
///
914914
/// # Arguments
915-
/// - lat1 - Latitude of 1st point [degrees] [-90.,90.]
916-
/// - lon1 - Longitude of 1st point [degrees] [-180., 180.]
917-
/// - azi1 - Azimuth at 1st point [degrees] [-180., 180.]
918-
/// - s12 - Distance from 1st to 2nd point [meters] Value may be negative
915+
/// - lat1 - Latitude of 1st point (degrees) [-90.,90.]
916+
/// - lon1 - Longitude of 1st point (degrees) [-180., 180.]
917+
/// - azi1 - Azimuth at 1st point (degrees) [-180., 180.]
918+
/// - s12 - Distance from 1st to 2nd point (meters) Value may be negative
919919
///
920920
/// # Returns
921921
///

src/geodesic_capability.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ pub const OUT_ALL: u64 = 0x7F80;
1111
// Includes LONG_UNROLL
1212
pub const OUT_MASK: u64 = 0xFF80;
1313
pub const EMPTY: u64 = 0;
14-
pub const LATITUDE: u64 = 1 << 7 | CAP_NONE;
15-
pub const LONGITUDE: u64 = 1 << 8 | CAP_C3;
16-
pub const AZIMUTH: u64 = 1 << 9 | CAP_NONE;
17-
pub const DISTANCE: u64 = 1 << 10 | CAP_C1;
14+
pub const LATITUDE: u64 = (1 << 7) | CAP_NONE;
15+
pub const LONGITUDE: u64 = (1 << 8) | CAP_C3;
16+
pub const AZIMUTH: u64 = (1 << 9) | CAP_NONE;
17+
pub const DISTANCE: u64 = (1 << 10) | CAP_C1;
1818
pub const STANDARD: u64 = LATITUDE | LONGITUDE | AZIMUTH | DISTANCE;
19-
pub const DISTANCE_IN: u64 = 1 << 11 | CAP_C1 | CAP_C1p;
20-
pub const REDUCEDLENGTH: u64 = 1 << 12 | CAP_C1 | CAP_C2;
21-
pub const GEODESICSCALE: u64 = 1 << 13 | CAP_C1 | CAP_C2;
22-
pub const AREA: u64 = 1 << 14 | CAP_C4;
19+
pub const DISTANCE_IN: u64 = (1 << 11) | CAP_C1 | CAP_C1p;
20+
pub const REDUCEDLENGTH: u64 = (1 << 12) | CAP_C1 | CAP_C2;
21+
pub const GEODESICSCALE: u64 = (1 << 13) | CAP_C1 | CAP_C2;
22+
pub const AREA: u64 = (1 << 14) | CAP_C4;
2323
pub const LONG_UNROLL: u64 = 1 << 15;
2424
// Does not include LONG_UNROLL
2525
pub const ALL: u64 = OUT_ALL | CAP_ALL;

src/geodesic_line.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use crate::geodesic_capability as caps;
55
use crate::geomath;
66
use std::collections::HashMap;
77

8+
/// A geodesic line.
9+
///
10+
/// Facilitates the determination of a series of points on a single geodesic.
811
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
912
pub struct GeodesicLine {
1013
tiny_: f64, // This should be moved to consts
@@ -47,6 +50,26 @@ pub struct GeodesicLine {
4750
}
4851

4952
impl GeodesicLine {
53+
/// Create a new geodesic line from an initial point and azimuth.
54+
///
55+
/// # Arguments
56+
/// - geod - geodesic parameters
57+
/// - lat1 - initial latitude (degrees)
58+
/// - lon1 - initial longitude (degrees)
59+
/// - azi1 - initial azimuth (degrees)
60+
/// - caps - bitor'ed combination of [capabilities](caps); defaults to `STANDARD | DISTANCE_IN`
61+
/// - `caps |= LATITUDE` for the latitude lat2; this is added automatically
62+
/// - `caps |= LONGITUDE` for the longitude lon2
63+
/// - `caps |= AZIMUTH` for the azimuth azi2; this is added automatically
64+
/// - `caps |= DISTANCE` for the distance s12
65+
/// - `caps |= REDUCEDLENGTH` for the reduced length m12
66+
/// - `caps |= GEODESICSCALE` for the geodesic scales M12 and M21
67+
/// - `caps |= AREA` for the area S12
68+
/// - `caps |= DISTANCE_IN` permits the length of the geodesic to be given in terms of s12;
69+
/// without this capability the length can only be specified in terms of arc length
70+
/// - `caps |= ALL` for all of the above
71+
/// - salp1 - sine of initial azimuth
72+
/// - calp1 - cosine of initial azimuth
5073
pub fn new(
5174
geod: &geodesic::Geodesic,
5275
lat1: f64,
@@ -197,7 +220,46 @@ impl GeodesicLine {
197220
}
198221
}
199222

200-
/// returns (a12, lat2, lon2, azi2, s12, m12, M12, M21, S12)
223+
/// Place a point at a given distance along this line.
224+
///
225+
/// # Arguments
226+
/// - arcmode - Indicates if s12_a12 is an arc length (true) or distance (false)
227+
/// - s12_a12 - Distance to point (meters) or arc length (degrees); can be negative
228+
/// - outmask - bitor'ed combination of [capabilities](caps) defining which values to return
229+
/// - `outmask |= LATITUDE` for the latitude lat2
230+
/// - `outmask |= LONGITUDE` for the longitude lon2
231+
/// - `outmask |= AZIMUTH` for the azimuth azi2
232+
/// - `outmask |= DISTANCE` for the distance s12
233+
/// - `outmask |= REDUCEDLENGTH` for the reduced length m12
234+
/// - `outmask |= GEODESICSCALE` for the geodesic scales M12 and M21
235+
/// - `outmask |= ALL` for all of the above
236+
/// - `outmask |= LONG_UNROLL` to unroll lon2 (instead of reducing it to the range [−180°, 180°])
237+
///
238+
/// # Returns
239+
/// Values are [f64::NAN] if not supported by the specified capabilities.
240+
/// - a12 arc length between point 1 and point 2 (degrees)
241+
/// - lat2 latitude of point 2 (degrees)
242+
/// - lon2 longitude of point 2 (degrees)
243+
/// - azi2 (forward) azimuth at point 2 (degrees)
244+
/// - s12 distance between point 1 and point 2 (meters)
245+
/// - m12 reduced length of geodesic (meters)
246+
/// - M12 geodesic scale of point 2 relative to point 1 (dimensionless)
247+
/// - M21 geodesic scale of point 1 relative to point 2 (dimensionless)
248+
/// - S12 area under the geodesic (meters<sup>2</sup>)
249+
///
250+
/// # Example
251+
/// ```rust
252+
/// use geographiclib_rs::{Geodesic, GeodesicLine, geodesic_capability as caps};
253+
/// let g = Geodesic::wgs84();
254+
/// let outmask = caps::LATITUDE | caps::LONGITUDE | caps::AZIMUTH | caps::DISTANCE_IN;
255+
/// let line = GeodesicLine::new(&g, -11.95887, -116.94513, 92.712619830452549, Some(outmask), None, None);
256+
/// let (_, lat2, lon2, azi2, _, _, _, _, _) = line._gen_position(false, 13834722.5801401374, outmask);
257+
///
258+
/// use approx::assert_relative_eq;
259+
/// assert_relative_eq!(lat2, 4.57352, epsilon=1e-13);
260+
/// assert_relative_eq!(lon2, 7.16501, epsilon=1e-13);
261+
/// assert_relative_eq!(azi2, 78.64960934409585, epsilon=1e-13);
262+
/// ```
201263
pub fn _gen_position(
202264
&self,
203265
arcmode: bool,

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub mod geodesic_capability;
8080
pub use geodesic_capability as capability;
8181

8282
mod geodesic_line;
83+
pub use geodesic_line::GeodesicLine;
8384
mod geomath;
8485
mod polygon_area;
8586
pub use polygon_area::PolygonArea;

src/polygon_area.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub struct PolygonArea<'a> {
6969
/// ```
7070
impl<'a> PolygonArea<'a> {
7171
/// Create a new PolygonArea using a Geodesic.
72-
pub fn new(geoid: &'a Geodesic, winding: Winding) -> PolygonArea {
72+
pub fn new(geoid: &'a Geodesic, winding: Winding) -> Self {
7373
PolygonArea {
7474
geoid,
7575
winding,

0 commit comments

Comments
 (0)