Skip to content

Commit

Permalink
Merge #54
Browse files Browse the repository at this point in the history
54: use `approx` for better failure output r=urschrei a=michaelkirk

Gives output like:
```
assert_relative_eq!(t.x(), 1450880.29)

    left  = 0.0
    right = 1450880.29
```

vs previously:
```
thread 'proj::test::test_london_inverse' panicked at 'assertion failed: f > 0.99999', src/proj.rs:885:9
```


Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
  • Loading branch information
bors[bot] and michaelkirk authored Jan 6, 2021
2 parents a6cc3a1 + 0cdb489 commit 3c33538
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pkg_config = [ "proj-sys/pkg_config" ]
network = ["reqwest"]

[dev-dependencies]
assert_approx_eq = "1.1.0"
approx = "0.3"

[package.metadata.docs.rs]
features = [ "proj-sys/nobuild", "network", "geo-types" ]
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ let ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();
let result = ft_to_m
.convert((4760096.421921f64, 3744293.729449f64))
.unwrap();
assert_approx_eq!(result.0, 1450880.2910605003);
assert_approx_eq!(result.1, 1141263.0111604529);
assert_relative_eq!(result.0, 1450880.2910605003);
assert_relative_eq!(result.1, 1141263.0111604529);
```

### Convert from [NAD 83 US Survey Feet](https://epsg.io/2230) to [NAD 83 Meters](https://epsg.io/26946) Using the `pipeline` Operator
Expand Down Expand Up @@ -71,8 +71,8 @@ let ft_to_m = Proj::new("

// The Presidio, approximately
let result = ft_to_m.convert((4760096.421921f64, 3744293.729449f64)).unwrap();
assert_approx_eq!(result.0, 1450880.2910605003);
assert_approx_eq!(result.1, 1141263.01116045);
assert_relative_eq!(result.0, 1450880.2910605003);
assert_relative_eq!(result.1, 1141263.01116045);
```

### Inverse Projection from [Stereo70](https://epsg.io/3844) to Geodetic
Expand All @@ -90,8 +90,8 @@ let stereo70 = Proj::new("
let geodetic_radians_point = stereo70.project(
(500119.70352012233f64, 500027.77896348457f64), true
).unwrap();
assert_approx_eq!(geodetic_radians_point.0, 0.436332);
assert_approx_eq!(geodetic_radians_point.1, 0.802851);
assert_relative_eq!(geodetic_radians_point.0, 0.436332, epsilon=1e-5);
assert_relative_eq!(geodetic_radians_point.1, 0.802851, epsiolon=1e-5);
```

## Usage
Expand Down Expand Up @@ -187,8 +187,8 @@ let proj = Proj::new_known_crs(&from, &to, None).unwrap();

let result = proj.convert(donut_shop).unwrap();

assert_approx_eq!(result.x(), 158458.67251293268);
assert_approx_eq!(result.y(), -434296.8803996085);
assert_relative_eq!(result.x(), 158458.67251293268);
assert_relative_eq!(result.y(), -434296.8803996085);
```

### Integration with `geo-types`
Expand All @@ -197,7 +197,7 @@ If you've enabled the `geo-types` feature, you can skip allocating an intermedia
and pass the [`geo-types`](https://crates.io/crates/geo-types) directly.

```rust
# use assert_approx_eq::assert_approx_eq;
# use approx::assert_relative_eq;
use proj::Proj;
use geo_types::Point;

Expand All @@ -209,8 +209,8 @@ let nad_ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();

let result = nad_ft_to_m.convert(my_point).unwrap();

assert_approx_eq!(result.x(), 1450880.2910605003f64);
assert_approx_eq!(result.y(), 1141263.0111604529f64);
assert_relative_eq!(result.x(), 1450880.2910605003f64);
assert_relative_eq!(result.y(), 1141263.0111604529f64);
```

License: MIT/Apache-2.0
2 changes: 1 addition & 1 deletion proj-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! [`proj`](https://github.com/georust/proj) crate for general use.
//!
//! A guide to the functions can be found here:
//! https://proj.org/development/reference/functions.html.
//! <https://proj.org/development/reference/functions.html>.
//!
//! By default, the crate will search for an existing `libproj` (via `PROJ v7.1.x`)
//! installation on your system using
Expand Down
12 changes: 6 additions & 6 deletions src/geo_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///```rust
/// # use assert_approx_eq::assert_approx_eq;
/// # use approx::assert_relative_eq;
/// extern crate proj;
/// use proj::Proj;
/// use geo_types::Coordinate;
Expand All @@ -10,8 +10,8 @@
/// let result = nad_ft_to_m
/// .convert(Coordinate { x: 4760096.421921f64, y: 3744293.729449f64 })
/// .unwrap();
/// assert_approx_eq!(result.x, 1450880.29f64, 1.0e-2);
/// assert_approx_eq!(result.y, 1141263.01f64, 1.0e-2);
/// assert_relative_eq!(result.x, 1450880.29f64, epsilon=1.0e-2);
/// assert_relative_eq!(result.y, 1141263.01f64, epsilon=1.0e-2);
/// ```
impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Coordinate<T> {
fn x(&self) -> T {
Expand All @@ -26,7 +26,7 @@ impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Coordinate<T
}

///```rust
/// # use assert_approx_eq::assert_approx_eq;
/// # use approx::assert_relative_eq;
/// extern crate proj;
/// use proj::Proj;
/// use geo_types::Point;
Expand All @@ -37,8 +37,8 @@ impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Coordinate<T
/// let result = nad_ft_to_m
/// .convert(Point::new(4760096.421921f64, 3744293.729449f64))
/// .unwrap();
/// assert_approx_eq!(result.x(), 1450880.29f64, 1.0e-2);
/// assert_approx_eq!(result.y(), 1141263.01f64, 1.0e-2);
/// assert_relative_eq!(result.x(), 1450880.29f64, epsilon=1.0e-2);
/// assert_relative_eq!(result.y(), 1141263.01f64, epsilon=1.0e-2);
/// ```
impl<T: crate::proj::CoordinateType> crate::Coord<T> for geo_types::Point<T> {
fn x(&self) -> T {
Expand Down
35 changes: 19 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! ## Convert from [NAD 83 US Survey Feet](https://epsg.io/2230) to [NAD 83 Meters](https://epsg.io/26946) Using EPSG Codes
//!
//! ```rust
//! # use assert_approx_eq::assert_approx_eq;
//! # use approx::assert_relative_eq;
//! use proj::Proj;
//!
//! let from = "EPSG:2230";
Expand All @@ -38,8 +38,8 @@
//! let result = ft_to_m
//! .convert((4760096.421921f64, 3744293.729449f64))
//! .unwrap();
//! assert_approx_eq!(result.0, 1450880.2910605003);
//! assert_approx_eq!(result.1, 1141263.0111604529);
//! assert_relative_eq!(result.0, 1450880.29, epsilon=1e-2);
//! assert_relative_eq!(result.1, 1141263.01, epsilon=1e-2);
//! ```
//!
//! ## Convert from [NAD 83 US Survey Feet](https://epsg.io/2230) to [NAD 83 Meters](https://epsg.io/26946) Using the `pipeline` Operator
Expand All @@ -54,7 +54,7 @@
//!
//!
//! ```rust
//! # use assert_approx_eq::assert_approx_eq;
//! # use approx::assert_relative_eq;
//! use proj::Proj;
//!
//! let ft_to_m = Proj::new("
Expand All @@ -70,14 +70,14 @@
//!
//! // The Presidio, approximately
//! let result = ft_to_m.convert((4760096.421921f64, 3744293.729449f64)).unwrap();
//! assert_approx_eq!(result.0, 1450880.2910605003);
//! assert_approx_eq!(result.1, 1141263.01116045);
//! assert_relative_eq!(result.0, 1450880.29, epsilon=1e-2);
//! assert_relative_eq!(result.1, 1141263.01, epsilon=1e-2);
//! ```
//!
//! ## Inverse Projection from [Stereo70](https://epsg.io/3844) to Geodetic
//!
//! ```rust
//! # use assert_approx_eq::assert_approx_eq;
//! # use approx::assert_relative_eq;
//! use proj::Proj;
//!
//! // Carry out an inverse projection from Pulkovo 1942(58) / Stereo70 (EPSG 3844)
Expand All @@ -90,8 +90,8 @@
//! let geodetic_radians_point = stereo70.project(
//! (500119.70352012233f64, 500027.77896348457f64), true
//! ).unwrap();
//! assert_approx_eq!(geodetic_radians_point.0, 0.436332);
//! assert_approx_eq!(geodetic_radians_point.1, 0.802851);
//! assert_relative_eq!(geodetic_radians_point.0, 0.436332, epsilon=1e-5);
//! assert_relative_eq!(geodetic_radians_point.1, 0.802851, epsilon=1e-5);
//! ```
//!
//! # Usage
Expand Down Expand Up @@ -160,7 +160,7 @@
//! without any intermediate allocation.
//!
//! ```rust
//! # use assert_approx_eq::assert_approx_eq;
//! # use approx::assert_relative_eq;
//! use proj::{Proj, Coord};
//!
//! struct MyPointOfIntereset {
Expand Down Expand Up @@ -188,8 +188,8 @@
//!
//! let result = proj.convert(donut_shop).unwrap();
//!
//! assert_approx_eq!(result.x(), 158458.67251293268);
//! assert_approx_eq!(result.y(), -434296.8803996085);
//! assert_relative_eq!(result.x(), 158458.67, epsilon=1e-2);
//! assert_relative_eq!(result.y(), -434296.88, epsilon=1e-2);
//! ```
#![cfg_attr(
feature = "geo-types",
Expand All @@ -200,7 +200,7 @@ If you've enabled the `geo-types` feature, you can skip allocating an intermedia
and pass the [`geo-types`](https://crates.io/crates/geo-types) directly.
```rust
# use assert_approx_eq::assert_approx_eq;
# use approx::assert_relative_eq;
use proj::Proj;
use geo_types::Point;
Expand All @@ -212,12 +212,11 @@ let nad_ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();
let result = nad_ft_to_m.convert(my_point).unwrap();
assert_approx_eq!(result.x(), 1450880.2910605003f64);
assert_approx_eq!(result.y(), 1141263.0111604529f64);
assert_relative_eq!(result.x(), 1450880.29, epsilon=1e-2);
assert_relative_eq!(result.y(), 1141263.01, epsilon=1e-2);
```
"##
)]

#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(feature = "network")]
Expand All @@ -227,6 +226,10 @@ mod network;
#[cfg(feature = "geo-types")]
mod geo_types;

#[cfg(test)]
#[macro_use]
extern crate approx;

mod proj;

pub use crate::proj::Area;
Expand Down
Loading

0 comments on commit 3c33538

Please sign in to comment.