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

Implement 3D and Measure support for geo types #742

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion geo-postgis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ edition = "2021"

[dependencies]
postgis = { version = ">=0.7.0, <0.9.0" }
geo-types = { version = "0.7", path = "../geo-types" }
geo-types = { version = "0.8.0", path = "../geo-types" }
22 changes: 22 additions & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changes

## Major 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`.

## Unreleased

* BREAKING: Make `Rect::to_lines` return lines in winding order for `Rect::to_polygon`.
Expand Down
2 changes: 1 addition & 1 deletion geo-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geo-types"
version = "0.7.3"
version = "0.8.0"
authors = ["Corey Farwell <[email protected]>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/georust/geo"
Expand Down
80 changes: 54 additions & 26 deletions geo-types/src/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
use crate::{
CoordFloat, Coordinate, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon, Rect, Triangle,
CoordFloat, CoordTZM, GeometryCollectionTZM, GeometryTZM, LineStringTZM, Measure,
MultiLineStringTZM, MultiPointTZM, MultiPolygonTZM, PointTZM, PolygonTZM, RectTZM, TriangleTZM,
ZCoord,
};
use std::mem;

impl<'a, T> arbitrary::Arbitrary<'a> for Coordinate<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for CoordTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(coord! {
x: u.arbitrary::<T>()?,
y: u.arbitrary::<T>()?,
z: u.arbitrary::<Z>()?,
m: u.arbitrary::<M>()?,
})
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for Point<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for PointTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary::<Coordinate<T>>().map(Self)
u.arbitrary::<CoordTZM<T, Z, M>>().map(Self)
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for LineString<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for LineStringTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let coords = u.arbitrary::<Vec<Coordinate<T>>>()?;
let coords = u.arbitrary::<Vec<CoordTZM<T, Z, M>>>()?;
if coords.len() < 2 {
Err(arbitrary::Error::IncorrectFormat)
} else {
Expand All @@ -39,86 +48,105 @@ where
}

fn size_hint(_depth: usize) -> (usize, Option<usize>) {
(mem::size_of::<T>() * 2, None)
(
mem::size_of::<T>() * 2 + mem::size_of::<Z>() + mem::size_of::<M>(),
None,
)
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for Polygon<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for PolygonTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self::new(
u.arbitrary::<LineString<T>>()?,
u.arbitrary::<Vec<LineString<T>>>()?,
u.arbitrary::<LineStringTZM<T, Z, M>>()?,
u.arbitrary::<Vec<LineStringTZM<T, Z, M>>>()?,
))
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for MultiPoint<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for MultiPointTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary::<Vec<Point<T>>>().map(Self)
u.arbitrary::<Vec<PointTZM<T, Z, M>>>().map(Self)
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for MultiLineString<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for MultiLineStringTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary::<Vec<LineString<T>>>().map(Self)
u.arbitrary::<Vec<LineStringTZM<T, Z, M>>>().map(Self)
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for MultiPolygon<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for MultiPolygonTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary::<Vec<Polygon<T>>>().map(Self)
u.arbitrary::<Vec<PolygonTZM<T, Z, M>>>().map(Self)
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for GeometryCollection<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for GeometryCollectionTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary()
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for Rect<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for RectTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self::new(
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<CoordTZM<T, Z, M>>()?,
u.arbitrary::<CoordTZM<T, Z, M>>()?,
))
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for Triangle<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for TriangleTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self(
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<Coordinate<T>>()?,
u.arbitrary::<CoordTZM<T, Z, M>>()?,
u.arbitrary::<CoordTZM<T, Z, M>>()?,
u.arbitrary::<CoordTZM<T, Z, M>>()?,
))
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for Geometry<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for GeometryTZM<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + ZCoord,
M: arbitrary::Arbitrary<'a> + Measure,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let n = u.int_in_range(0..=8)?;
Expand Down
Loading