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

3D (3-dimensional) data types #1160

Closed
wants to merge 13 commits into from
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>
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

### Breaking changes
* All geo types now support optional 3D (z coordinate) and M (measure) values. For example, `LineM` contains `x`, `y`, and `m` values, whereas `Line3D` has `x,y,z`. `Line3DM` has both `z` and `m`. When not used, `z` and `m` values are represented by the `NoValue` empty struct. `NoValue` behaves like a number.
* 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>`
* Remove deprecated `CoordinateType` trait. Use `CoordFloat` or `CoordNum` instead.
* Remove deprecated functions from `LineString<T>`
* Remove `points_iter()` -- use `points()` instead.
* Remove `num_coords()` -- use `geo::algorithm::coords_iter::CoordsIter::coords_count` instead.
* 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.
* Remove deprecated `Polygon<T>::is_convex()` -- use `geo::is_convex` on `poly.exterior()` instead.
* Remove deprecated `Rect<T>::try_new()` -- use `Rect::new` instead, since `Rect::try_new` will never Error. Also removes corresponding `InvalidRectCoordinatesError`.
* Replace deprecated `GeometryCollection::new()` with `GeometryCollection::new(value)`, and deprecated `GeometryCollection::new_from(value)`.

## 0.7.13

* POSSIBLY BREAKING: Minimum supported version of Rust (MSRV) is now 1.70
Expand Down
79 changes: 53 additions & 26 deletions geo-types/src/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
use crate::{
Coord, CoordFloat, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon, Rect, Triangle,
Coord, CoordFloat, CoordNum, Geometry, GeometryCollection, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};
use std::mem;

impl<'a, T> arbitrary::Arbitrary<'a> for Coord<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for Coord<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + CoordNum,
M: arbitrary::Arbitrary<'a> + CoordNum,
{
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 Point<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + CoordNum,
M: arbitrary::Arbitrary<'a> + CoordNum,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary::<Coord<T>>().map(Self)
u.arbitrary::<Coord<T, Z, M>>().map(Self)
}
}

impl<'a, T> arbitrary::Arbitrary<'a> for LineString<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for LineString<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + CoordNum,
M: arbitrary::Arbitrary<'a> + CoordNum,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let coords = u.arbitrary::<Vec<Coord<T>>>()?;
let coords = u.arbitrary::<Vec<Coord<T, Z, M>>>()?;
if coords.len() < 2 {
Err(arbitrary::Error::IncorrectFormat)
} else {
Expand All @@ -39,86 +47,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 Polygon<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + CoordNum,
M: arbitrary::Arbitrary<'a> + CoordNum,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self::new(
u.arbitrary::<LineString<T>>()?,
u.arbitrary::<Vec<LineString<T>>>()?,
u.arbitrary::<LineString<T, Z, M>>()?,
u.arbitrary::<Vec<LineString<T, Z, M>>>()?,
))
}
}

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

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

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

impl<'a, T> arbitrary::Arbitrary<'a> for GeometryCollection<T>
impl<'a, T, Z, M> arbitrary::Arbitrary<'a> for GeometryCollection<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + CoordNum,
M: arbitrary::Arbitrary<'a> + CoordNum,
{
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 Rect<T, Z, M>
where
T: arbitrary::Arbitrary<'a> + CoordFloat,
Z: arbitrary::Arbitrary<'a> + CoordNum,
M: arbitrary::Arbitrary<'a> + CoordNum,
{
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self::new(
u.arbitrary::<Coord<T>>()?,
u.arbitrary::<Coord<T>>()?,
u.arbitrary::<Coord<T, Z, M>>()?,
u.arbitrary::<Coord<T, Z, M>>()?,
))
}
}

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

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