Skip to content

Commit 8800929

Browse files
committed
Simplified, and added dimension+measure
1 parent 8fdbda2 commit 8800929

12 files changed

+111
-157
lines changed

examples/01-geometric_geodesy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ fn main() -> Result<(), Error> {
4646
// surface of the ellipsoid. Let's compute the distance and
4747
// azimuth between the approximate locations of the airports
4848
// of Copenhagen (CPH) and Paris (CDG).
49-
let CPH = Coor4D::geo(55., 12., 0., 0.);
50-
let CDG = Coor4D::geo(49., 2., 0., 0.);
49+
let CPH = Coor2D::geo(55., 12.);
50+
let CDG = Coor2D::geo(49., 2.);
5151

5252
// By historical convention the "from A to B" situation is considered
5353
// the inverse sense of the geodesic problem - hence `geodesic_inv`:

examples/08-user_defined_operators_using_proj.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub fn proj_constructor(parameters: &RawParameters, _ctx: &dyn Context) -> Resul
173173
fn main() -> anyhow::Result<()> {
174174
let mut prv = geodesy::Minimal::new();
175175
prv.register_op("proj", OpConstructor(proj_constructor));
176+
let e = Ellipsoid::default();
176177

177178
// Check that we can access the `proj` binary - if not, just ignore
178179
if Command::new("proj").stderr(Stdio::piped()).spawn().is_err() {
@@ -195,7 +196,7 @@ fn main() -> anyhow::Result<()> {
195196
println!("projected: {:?}", geo[0]);
196197

197198
ctx.apply(op, Inv, &mut geo)?;
198-
assert!(rtp[0].default_ellps_dist(&geo[0]) < 1e-5);
199+
assert!(e.distance(&rtp[0], &geo[0]) < 1e-5);
199200
println!("roundtrip: {:?}", geo[0].to_degrees());
200201

201202
// Inverted invocation - note "proj inv ..."
@@ -208,7 +209,7 @@ fn main() -> anyhow::Result<()> {
208209

209210
// Now, we get the inverse utm projection when calling the operator in the Fwd direction
210211
ctx.apply(op, Fwd, &mut utm)?;
211-
assert!(geo[0].default_ellps_dist(&utm[0]) < 1e-5);
212+
assert!(e.distance(&utm[0], &geo[0]) < 1e-5);
212213
// ...and roundtrip back to utm
213214
ctx.apply(op, Inv, &mut utm)?;
214215
assert!(rtp[0].hypot2(&utm[0]) < 1e-5);

src/coordinate/coor2d.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,9 @@ impl Coor2D {
164164
(self[0] - other[0]).hypot(self[1] - other[1])
165165
}
166166

167-
/// The Geodesic distance on the default ellipsoid. Mostly a shortcut
168-
/// for test authoring
169-
pub fn default_ellps_dist(&self, other: &Self) -> f64 {
170-
Ellipsoid::default().distance(
171-
&Coor4D([self[0], self[1], 0., 0.]),
172-
&Coor4D([other[0], other[1], 0., 0.]),
173-
)
174-
}
175167
}
176168

169+
177170
impl From<Coor2D> for Coor4D {
178171
fn from(c: Coor2D) -> Self {
179172
Coor4D([c[0], c[1], 0.0, 0.0])
@@ -193,11 +186,12 @@ mod tests {
193186
use super::*;
194187
#[test]
195188
fn distances() {
189+
let e = Ellipsoid::default();
196190
let lat = angular::dms_to_dd(55, 30, 36.);
197191
let lon = angular::dms_to_dd(12, 45, 36.);
198192
let dms = Coor2D::geo(lat, lon);
199193
let geo = Coor2D::geo(55.51, 12.76);
200-
assert!(geo.default_ellps_dist(&dms) < 1e-10);
194+
assert!(e.distance(&geo, &dms) < 1e-10);
201195
}
202196

203197
#[test]

src/coordinate/coor32.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,6 @@ impl Coor32 {
177177
pub fn hypot2(&self, other: &Self) -> f64 {
178178
(self[0] as f64 - other[0] as f64).hypot(self[1] as f64 - other[1] as f64)
179179
}
180-
181-
/// The Geodesic distance on the default ellipsoid. Mostly a shortcut
182-
/// for test authoring
183-
pub fn default_ellps_dist(&self, other: &Self) -> f64 {
184-
Ellipsoid::default().distance(
185-
&Coor4D([self[0] as f64, self[1] as f64, 0., 0.]),
186-
&Coor4D([other[0] as f64, other[1] as f64, 0., 0.]),
187-
)
188-
}
189180
}
190181

191182
// ----- T E S T S ---------------------------------------------------
@@ -199,7 +190,8 @@ mod tests {
199190
let lon = angular::dms_to_dd(12, 45, 36.);
200191
let dms = Coor32::geo(lat, lon);
201192
let geo = Coor32::geo(55.51, 12.76);
202-
assert!(geo.default_ellps_dist(&dms) < 1e-10);
193+
let e = &Ellipsoid::default();
194+
assert!(e.distance(&dms, &geo) < 1e-9);
203195
}
204196

205197
#[test]

src/coordinate/coor3d.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -263,37 +263,22 @@ impl Coor3D {
263263
.hypot(self[2] - other[2])
264264
}
265265

266-
/// The 3D distance between two points given as internal angular
267-
/// coordinates. Mostly a shortcut for test authoring
268-
pub fn default_ellps_3d_dist(&self, other: &Self) -> f64 {
269-
let e = Ellipsoid::default();
270-
let from = Coor4D([self[0], self[1], self[2], 0.]);
271-
let to = Coor4D([other[0], other[1], other[2], 0.]);
272-
273-
e.cartesian(&from).hypot3(&e.cartesian(&to))
274-
}
275-
276-
/// The Geodesic distance on the default ellipsoid. Mostly a shortcut
277-
/// for test authoring
278-
pub fn default_ellps_dist(&self, other: &Self) -> f64 {
279-
let from = Coor4D([self[0], self[1], self[2], 0.]);
280-
let to = Coor4D([other[0], other[1], other[2], 0.]);
281-
Ellipsoid::default().distance(&from, &to)
282-
}
283266
}
284267

285268
// ----- T E S T S ---------------------------------------------------
286269

287270
#[cfg(test)]
288271
mod tests {
289272
use super::*;
273+
290274
#[test]
291275
fn distances() {
276+
let e = Ellipsoid::default();
292277
let lat = angular::dms_to_dd(55, 30, 36.);
293278
let lon = angular::dms_to_dd(12, 45, 36.);
294279
let dms = Coor3D::geo(lat, lon, 0.);
295280
let geo = Coor3D::geo(55.51, 12.76, 0.);
296-
assert!(geo.default_ellps_dist(&dms) < 1e-10);
281+
assert!(e.distance(&geo, &dms) < 1e-10);
297282
}
298283

299284
#[test]

src/coordinate/coor4d.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -269,33 +269,22 @@ impl Coor4D {
269269
.hypot(self[1] - other[1])
270270
.hypot(self[2] - other[2])
271271
}
272-
273-
/// The 3D distance between two points given as internal angular
274-
/// coordinates. Mostly a shortcut for test authoring
275-
pub fn default_ellps_3d_dist(&self, other: &Self) -> f64 {
276-
let e = Ellipsoid::default();
277-
e.cartesian(self).hypot3(&e.cartesian(other))
278-
}
279-
280-
/// The Geodesic distance on the default ellipsoid. Mostly a shortcut
281-
/// for test authoring
282-
pub fn default_ellps_dist(&self, other: &Self) -> f64 {
283-
Ellipsoid::default().distance(self, other)
284-
}
285272
}
286273

287274
// ----- T E S T S ---------------------------------------------------
288275

289276
#[cfg(test)]
290277
mod tests {
291278
use super::*;
279+
292280
#[test]
293281
fn distances() {
294282
let lat = angular::dms_to_dd(55, 30, 36.);
295283
let lon = angular::dms_to_dd(12, 45, 36.);
296284
let dms = Coor4D::geo(lat, lon, 0., 2020.);
297285
let geo = Coor4D::geo(55.51, 12.76, 0., 2020.);
298-
assert!(geo.default_ellps_dist(&dms) < 1e-10);
286+
let e = Ellipsoid::default();
287+
assert!(e.distance(&geo, &dms) < 1e-10);
299288
}
300289

301290
#[test]

0 commit comments

Comments
 (0)