Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove all deprecated features from geo-types #772

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ members = ["geo", "geo-types", "geo-postgis", "geo-test-fixtures", "jts-test-run

# Ensure any transitive dependencies also use the local geo/geo-types
geo = { path = "geo" }
geo-types = { path = "geo-types" }
# Uncomment this after geo-types 0.8+ is published with TZM support
# geo-types = { path = "geo-types" }
4 changes: 3 additions & 1 deletion geo-postgis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ edition = "2021"

[dependencies]
postgis = { version = ">=0.7.0, <0.9.0" }
geo-types = { version = "0.7", path = "../geo-types" }
geo-types = "0.7.4"
# Use this after geo-types 0.8+ is published with TZM support
#geo-types = { version = "0.8", path = "../geo-types" }
4 changes: 3 additions & 1 deletion geo-test-fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ publish = false

[dependencies]
wkt = { version = "0.10.0", default-features = false }
geo-types = { path = "../geo-types" }
geo-types = "0.7.4"
# Use this after geo-types 0.8+ is published with TZM support
#geo-types = { version = "0.8", path = "../geo-types" }
23 changes: 23 additions & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changes

## Unreleased

* BREAKING: Remove deprecated functions on the `Geometry<T>`:
* `into_point` - Switch to `std::convert::TryInto<Point>`
* `into_line_string` - Switch to `std::convert::TryInto<LineString>`
* `into_line` - Switch to `std::convert::TryInto<Line>`
* `into_polygon` - Switch to `std::convert::TryInto<Polygon>`
* `into_multi_point` - Switch to `std::convert::TryInto<MultiPoint>`
* `into_multi_line_string` - Switch to `std::convert::TryInto<MultiLineString>`
* `into_multi_polygon` - Switch to `std::convert::TryInto<MultiPolygon>`
* BREAKING: Remove deprecated `CoordinateType` trait. Use `CoordFloat` or `CoordNum` instead.
* BREAKING: Remove deprecated functions from `LineString<T>`
* Remove `points_iter()` -- use `points()` instead.
* Remove `num_coords()` -- use `geo::algorithm::coords_iter::CoordsIter::coords_count` instead.
* BREAKING: Remove deprecated functions from `Point<T>`
* Remove `lng()` -- use `x()` instead.
* Remove `set_lng()` -- use `set_x()` instead.
* Remove `lat()` -- use `y()` instead.
* Remove `set_lat()` -- use `set_y()` instead.
* BREAKING: Remove deprecated `Polygon<T>::is_convex()` -- use `geo::is_convex` on `poly.exterior()` instead.
* BREAKING: Remove deprecated `Rect<T>::try_new()` -- use `Rect::new` instead, since `Rect::try_new` will never Error. Also removes corresponding `InvalidRectCoordinatesError`.
* BREAKING: Replace deprecated `GeometryCollection::new()` with `GeometryCollection::new(value)`, and remove deprecated `GeometryCollection::new_from(value)`.

## 0.7.4

* BREAKING: Make `Rect::to_lines` return lines in winding order for `Rect::to_polygon`.
Expand Down
97 changes: 0 additions & 97 deletions geo-types/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,103 +87,6 @@ impl<T: CoordNum> From<Triangle<T>> for Geometry<T> {
}
}

impl<T: CoordNum> Geometry<T> {
/// If this Geometry is a Point, then return that, else None.
///
/// # Examples
///
/// ```
/// use geo_types::*;
/// use std::convert::TryInto;
///
/// let g = Geometry::Point(Point::new(0., 0.));
/// let p2: Point<f32> = g.try_into().unwrap();
/// assert_eq!(p2, Point::new(0., 0.,));
/// ```
#[deprecated(
note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<Point>"
)]
pub fn into_point(self) -> Option<Point<T>> {
if let Geometry::Point(x) = self {
Some(x)
} else {
None
}
}

/// If this Geometry is a LineString, then return that LineString, else None.
#[deprecated(
note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<LineString>"
)]
pub fn into_line_string(self) -> Option<LineString<T>> {
if let Geometry::LineString(x) = self {
Some(x)
} else {
None
}
}

/// If this Geometry is a Line, then return that Line, else None.
#[deprecated(
note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<Line>"
)]
pub fn into_line(self) -> Option<Line<T>> {
if let Geometry::Line(x) = self {
Some(x)
} else {
None
}
}

/// If this Geometry is a Polygon, then return that, else None.
#[deprecated(
note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<Polygon>"
)]
pub fn into_polygon(self) -> Option<Polygon<T>> {
if let Geometry::Polygon(x) = self {
Some(x)
} else {
None
}
}

/// If this Geometry is a MultiPoint, then return that, else None.
#[deprecated(
note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPoint>"
)]
pub fn into_multi_point(self) -> Option<MultiPoint<T>> {
if let Geometry::MultiPoint(x) = self {
Some(x)
} else {
None
}
}

/// If this Geometry is a MultiLineString, then return that, else None.
#[deprecated(
note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiLineString>"
)]
pub fn into_multi_line_string(self) -> Option<MultiLineString<T>> {
if let Geometry::MultiLineString(x) = self {
Some(x)
} else {
None
}
}

/// If this Geometry is a MultiPolygon, then return that, else None.
#[deprecated(
note = "Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPolygon>"
)]
pub fn into_multi_polygon(self) -> Option<MultiPolygon<T>> {
if let Geometry::MultiPolygon(x) = self {
Some(x)
} else {
None
}
}
}

macro_rules! try_from_geometry_impl {
($($type: ident),+) => {
$(
Expand Down
30 changes: 10 additions & 20 deletions geo-types/src/geometry_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::ops::{Index, IndexMut};
/// use geo_types::{Point, point, Geometry, GeometryCollection};
/// let p = point!(x: 1.0, y: 1.0);
/// let pe = Geometry::Point(p);
/// let gc = GeometryCollection::new_from(vec![pe]);
/// let gc = GeometryCollection::new(vec![pe]);
/// for geom in gc {
/// println!("{:?}", Point::try_from(geom).unwrap().x());
/// }
Expand All @@ -37,7 +37,7 @@ use std::ops::{Index, IndexMut};
/// use geo_types::{Point, point, Geometry, GeometryCollection};
/// let p = point!(x: 1.0, y: 1.0);
/// let pe = Geometry::Point(p);
/// let gc = GeometryCollection::new_from(vec![pe]);
/// let gc = GeometryCollection::new(vec![pe]);
/// gc.iter().for_each(|geom| println!("{:?}", geom));
/// ```
///
Expand All @@ -48,7 +48,7 @@ use std::ops::{Index, IndexMut};
/// use geo_types::{Point, point, Geometry, GeometryCollection};
/// let p = point!(x: 1.0, y: 1.0);
/// let pe = Geometry::Point(p);
/// let mut gc = GeometryCollection::new_from(vec![pe]);
/// let mut gc = GeometryCollection::new(vec![pe]);
/// gc.iter_mut().for_each(|geom| {
/// if let Geometry::Point(p) = geom {
/// p.set_x(0.2);
Expand All @@ -65,7 +65,7 @@ use std::ops::{Index, IndexMut};
/// use geo_types::{Point, point, Geometry, GeometryCollection};
/// let p = point!(x: 1.0, y: 1.0);
/// let pe = Geometry::Point(p);
/// let gc = GeometryCollection::new_from(vec![pe]);
/// let gc = GeometryCollection::new(vec![pe]);
/// println!("{:?}", gc[0]);
/// ```
///
Expand All @@ -82,18 +82,8 @@ impl<T: CoordNum> Default for GeometryCollection<T> {
}

impl<T: CoordNum> GeometryCollection<T> {
/// Return an empty GeometryCollection
#[deprecated(
note = "Will be replaced with a parametrized version in upcoming version. Use GeometryCollection::default() instead"
)]
pub fn new() -> Self {
GeometryCollection::default()
}

/// DO NOT USE!
/// This fn will be renamed to `new` in the upcoming version.
/// This fn is not marked as deprecated because it would require extensive refactoring of the geo code.
pub fn new_from(value: Vec<Geometry<T>>) -> Self {
/// Instantiate Self from the raw content value
pub fn new(value: Vec<Geometry<T>>) -> Self {
Self(value)
}

Expand Down Expand Up @@ -254,8 +244,8 @@ where
/// ```
/// use geo_types::{GeometryCollection, point};
///
/// let a = GeometryCollection::new_from(vec![point![x: 1.0, y: 2.0].into()]);
/// let b = GeometryCollection::new_from(vec![point![x: 1.0, y: 2.01].into()]);
/// let a = GeometryCollection::new(vec![point![x: 1.0, y: 2.0].into()]);
/// let b = GeometryCollection::new(vec![point![x: 1.0, y: 2.01].into()]);
///
/// approx::assert_relative_eq!(a, b, max_relative=0.1);
/// approx::assert_relative_ne!(a, b, max_relative=0.0001);
Expand Down Expand Up @@ -296,8 +286,8 @@ where
/// ```
/// use geo_types::{GeometryCollection, point};
///
/// let a = GeometryCollection::new_from(vec![point![x: 0.0, y: 0.0].into()]);
/// let b = GeometryCollection::new_from(vec![point![x: 0.0, y: 0.1].into()]);
/// let a = GeometryCollection::new(vec![point![x: 0.0, y: 0.0].into()]);
/// let b = GeometryCollection::new(vec![point![x: 0.0, y: 0.1].into()]);
///
/// approx::abs_diff_eq!(a, b, epsilon=0.1);
/// approx::abs_diff_ne!(a, b, epsilon=0.001);
Expand Down
14 changes: 3 additions & 11 deletions geo-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,14 @@ extern crate rstar_0_8;
#[macro_use]
extern crate approx;

#[deprecated(since = "0.7.0", note = "use `CoordFloat` or `CoordNum` instead")]
pub trait CoordinateType: Num + Copy + NumCast + PartialOrd + Debug {}
#[allow(deprecated)]
impl<T: Num + Copy + NumCast + PartialOrd + Debug> CoordinateType for T {}

/// The type of an x or y value of a point/coordinate.
///
/// Floats (`f32` and `f64`) and Integers (`u8`, `i32` etc.) implement this.
///
/// For algorithms which only make sense for floating point, like area or length calculations,
/// see [CoordFloat](trait.CoordFloat.html).
#[allow(deprecated)]
pub trait CoordNum: CoordinateType + Debug {}
#[allow(deprecated)]
impl<T: CoordinateType + Debug> CoordNum for T {}
pub trait CoordNum: Num + Copy + NumCast + PartialOrd + Debug {}
impl<T: Num + Copy + NumCast + PartialOrd + Debug> CoordNum for T {}

pub trait CoordFloat: CoordNum + Float {}
impl<T: CoordNum + Float> CoordFloat for T {}
Expand Down Expand Up @@ -117,8 +110,7 @@ mod triangle;
pub use crate::triangle::Triangle;

mod rect;
#[allow(deprecated)]
pub use crate::rect::{InvalidRectCoordinatesError, Rect};
pub use crate::rect::Rect;

mod error;
pub use error::Error;
Expand Down
26 changes: 0 additions & 26 deletions geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,6 @@ impl<T: CoordNum> LineString<T> {
Self(value)
}

/// Return an iterator yielding the coordinates of a [`LineString`] as [`Point`]s
#[deprecated(note = "Use points() instead")]
pub fn points_iter(&self) -> PointsIter<T> {
PointsIter(self.0.iter())
}

/// Return an iterator yielding the coordinates of a [`LineString`] as [`Point`]s
pub fn points(&self) -> PointsIter<T> {
PointsIter(self.0.iter())
Expand Down Expand Up @@ -287,26 +281,6 @@ impl<T: CoordNum> LineString<T> {
}
}

/// Return the number of coordinates in the [`LineString`].
///
/// # Examples
///
/// ```
/// use geo_types::LineString;
///
/// let mut coords = vec![(0., 0.), (5., 0.), (7., 9.)];
/// let line_string: LineString<f32> = coords.into_iter().collect();
///
/// # #[allow(deprecated)]
/// # {
/// assert_eq!(3, line_string.num_coords());
/// # }
/// ```
#[deprecated(note = "Use geo::algorithm::coords_iter::CoordsIter::coords_count instead")]
pub fn num_coords(&self) -> usize {
self.0.len()
}

/// Checks if the linestring is closed; i.e. it is
/// either empty or, the first and last points are the
/// same.
Expand Down
66 changes: 0 additions & 66 deletions geo-types/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,72 +157,6 @@ impl<T: CoordNum> Point<T> {
pub fn x_y(self) -> (T, T) {
(self.0.x, self.0.y)
}
/// Returns the longitude/horizontal component of the point.
///
/// # Examples
///
/// ```
/// use geo_types::Point;
///
/// let p = Point::new(1.234, 2.345);
///
/// assert_eq!(p.x(), 1.234);
/// ```
#[deprecated = "use `Point::x` instead, it's less ambiguous"]
pub fn lng(self) -> T {
self.x()
}

/// Sets the longitude/horizontal component of the point.
///
/// # Examples
///
/// ```
/// use geo_types::Point;
///
/// let mut p = Point::new(1.234, 2.345);
/// #[allow(deprecated)]
/// p.set_lng(9.876);
///
/// assert_eq!(p.x(), 9.876);
/// ```
#[deprecated = "use `Point::set_x` instead, it's less ambiguous"]
pub fn set_lng(&mut self, lng: T) -> &mut Self {
self.set_x(lng)
}

/// Returns the latitude/vertical component of the point.
///
/// # Examples
///
/// ```
/// use geo_types::Point;
///
/// let p = Point::new(1.234, 2.345);
///
/// assert_eq!(p.y(), 2.345);
/// ```
#[deprecated = "use `Point::y` instead, it's less ambiguous"]
pub fn lat(self) -> T {
self.y()
}
/// Sets the latitude/vertical component of the point.
///
/// # Examples
///
/// ```
/// use geo_types::Point;
///
/// let mut p = Point::new(1.234, 2.345);
/// #[allow(deprecated)]
/// p.set_lat(9.876);
///
/// assert_eq!(p.y(), 9.876);
/// ```
#[deprecated = "use `Point::set_y` instead, it's less ambiguous"]
pub fn set_lat(&mut self, lat: T) -> &mut Self {
self.set_y(lat)
}
}

impl<T: CoordNum> Point<T> {
Expand Down
Loading