From 164ba8735aeedea794e57eac700fb5a185b50ee7 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 22 Feb 2022 17:58:45 -0500 Subject: [PATCH 1/3] Make CoordinateType an "alias" to CoordFloat Migrate `CoordinateType: Float + Copy + PartialOrd + Debug` to `CoordinateType: CoordFloat`. TBD: Does it make sense to get rid of `CoordinateType` outright, and replace it with CoordFloat? This simplifies usage of proj in other geo libs by making trait requirements consistent. The old requirement of `Float + Copy + PartialOrd + Debug` is now expanded to `Float + Num + Copy + NumCast + PartialOrd + Debug`, plus it fully moves the management of this type upstream to geo-types - so once `Default` is added to geo-types, it becomes transparently added to proj as well. --- src/proj.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/proj.rs b/src/proj.rs index fe529292..90d9b96e 100644 --- a/src/proj.rs +++ b/src/proj.rs @@ -1,6 +1,5 @@ use libc::c_int; use libc::{c_char, c_double}; -use num_traits::Float; use proj_sys::{ proj_area_create, proj_area_destroy, proj_area_set_bbox, proj_cleanup, proj_context_create, proj_context_destroy, proj_context_errno, proj_context_get_url_endpoint, @@ -25,10 +24,11 @@ use std::ffi::CStr; use std::ffi::CString; use std::mem::MaybeUninit; use std::path::Path; +use geo_types::CoordFloat; use thiserror::Error; -pub trait CoordinateType: Float + Copy + PartialOrd + Debug {} -impl CoordinateType for T {} +pub trait CoordinateType: CoordFloat {} +impl CoordinateType for T {} /// An error number returned from a PROJ call. pub(crate) struct Errno(pub libc::c_int); From 05690f44aec916f88c57522f5629afd8e2f8e103 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 22 Feb 2022 18:17:37 -0500 Subject: [PATCH 2/3] ignore idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6e372500..946603af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea target Cargo.lock proj-sys/PROJSRC/proj/ From 79866e96077a4e6c691650bc1ba7787d93535de8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 22 Feb 2022 19:16:25 -0500 Subject: [PATCH 3/3] Support for standalone CoordFloat, without geo_types --- src/proj.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/proj.rs b/src/proj.rs index 90d9b96e..9900f453 100644 --- a/src/proj.rs +++ b/src/proj.rs @@ -24,9 +24,18 @@ use std::ffi::CStr; use std::ffi::CString; use std::mem::MaybeUninit; use std::path::Path; -use geo_types::CoordFloat; use thiserror::Error; +#[cfg(feature = "geo-types")] +use geo_types::CoordFloat; +#[cfg(not(feature = "geo-types"))] +use num_traits::{Num, Float, NumCast}; +#[cfg(not(feature = "geo-types"))] +pub trait CoordFloat: Float + Num + Copy + NumCast + PartialOrd + PartialOrd + Debug + Default {} +#[cfg(not(feature = "geo-types"))] +impl CoordFloat for T {} + + pub trait CoordinateType: CoordFloat {} impl CoordinateType for T {}