Skip to content

Commit

Permalink
Updated changelog; clippy fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim committed Jan 8, 2023
1 parent 2954a82 commit 8b91a97
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

- <https://github.com/georust/gdal/pull/355>

- Implemented `Geometry::make_valid` and `Geometry::make_valid_ex`.
- Exposed various functions on `Geometry`: `make_valid`, `geometry_name`, and `point_count`.

- <https://github.com/georust/gdal/pull/356>

Expand Down
2 changes: 1 addition & 1 deletion src/cpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl From<()> for CslStringList {
}
}

/// Creates a [`CslStringList`] from a slice of _key_/_value_ pairs.
/// Creates a [`CslStringList`] from a slice of _key_/_value_ tuples.
impl<const N: usize> From<&[(&str, &str); N]> for CslStringList {
fn from(pairs: &[(&str, &str); N]) -> Self {
let mut result = Self::default();
Expand Down
32 changes: 20 additions & 12 deletions src/vector/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,21 +473,29 @@ impl Geometry {
///
/// Refer: [OGR_G_MakeValidEx](https://gdal.org/api/vector_c_api.html#_CPPv417OGR_G_MakeValidEx12OGRGeometryH12CSLConstList)
pub fn make_valid<O: Into<CslStringList>>(&self, opts: O) -> Result<Geometry> {
fn inner(geo: &Geometry, opts: CslStringList) -> Result<OGRGeometryH> {
#[cfg(all(major_ge_3, minor_ge_4))]
let c_geom = unsafe { gdal_sys::OGR_G_MakeValidEx(geo.c_geometry(), opts.as_ptr()) };
#[cfg(not(all(major_ge_3, minor_ge_4)))]
let c_geom = unsafe { gdal_sys::OGR_G_MakeValid(geo.c_geometry()) };
Ok(c_geom)
}
let opts = opts.into();

let c_geom = inner(self, opts.into())?;
fn inner(geom: &Geometry, opts: CslStringList) -> Result<Geometry> {
#[cfg(all(major_ge_3, minor_ge_4))]
let c_geom = unsafe { gdal_sys::OGR_G_MakeValidEx(geom.c_geometry(), opts.as_ptr()) };

if c_geom.is_null() {
Err(_last_null_pointer_err("OGR_G_MakeValid"))
} else {
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
#[cfg(not(all(major_ge_3, minor_ge_4)))]
let c_geom = {
if !opts.is_empty() {
return Err(GdalError::BadArgument(
"Options to make_valid require GDAL >= 3.4".into(),
));
}
unsafe { gdal_sys::OGR_G_MakeValid(geom.c_geometry()) }
};

if c_geom.is_null() {
Err(_last_null_pointer_err("OGR_G_MakeValid"))
} else {
Ok(unsafe { Geometry::with_c_geometry(c_geom, true) })
}
}
inner(self, opts)
}
}

Expand Down

0 comments on commit 8b91a97

Please sign in to comment.