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
24 changes: 12 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
matrix:
container_image:
# Use the latest stable version. No need for older versions.
- "georust/geo-ci:rust-1.59"
- "georust/geo-ci:proj-9.0.0-rust-1.59"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -66,10 +66,10 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:rust-1.56"
- "georust/geo-ci:proj-9.0.0-rust-1.56"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:rust-1.58"
- "georust/geo-ci:rust-1.59"
- "georust/geo-ci:proj-9.0.0-rust-1.58"
- "georust/geo-ci:proj-9.0.0-rust-1.59"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -92,10 +92,10 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:rust-1.56"
- "georust/geo-ci:proj-9.0.0-rust-1.56"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:rust-1.58"
- "georust/geo-ci:rust-1.59"
- "georust/geo-ci:proj-9.0.0-rust-1.58"
- "georust/geo-ci:proj-9.0.0-rust-1.59"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -119,10 +119,10 @@ jobs:
# giving us about 6 months of coverage.
#
# Minimum supported rust version (MSRV)
- "georust/geo-ci:rust-1.56"
- "georust/geo-ci:proj-9.0.0-rust-1.56"
# Two most recent releases - we omit older ones for expedient CI
- "georust/geo-ci:rust-1.58"
- "georust/geo-ci:rust-1.59"
- "georust/geo-ci:proj-9.0.0-rust-1.58"
- "georust/geo-ci:proj-9.0.0-rust-1.59"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -142,7 +142,7 @@ jobs:
matrix:
container_image:
# Fuzz only on latest
- "georust/geo-ci:rust-1.59"
- "georust/geo-ci:proj-9.0.0-rust-1.59"
container:
image: ${{ matrix.container_image }}
steps:
Expand All @@ -155,7 +155,7 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
container:
image: georust/geo-ci:rust-1.59
image: georust/geo-ci:proj-9.0.0-rust-1.59
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,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" }
wkt = { git = "https://github.com/nyurik/wkt", branch = "wkt-dim" }
proj = { git = "https://github.com/georust/proj", branch = "main" }
2 changes: 1 addition & 1 deletion geo-postgis/src/from_postgis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where
.iter()
.filter_map(Option::from_postgis)
.collect();
GeometryCollection::new_from(geoms)
GeometryCollection::new(geoms)
}
}
impl<'a, T> FromPostgis<&'a GeometryT<T>> for Option<Geometry<f64>>
Expand Down
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
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